Class PdfImportSession
- java.lang.Object
 - 
- de.xima.fc.gui.designer.form.pdfimport.PdfImportSession
 
 
- 
- All Implemented Interfaces:
 Serializable,AutoCloseable
public final class PdfImportSession extends Object implements AutoCloseable, Serializable
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:
 - Serialized Form
 
 
- 
- 
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPdfImportSession.PdfImportResourceHandlerPrimeFaces dynamic resources (DynamicContentSrcBuilder) use the Faces resource servlet, which does not support view scoped beans. 
- 
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()static PdfImportSessionforExistingFile(Path pdfData, String fileName, String password, javax.faces.context.FacesContext context)Creates a new PDF import session for the given PDF document.static PdfImportSessionforInputStream(InputStream pdfData, String fileName, String password, javax.faces.context.FacesContext context)Creates a new PDF import session for the given PDF document.static PdfImportSessionforSessionKey(String serializedSessionKey, javax.faces.context.FacesContext context)StringgetFormHtml()byte[]getInlineImage(String imageId)intgetPageCount()StringgetPageHtml(int page)List<String>getPageHtml(com.google.common.collect.Range<Integer> pageRange)byte[]getPageScreenshot(int page)List<de.xima.fc.gui.designer.form.pdfimport.PageSize>getPageSizes()byte[]getPageThumbnail(int page)StringgetPdfAuthor()StringgetPdfFileName()StringgetPdfTitle()StringgetSerializedKey()Retrieves the key of this import session in its serialized form.List<String>getThumbnailUrls()booleanisRequiresPassword()Use this to check whether the PDF document requires a password.voidloadWithPassword(String password, javax.faces.context.FacesContext context)If the PDF documentrequired a password, loads the document with the given password. 
 - 
 
- 
- 
Method Detail
- 
close
public void close()
- Specified by:
 closein interfaceAutoCloseable
 
- 
getFormHtml
public String getFormHtml() throws IllegalStateException
- Returns:
 - The rendered HTML for the form, without the individual page content.
 - Throws:
 IllegalStateException- When the PDF documentrequires a passwordandloadWithPasswordwas 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 passwordandloadWithPasswordwas not yet called.IllegalArgumentException- When no image with the given ID exists.
 
- 
getPageCount
public int getPageCount() throws IllegalStateException- Returns:
 - The total number of available pages.
 - Throws:
 IllegalStateException- When the PDF documentrequires a passwordandloadWithPasswordwas not yet called.
 
- 
getPageHtml
public String getPageHtml(int page) throws IOException, IllegalStateException
- 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 passwordandloadWithPasswordwas 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 passwordandloadWithPasswordwas 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 passwordandloadWithPasswordwas 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 passwordandloadWithPasswordwas not yet called.
 
- 
getPageThumbnail
public byte[] getPageThumbnail(int page) throws IOException, IllegalStateException- 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 passwordandloadWithPasswordwas not yet called.
 
- 
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. viaforSessionKey(String, FacesContext).- Returns:
 - The serialized key of this import session.
 
 
- 
getThumbnailUrls
public List<String> getThumbnailUrls() throws IllegalStateException
- Returns:
 - URLs for the thumbnail of each PDF page.
 - Throws:
 IllegalStateException- When the PDF documentrequires a passwordandloadWithPasswordwas 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:
 truewhen 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 
nullif no such session exists. 
 
 - 
 
 -