X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.help.base%2Fsrc%2Forg%2Fsimantics%2Fhelp%2Fbase%2Finternal%2FPDFUtil.java;h=d0eff0550706b1877480d45fec20ae201f2bba27;hb=HEAD;hp=43fac6c7079a114d92e99e690824c46262967969;hpb=6ceab2d9498554c1b825ab6ae76bef520bb05789;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.help.base/src/org/simantics/help/base/internal/PDFUtil.java b/bundles/org.simantics.help.base/src/org/simantics/help/base/internal/PDFUtil.java index 43fac6c70..d0eff0550 100644 --- a/bundles/org.simantics.help.base/src/org/simantics/help/base/internal/PDFUtil.java +++ b/bundles/org.simantics.help.base/src/org/simantics/help/base/internal/PDFUtil.java @@ -1,42 +1,42 @@ -package org.simantics.help.base.internal; - -import java.io.File; -import java.io.IOException; - -import org.apache.pdfbox.cos.COSDocument; -import org.apache.pdfbox.io.RandomAccessFile; -import org.apache.pdfbox.pdfparser.PDFParser; -import org.apache.pdfbox.pdmodel.PDDocument; -import org.apache.pdfbox.pdmodel.PDDocumentInformation; -import org.apache.pdfbox.text.PDFTextStripper; -import org.eclipse.help.search.ISearchDocument; - -/** - * @author Tuukka Lehtonen - */ -public class PDFUtil { - - public static void stripText(File fromPdf, ISearchDocument doc) throws IOException { - PDFParser parser = new PDFParser(new RandomAccessFile(fromPdf, "r")); - parser.parse(); - - try (COSDocument cosDoc = parser.getDocument()) { - try (PDDocument pdDoc = new PDDocument(cosDoc)) { - int numPages = pdDoc.getNumberOfPages(); - PDFTextStripper stripper = new PDFTextStripper(); - stripper.setStartPage(1); - stripper.setEndPage(numPages); - String text = stripper.getText(pdDoc); - PDDocumentInformation docInfo = pdDoc.getDocumentInformation(); - String title = docInfo.getTitle(); - String subject = docInfo.getSubject(); - if (title != null) - doc.setTitle(title); - if (subject != null) - doc.setSummary(subject); - doc.addContents(text); - } - } - } - +package org.simantics.help.base.internal; + +import java.io.File; +import java.io.IOException; + +import org.apache.pdfbox.cos.COSDocument; +import org.apache.pdfbox.io.RandomAccessFile; +import org.apache.pdfbox.pdfparser.PDFParser; +import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdmodel.PDDocumentInformation; +import org.apache.pdfbox.text.PDFTextStripper; +import org.eclipse.help.search.ISearchDocument; + +/** + * @author Tuukka Lehtonen + */ +public class PDFUtil { + + public static void stripText(File fromPdf, ISearchDocument doc) throws IOException { + PDFParser parser = new PDFParser(new RandomAccessFile(fromPdf, "r")); + parser.parse(); + + try (COSDocument cosDoc = parser.getDocument()) { + try (PDDocument pdDoc = new PDDocument(cosDoc)) { + int numPages = pdDoc.getNumberOfPages(); + PDFTextStripper stripper = new PDFTextStripper(); + stripper.setStartPage(1); + stripper.setEndPage(numPages); + String text = stripper.getText(pdDoc); + PDDocumentInformation docInfo = pdDoc.getDocumentInformation(); + String title = docInfo.getTitle(); + String subject = docInfo.getSubject(); + if (title != null) + doc.setTitle(title); + if (subject != null) + doc.setSummary(subject); + doc.addContents(text); + } + } + } + } \ No newline at end of file