diff --git a/pdf/pom.xml b/pdf/pom.xml index 078a364e77..be1e9822e2 100644 --- a/pdf/pom.xml +++ b/pdf/pom.xml @@ -24,49 +24,31 @@ 3.8.1 test - - - org.apache.pdfbox - pdfbox - 2.0.3 - - org.apache.pdfbox pdfbox-tools 2.0.3 - net.sf.cssbox pdf2dom 1.6 - com.itextpdf itextpdf 5.5.10 - org.apache.poi poi 3.15 - - - org.apache.poi - poi-ooxml - 3.15 - - org.apache.poi poi-scratchpad 3.15 - org.apache.xmlgraphics batik-transcoder diff --git a/pdf/src/main/java/com/baeldung/pdf/PDF2HTMLExample.java b/pdf/src/main/java/com/baeldung/pdf/PDF2HTMLExample.java index 14e886e23b..0d38208bab 100644 --- a/pdf/src/main/java/com/baeldung/pdf/PDF2HTMLExample.java +++ b/pdf/src/main/java/com/baeldung/pdf/PDF2HTMLExample.java @@ -23,17 +23,13 @@ public class PDF2HTMLExample { } private static void generateHTMLFromPDF(String filename) throws ParserConfigurationException, IOException { - try { - PDDocument pdf = PDDocument.load(new File(filename)); - PDFDomTree parser = new PDFDomTree(); - Writer output = new PrintWriter("src/output/pdf.html", "utf-8"); - parser.writeText(pdf, output); - output.close(); - if (pdf != null) { - pdf.close(); - } - } catch (IOException e) { - e.printStackTrace(); + PDDocument pdf = PDDocument.load(new File(filename)); + PDFDomTree parser = new PDFDomTree(); + Writer output = new PrintWriter("src/output/pdf.html", "utf-8"); + parser.writeText(pdf, output); + output.close(); + if (pdf != null) { + pdf.close(); } } } diff --git a/pdf/src/main/java/com/baeldung/pdf/PDF2TextExample.java b/pdf/src/main/java/com/baeldung/pdf/PDF2TextExample.java index e4fb29dfaa..c5880a4e91 100644 --- a/pdf/src/main/java/com/baeldung/pdf/PDF2TextExample.java +++ b/pdf/src/main/java/com/baeldung/pdf/PDF2TextExample.java @@ -23,30 +23,26 @@ public class PDF2TextExample { } private static void generateTxtFromPDF(String filename) throws IOException { - try { - File f = new File(filename); - String parsedText; - PDFParser parser = new PDFParser(new RandomAccessFile(f, "r")); - parser.parse(); + File f = new File(filename); + String parsedText; + PDFParser parser = new PDFParser(new RandomAccessFile(f, "r")); + parser.parse(); - COSDocument cosDoc = parser.getDocument(); + COSDocument cosDoc = parser.getDocument(); - PDFTextStripper pdfStripper = new PDFTextStripper(); - PDDocument pdDoc = new PDDocument(cosDoc); + PDFTextStripper pdfStripper = new PDFTextStripper(); + PDDocument pdDoc = new PDDocument(cosDoc); - parsedText = pdfStripper.getText(pdDoc); + parsedText = pdfStripper.getText(pdDoc); - if (cosDoc != null) - cosDoc.close(); - if (pdDoc != null) - pdDoc.close(); - - PrintWriter pw = new PrintWriter("src/output/pdf.txt"); - pw.print(parsedText); - pw.close(); - } catch (Exception e) { - e.printStackTrace(); - } + if (cosDoc != null) + cosDoc.close(); + if (pdDoc != null) + pdDoc.close(); + + PrintWriter pw = new PrintWriter("src/output/pdf.txt"); + pw.print(parsedText); + pw.close(); } }