@Override PDDocument open() throws IOException { return PDDocument.load(file, password); } };
/** * Parses a PDF. Unrestricted main memory will be used for buffering PDF streams. * * @param input byte array that contains the document. * * @return loaded document * * @throws InvalidPasswordException If the PDF required a non-empty password. * @throws IOException In case of a reading or parsing error. */ public static PDDocument load(byte[] input) throws InvalidPasswordException, IOException { return load(input, ""); }
/** * Parses a PDF. * * @param file file to be loaded * @param memUsageSetting defines how memory is used for buffering PDF streams * * @return loaded document * * @throws InvalidPasswordException If the file required a non-empty password. * @throws IOException in case of a file reading or parsing error */ public static PDDocument load(File file, MemoryUsageSetting memUsageSetting) throws InvalidPasswordException, IOException { return load(file, "", null, null, memUsageSetting); }
/** * Parses a PDF. Unrestricted main memory will be used for buffering PDF streams. * * @param input byte array that contains the document. * @param password password to be used for decryption * * @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) throws InvalidPasswordException, IOException { return load(input, password, null, null); }
/** * Parses a PDF. * * @param file file to be loaded * @param password password to be used for decryption * @param memUsageSetting defines how memory is used for buffering PDF streams * * @return loaded document * * @throws InvalidPasswordException If the password is incorrect. * @throws IOException in case of a file reading or parsing error */ public static PDDocument load(File file, String password, MemoryUsageSetting memUsageSetting) throws InvalidPasswordException, IOException { return load(file, password, null, null, memUsageSetting); }
private PDDocument loadPDF(String pdfName) throws IOException { return PDDocument.load(new File(pdfName)); }
@Override PDDocument open() throws IOException { return PDDocument.load(new URL(urlString).openStream(), password); } };
private void calculatePageSizeFromFile(String filename, int page) throws IOException { try (PDDocument document = PDDocument.load(new File(filename))) { // calculate height and width of document page calculatePageSize(document, page); } }
private void calculatePageSizeFromStream(InputStream documentStream, int page) throws IOException { try (PDDocument document = PDDocument.load(documentStream)) { // calculate height and width of document page calculatePageSize(document, page); } }
/** * Parses a PDF. Unrestricted main memory will be used for buffering PDF streams. * * @param file file to be loaded * * @return loaded document * * @throws InvalidPasswordException If the file required a non-empty password. * @throws IOException in case of a file reading or parsing error */ public static PDDocument load(File file) throws InvalidPasswordException, IOException { return load(file, "", MemoryUsageSetting.setupMainMemoryOnly()); }
/** * Parses a PDF. The given input stream is copied to the memory to enable random access to the pdf. * Unrestricted main memory will be used for buffering PDF streams. * * @param input stream that contains the document. * * @return loaded document * * @throws InvalidPasswordException If the PDF required a non-empty password. * @throws IOException In case of a reading or parsing error. */ public static PDDocument load(InputStream input) throws InvalidPasswordException, IOException { return load(input, "", null, null, MemoryUsageSetting.setupMainMemoryOnly()); }
/** * Parses a PDF. Unrestricted main memory will be used for buffering PDF streams. * * @param file file to be loaded * @param password password to be used for decryption * * @return loaded document * * @throws InvalidPasswordException If the password is incorrect. * @throws IOException in case of a file reading or parsing error */ public static PDDocument load(File file, String password) throws InvalidPasswordException, IOException { return load(file, password, null, null, MemoryUsageSetting.setupMainMemoryOnly()); }
/** * Parses a PDF. The given input stream is copied to the memory to enable random access to the pdf. * Unrestricted main memory will be used for buffering PDF streams. * * @param input stream that contains the document. * @param password password to be used for decryption * * @return loaded document * * @throws InvalidPasswordException If the password is incorrect. * @throws IOException In case of a reading or parsing error. */ public static PDDocument load(InputStream input, String password) throws InvalidPasswordException, IOException { return load(input, password, null, null, MemoryUsageSetting.setupMainMemoryOnly()); }
/** * Parses a PDF. Unrestricted main memory will be used for buffering PDF streams. * * @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 * * @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) throws IOException { return load(input, password, keyStore, alias, MemoryUsageSetting.setupMainMemoryOnly()); }
public static void main(String[] args) throws IOException { File file = new File("src/main/resources/org/apache/pdfbox/examples/rendering/", "custom-render-demo.pdf"); try (PDDocument doc = PDDocument.load(file)) { PDFRenderer renderer = new MyPDFRenderer(doc); BufferedImage image = renderer.renderImage(0); ImageIO.write(image, "PNG", new File("custom-render.png")); } }
public static void main(String[] args) throws IOException { File file = new File("src/main/resources/org/apache/pdfbox/examples/rendering/", "custom-render-demo.pdf"); try (PDDocument doc = PDDocument.load(file)) { PDPage page = doc.getPage(0); CustomGraphicsStreamEngine engine = new CustomGraphicsStreamEngine(page); engine.run(); } }
private void extract(String pdfFile, String password) throws IOException { try (PDDocument document = PDDocument.load(new File(pdfFile), password)) { AccessPermission ap = document.getCurrentAccessPermission(); if (!ap.canExtractContent()) { throw new IOException("You do not have permission to extract images"); } for (PDPage page : document.getPages()) { ImageGraphicsEngine extractor = new ImageGraphicsEngine(page); extractor.run(); } } }
private void importXFDF( String[] args ) throws IOException { if( args.length != 3 ) { usage(); } else { ImportFDF importer = new ImportFDF(); try (PDDocument pdf = PDDocument.load( new File(args[0]) ); FDFDocument fdf = FDFDocument.loadXFDF( args[1] )) { importer.importFDF( pdf, fdf ); pdf.save( args[2] ); } } }
private void importFDF( String[] args ) throws IOException { if( args.length != 3 ) { usage(); } else { ImportFDF importer = new ImportFDF(); try (PDDocument pdf = PDDocument.load( new File(args[0]) ); FDFDocument fdf = FDFDocument.load( args[1] )) { importer.importFDF( pdf, fdf ); pdf.save( args[2] ); } } }
private List<String> extractStrings(File pdfFile) throws IOException { PDDocument pdf = PDDocument.load(pdfFile); assertThat(pdf.getNumberOfPages()).isEqualTo(1); StringExtractor stringExtractor = new StringExtractor(); stringExtractor.processPage(pdf.getPage(0)); return stringExtractor.getStrings(); }