Class PdfImportSession

    • Method Detail

      • getPdfAuthor

        public String getPdfAuthor()
        Returns:
        The author of the opened PDF document.
      • getPdfFileName

        public String getPdfFileName()
        Returns:
        The file name of the loaded PDF document.
      • getPdfTitle

        public String getPdfTitle()
        Returns:
        The title of the opened PDF document.
      • getSerializedKey

        public String getSerializedKey()
        Retrieves the key of this import session in its serialized form. Can be used later to resume the session, e.g. via forSessionKey(String, FacesContext).
        Returns:
        The serialized key of this import session.
      • isRequiresPassword

        public boolean isRequiresPassword()
        Use this to check whether the PDF document requires a password. If so, you should call loadWithPassword(String, FacesContext) first before attempting to call any other methods.
        Returns:
        true when the PDF file was not loaded yet and can only be loaded with the correct password.
      • loadWithPassword

        public void loadWithPassword​(String password,
                                     javax.faces.context.FacesContext context)
                              throws UnsupportedXfaFormException,
                                     org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException,
                                     IOException
        If the PDF document required a password, loads the document with the given password. Other methods should not be called before this method was called.

        If the PDF was decrypted already, this is a no-op.

        Parameters:
        password - Password for decrypting the PDF document.
        context - Current faces context.
        Throws:
        UnsupportedXfaFormException - When the PDF contains an XFA form.
        org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException - When the given password was incorrect.
        IOException - When the PDF document could not be read, such as due to a file system error.
      • forExistingFile

        public static PdfImportSession forExistingFile​(Path pdfData,
                                                       String fileName,
                                                       String password,
                                                       javax.faces.context.FacesContext context)
                                                throws UnsupportedXfaFormException,
                                                       org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException,
                                                       IOException
        Creates a new PDF import session for the given PDF document.
        Parameters:
        pdfData - Data of the PDF document to import.
        fileName - Name of the PDF file, defaults to the name of the given file when empty.
        password - Optional password if the PDF document is encrypted.
        context - Current faces context.
        Returns:
        The PDF import session for importing the given PDF document.
        Throws:
        UnsupportedXfaFormException - When the PDF contains an XFA form.
        org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException - When the PDF is encrypted and the given password is wrong.
        IOException - When the PDF could not be read or temporary files could not be written.
      • forInputStream

        public static PdfImportSession forInputStream​(InputStream pdfData,
                                                      String fileName,
                                                      String password,
                                                      javax.faces.context.FacesContext context)
                                               throws UnsupportedXfaFormException,
                                                      org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException,
                                                      IOException
        Creates a new PDF import session for the given PDF document.
        Parameters:
        pdfData - Data of the PDF document to import.
        fileName - Name of the PDF file.
        password - Optional password if the PDF document is encrypted.
        context - Current faces context.
        Returns:
        The PDF import session for importing the given PDF document.
        Throws:
        UnsupportedXfaFormException - When the PDF contains an XFA form.
        org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException - When the PDF is encrypted and the given password is wrong.
        IOException - When the PDF could not be read or temporary files could not be written.
      • forSessionKey

        public static PdfImportSession forSessionKey​(String serializedSessionKey,
                                                     javax.faces.context.FacesContext context)
        Parameters:
        serializedSessionKey - Serialized session key as returned by getSerializedKey().
        context - Current faces context of the ongoing faces request.
        Returns:
        The PDF import session for the given key, or null if no such session exists.