public void ReadPDF() throws Exception { URL TestURL = new URL("http://www.axmag.com/download/pdfurl-guide.pdf"); BufferedInputStream TestFile = new BufferedInputStream(TestURL.openStream()); PDFParser TestPDF = new PDFParser(TestFile); TestPDF.parse(); String TestText = new PDFTextStripper().getText(TestPDF.getPDDocument()); Assert.assertTrue(TestText.contains("Open the setting.xml, you can see it is like this")); }
File in = new File("somefile.pdf"); InputStream fin = new FileInputStream(in); PDFParser parser = new PDFParser(fin); parser.setTempDirectory(new File(tempDirectoryPath)); parser.parse(); PDDocument document = parser.getPDDocument();
private void openPDFDoc(final File pdfFile) throws Exception { File originalPDF = pdfFile; PDFParser parser = new PDFParser(new BufferedInputStream(new FileInputStream( originalPDF))); parser.parse(); PDDocument originialPdfDoc = parser.getPDDocument(); boolean isOriginalDocEncrypted = originialPdfDoc.isEncrypted(); if (isOriginalDocEncrypted) { originialPdfDoc.openProtection(new StandardDecryptionMaterial("password")); } }
PDFParser pdfParser = new PDFParser(new FileInputStream("c:\\temp\\owgr49f2013.pdf")); pdfParser.parse(); PDDocument pdDocument = pdfParser.getPDDocument(); PDFTextStripper stripper = new PDFTextStripper("UTF-8"); stripper.setSortByPosition(false); stripper.setWordSeparator("###"); System.out.println(stripper.getText(pdDocument));