/** * Parses a PDF. * * @param input byte array that contains the document. * @param password password to be used for decryption * @param keyStore key store to be used for decryption when using public key security * @param alias alias to be used for decryption when using public key security * @param memUsageSetting defines how memory is used for buffering input stream and PDF streams * * @return loaded document * * @throws InvalidPasswordException If the password is incorrect. * @throws IOException In case of a reading or parsing error. */ public static PDDocument load(byte[] input, String password, InputStream keyStore, String alias, MemoryUsageSetting memUsageSetting) throws IOException { ScratchFile scratchFile = new ScratchFile(memUsageSetting); RandomAccessRead source = new RandomAccessBuffer(input); PDFParser parser = new PDFParser(source, password, keyStore, alias, scratchFile); parser.parse(); return parser.getPDDocument(); }
PDFParser parser = new PDFParser(source, password, keyStore, alias, scratchFile); parser.parse(); return parser.getPDDocument();
return parser.getPDDocument();
@SuppressFBWarnings( value = "EXS_EXCEPTION_SOFTENING_RETURN_FALSE", justification = "This method is an helper to check the password") private PDDocument testPassword(ScratchFile inFile, RandomAccessRead source, String password) throws IOException { PDFParser parser = new PDFParser(source, password, inFile); try { parser.parse(); return parser.getPDDocument(); } catch (InvalidPasswordException e) { LOGGER.error("The tested password is invalid"); return null; } finally { source.rewind((int) source.getPosition()); } }
public static String pdfText(File f) { try { if (toLowerCase(f.getName()).endsWith(FILE_PDF)) { PDFParser p = new PDFParser(new RandomAccessFile(f, "r")); p.parse(); PDDocument pdd = p.getPDDocument(); PDFTextStripper ts = new PDFTextStripper(); String c = ts.getText(pdd); pdd.close(); return trim(c); } } catch (Exception e) { LOG.error(e.getLocalizedMessage(), e); } return EMPTY; }
PDFParser pdfParser = new PDFParser(new RandomAccessBuffer(inputStream)); pdfParser.parse(); pdFormXObject = layerUtility.importPageAsForm(pdfParser.getPDDocument(), pdfpage - 1); pdfParser.getPDDocument().close(); } finally { inputStream.close();
/** * Parses a PDF. * * @param input byte array that contains the document. * @param password password to be used for decryption * @param keyStore key store to be used for decryption when using public key security * @param alias alias to be used for decryption when using public key security * @param memUsageSetting defines how memory is used for buffering input stream and PDF streams * * @return loaded document * * @throws InvalidPasswordException If the password is incorrect. * @throws IOException In case of a reading or parsing error. */ public static PDDocument load(byte[] input, String password, InputStream keyStore, String alias, MemoryUsageSetting memUsageSetting) throws IOException { ScratchFile scratchFile = new ScratchFile(memUsageSetting); RandomAccessRead source = new RandomAccessBuffer(input); PDFParser parser = new PDFParser(source, password, keyStore, alias, scratchFile); parser.parse(); return parser.getPDDocument(); }
public static String convertPDFDocument(String url) throws FileNotFoundException, IOException { PDFTextStripper stripper = new PDFTextStripper(); PDFParser parser = new PDFParser(new FileInputStream(url)); parser.parse(); PDDocument doc = parser.getPDDocument(); String text = stripper.getText(doc); parser.clearResources(); doc.close(); if(text==null || text.isEmpty() || verifyValidOCRlenght(text)==false) { try { text = fileOCR(url); } catch (TesseractException e) { text = new String(); } } if(text==null || text.isEmpty() || verifyValidOCRlenght(text)==false) { try { text = convertEncryptedPDFDocument(url); } catch (TesseractException e) { text = new String(); } } return NormalizationForm.removeOffsetProblemSituation(text); }
/** * Parses a PDF. * * @param input byte array that contains the document. * @param password password to be used for decryption * @param keyStore key store to be used for decryption when using public key security * @param alias alias to be used for decryption when using public key security * @param memUsageSetting defines how memory is used for buffering input stream and PDF streams * * @return loaded document * * @throws InvalidPasswordException If the password is incorrect. * @throws IOException In case of a reading or parsing error. */ public static PDDocument load(byte[] input, String password, InputStream keyStore, String alias, MemoryUsageSetting memUsageSetting) throws IOException { ScratchFile scratchFile = new ScratchFile(memUsageSetting); RandomAccessRead source = new RandomAccessBuffer(input); PDFParser parser = new PDFParser(source, password, keyStore, alias, scratchFile); parser.parse(); return parser.getPDDocument(); }
PDFParser parser = new PDFParser(source, password, keyStore, alias, scratchFile); parser.parse(); return parser.getPDDocument();
PDFParser parser = new PDFParser(source, password, keyStore, alias, scratchFile); parser.parse(); return parser.getPDDocument();
return parser.getPDDocument();
return parser.getPDDocument();
PDDocument pdfDoc = parser.getPDDocument(); try { if (pdfDoc.isEncrypted()) {