Class PdDocumentLoader


  • public final class PdDocumentLoader
    extends Object
    Helper methods for loading a PDDocument.
    Since:
    7.2.0
    Author:
    XIMA MEDIA GmbH
    • Method Detail

      • load

        public static org.apache.pdfbox.pdmodel.PDDocument load​(byte[] pdf,
                                                                String password)
                                                         throws org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException,
                                                                IOException
        Loads a PDF file via PDFBox into a PDDocument. Make sure to close the document when done, prefer using a try-with-resources-statement.
        Parameters:
        pdf - PDF file to open.
        password - Password when the PDF is encrypted. Can be null when not encrypted.
        Returns:
        The loaded PDF document.
        Throws:
        org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException - When the PDF is encrypted and the password in invalid.
        IOException - When the PDF document could not be loaded.
      • load

        public static org.apache.pdfbox.pdmodel.PDDocument load​(File pdf,
                                                                String password)
                                                         throws org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException,
                                                                IOException
        Loads a PDF file via PDFBox into a PDDocument. Make sure to close the document when done, prefer using a try-with-resources-statement.
        Parameters:
        pdf - PDF file to open.
        password - Password when the PDF is encrypted. Can be null when not encrypted.
        Returns:
        The loaded PDF document.
        Throws:
        org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException - When the PDF is encrypted and the password in invalid.
        IOException - When the PDF document could not be loaded.
      • load

        public static org.apache.pdfbox.pdmodel.PDDocument load​(InputStream pdf,
                                                                String password)
                                                         throws org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException,
                                                                IOException
        Loads a PDF file via PDFBox into a PDDocument. Make sure to close the document when done, prefer using a try-with-resources-statement.
        Parameters:
        pdf - PDF file to open.
        password - Password when the PDF is encrypted. Can be null when not encrypted.
        Returns:
        The loaded PDF document.
        Throws:
        org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException - When the PDF is encrypted and the password in invalid.
        IOException - When the PDF document could not be loaded.
      • load

        public static org.apache.pdfbox.pdmodel.PDDocument load​(Path pdf,
                                                                String password)
                                                         throws org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException,
                                                                IOException
        Loads a PDF file via PDFBox into a PDDocument. Make sure to close the document when done, prefer using a try-with-resources-statement.
        Parameters:
        pdf - PDF file to open.
        password - Password when the PDF is encrypted. Can be null when not encrypted.
        Returns:
        The loaded PDF document.
        Throws:
        org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException - When the PDF is encrypted and the password in invalid.
        IOException - When the PDF document could not be loaded.