Class PdfImportSession
java.lang.Object
de.xima.fc.gui.designer.form.pdfimport.PdfImportSession
- All Implemented Interfaces:
Serializable
,AutoCloseable
An ongoing PDF import process session. Keeps handles to opened files etc. Closes itself at the end of the session.
- Since:
- 7.2.0
- Author:
- XIMA MEDIA GmbH
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
PrimeFaces dynamic resources (DynamicContentSrcBuilder
) use the Faces resource servlet, which does not support view scoped beans. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
static PdfImportSession
forExistingFile
(Path pdfData, String fileName, String password, javax.faces.context.FacesContext context) Creates a new PDF import session for the given PDF document.static PdfImportSession
forInputStream
(InputStream pdfData, String fileName, String password, javax.faces.context.FacesContext context) Creates a new PDF import session for the given PDF document.static PdfImportSession
forSessionKey
(String serializedSessionKey, javax.faces.context.FacesContext context) byte[]
getInlineImage
(String imageId) int
getPageHtml
(int page) getPageHtml
(com.google.common.collect.Range<Integer> pageRange) byte[]
getPageScreenshot
(int page) List<de.xima.fc.gui.designer.form.pdfimport.PageSize>
byte[]
getPageThumbnail
(int page) Retrieves the key of this import session in its serialized form.boolean
Use this to check whether the PDF document requires a password.void
loadWithPassword
(String password, javax.faces.context.FacesContext context) If the PDF documentrequired a password
, loads the document with the given password.
-
Method Details
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
-
getFormHtml
- Returns:
- The rendered HTML for the form, without the individual page content.
- Throws:
IllegalStateException
- When the PDF documentrequires a password
andloadWithPassword
was not yet called.
-
getInlineImage
public byte[] getInlineImage(String imageId) throws IOException, IllegalStateException, IllegalArgumentException - Parameters:
imageId
- ID of the inline image to fetch.- Returns:
- The inline PDF image with the given ID.
- Throws:
IOException
- When the PDF image could not be read.IllegalStateException
- When the PDF documentrequires a password
andloadWithPassword
was not yet called.IllegalArgumentException
- When no image with the given ID exists.
-
getPageCount
- Returns:
- The total number of available pages.
- Throws:
IllegalStateException
- When the PDF documentrequires a password
andloadWithPassword
was not yet called.
-
getPageHtml
- Parameters:
page
- 0-based index range of the pages to fetch.- Returns:
- The rendered HTML of the given page.
- Throws:
IOException
- When the page HTML could not be read.IllegalStateException
- When the PDF documentrequires a password
andloadWithPassword
was not yet called.
-
getPageHtml
public List<String> getPageHtml(com.google.common.collect.Range<Integer> pageRange) throws IOException, IllegalStateException - Parameters:
pageRange
- 0-based index range of the pages to fetch.- Returns:
- The rendered HTML of the given pages.
- Throws:
IOException
- When the page HTML could not be read.IllegalStateException
- When the PDF documentrequires a password
andloadWithPassword
was not yet called.
-
getPageScreenshot
public byte[] getPageScreenshot(int page) throws IOException, IllegalStateException, IndexOutOfBoundsException - Parameters:
page
- 0-based index of a page.- Returns:
- The PNG with the screenshot of the given page.
- Throws:
IOException
- When the page screenshot could not be read.IllegalStateException
- When the PDF documentrequires a password
andloadWithPassword
was not yet called.IndexOutOfBoundsException
- When the given page number is invalid.
-
getPageSizes
public List<de.xima.fc.gui.designer.form.pdfimport.PageSize> getPageSizes() throws IllegalStateException- Returns:
- A list with the width and height of each page.
- Throws:
IllegalStateException
- When the PDF documentrequires a password
andloadWithPassword
was not yet called.
-
getPageThumbnail
- Parameters:
page
- 0-based index of a page.- Returns:
- The PNG with the thumbnail of the given page.
- Throws:
IOException
- When the page thumbnail could not be read.IllegalStateException
- When the PDF documentrequires a password
andloadWithPassword
was not yet called.
-
getPdfAuthor
- Returns:
- The author of the opened PDF document.
-
getPdfFileName
- Returns:
- The file name of the loaded PDF document.
-
getPdfTitle
- Returns:
- The title of the opened PDF document.
-
getSerializedKey
Retrieves the key of this import session in its serialized form. Can be used later to resume the session, e.g. viaforSessionKey(String, FacesContext)
.- Returns:
- The serialized key of this import session.
-
getThumbnailUrls
- Returns:
- URLs for the thumbnail of each PDF page.
- Throws:
IllegalStateException
- When the PDF documentrequires a password
andloadWithPassword
was not yet called.
-
isRequiresPassword
public boolean isRequiresPassword()Use this to check whether the PDF document requires a password. If so, you should callloadWithPassword(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 documentrequired 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 bygetSerializedKey()
.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.
-