public class PDFAssemble extends Object
PDFAssemble
class provides methods to assemble and disassemble PDF documents.
The PDFAssemble class can load existing documents (or start from a blank document) and can add pages
from other documents or delete pages in the document.Modifier and Type | Class and Description |
---|---|
static class |
PDFAssemble.KeyInfoAssemble
This is the Main-Class for the jPDFAssemble.jar that can generate server
key requests, validate a key, and display server information.
|
Modifier and Type | Field and Description |
---|---|
static String |
MAGNIFICATION_FIT_ACTUAL
Setting for the initial magnification: 100% Scale
|
static String |
MAGNIFICATION_FIT_HEIGHT
Setting for the initial magnification: Fit to height
|
static String |
MAGNIFICATION_FIT_PAGE
Setting for the initial magnification: Fit page (both width and height)
|
static String |
MAGNIFICATION_FIT_WIDTH
Setting for the initial magnification: Fit to width
|
static String |
PAGELAYOUT_ONECOLUMN
Setting for the initial page layout: Single page continuous
|
static String |
PAGELAYOUT_SINGLEPAGE
Setting for the initial page layout: Single page
|
static String |
PAGELAYOUT_TWOCOLUMNLEFT
Setting for the initial page layout: Two pages continuous
|
static String |
PAGELAYOUT_TWOPAGELEFT
Setting for the initial page layout: Two pages
|
static String |
PAGEMODE_FULLSCREEN
Setting for the initial page mode: Full-screen mode, with no menu bar, window controls, or any other window visible
|
static String |
PAGEMODE_USEATTACHMENTS
Setting for the initial page mode: (PDF 1.6) Attachments panel visible
|
static String |
PAGEMODE_USENONE
Setting for the initial page mode: Neither document outline nor thumbnail images visible
|
static String |
PAGEMODE_USEOC
Setting for the initial page mode: (PDF 1.5) Optional content group panel visible
|
static String |
PAGEMODE_USEOUTLINES
Setting for the initial page mode: Document outline visible
|
static String |
PAGEMODE_USETHUMBS
Setting for the initial page mode: Thumbnail images visible
|
Constructor and Description |
---|
PDFAssemble()
Creates a blank PDFAssemble object.
|
PDFAssemble(InputStream inStream,
IPassword password)
Loads a PDF document from an InputStream.
|
PDFAssemble(String fileName,
IPassword password)
Loads a PDF document from a file.
|
PDFAssemble(URL url,
IPassword password)
Loads a PDF document from a URL.
|
Modifier and Type | Method and Description |
---|---|
void |
addGoToPage(Bookmark bookmark,
int pageNum)
Adds a GoToPage action to the Bookmark Parameter.
|
void |
addGoToPage(Bookmark bookmark,
int pageNum,
int zoomMode)
Adds a GoToPage action to the Bookmark Parameter with a zoom mode.
|
void |
addGoToPage(Bookmark bookmark,
int pageNum,
int x,
int y,
double scale)
Adds a GoToPage action to the Bookmark Parameter that uses x and y coordinates and a zoom scale.
|
void |
appendDocument(PDFAssemble appendDoc)
Appends a PDF document to this document.
|
void |
appendPage(PDFAssemble source,
int pageIndex)
Appends a page to this document.
|
void |
close()
Close / release all resources held by this document.
|
Bookmark |
createBookmark(Bookmark parent,
int pageNum)
Creates a Bookmark with a GoToPage action, and Add it as a child to the parent Bookmark parameter
|
Bookmark |
createBookmark(Bookmark parent,
int pageNum,
int zoomMode)
Creates a Bookmark with a GoToPage action with a zoom mode, and Add it as a child to the parent Bookmark parameter
|
Bookmark |
createBookmark(Bookmark parent,
int pageNum,
int x,
int y,
double scale)
Creates a Bookmark with a GoToPage action that uses x and y coordinates and a zoom scale.
|
Bookmark |
createRootBookmark()
Creates a new root bookmark and saves it in the document catalog.
|
void |
deletePage(int pageIndex)
Deletes a page from this document.
|
void |
deletePages(int startIndex,
int endIndex)
Deletes a range of pages in the document.
|
PDFAssemble |
extractPages(int startIndex,
int endIndex,
OutputStream outStream)
Creates and saves a new PDF document that contains a range of pages from this document.
|
PDFAssemble |
extractPages(int startIndex,
int endIndex,
String outputFile)
Creates and saves a new PDF document that contains a range of pages from this document.
|
DocumentInfo |
getDocumentInfo()
Returns a DocumentInfo object containing the information
section of a PDF document (author, title, etc.)
|
int |
getPageCount()
Returns the number of pages in this document.
|
AllPDFPermissions |
getPDFPermissions()
Returns the AllPDFPermissions object which encompasses this document's PasswordPermissions, DocMDPPermissions, and UsageRightsPermissions.
|
Bookmark |
getRootBookmark()
Returns the 'root' bookmark.
|
static String |
getVersion()
Returns version string for jPDFFields.
|
void |
insertPage(PDFAssemble sourceDoc,
int srcPageIndex,
int dstPageIndex)
Inserts a page into this document at the given index.
|
static void |
loadLicense(InputStream licenseStream)
Method to load a license file from an inputstream.
|
static void |
loadLicense(String licenseFile)
Method to load a license file.
|
void |
saveDocument(OutputStream outStream)
Saves this document to an output stream.
|
void |
saveDocument(String fileName)
Saves this document to a file.
|
static boolean |
setAppletKey(String key,
Applet applet)
Method to unlock the production version of the library.
|
void |
setInitialPage(int pageIndex,
String scale)
Sets the initial page and scale to use when this document is opened with a PDF viewer.
|
void |
setInitialPageLayout(String pageLayout)
Changes the value of the page layout key for this document.
|
void |
setInitialPageMode(String pageMode)
Changes the value of the page mode viewer preference in the document.
|
static boolean |
setKey(String key)
Method to unlock the production version of the library.
|
boolean |
usePermissionsPassword(String ownerPassword)
Tells the PDFAssemble object that the permissions password is known, so
all permissions are granted.
|
public static final String MAGNIFICATION_FIT_WIDTH
public static final String MAGNIFICATION_FIT_HEIGHT
public static final String MAGNIFICATION_FIT_PAGE
public static final String MAGNIFICATION_FIT_ACTUAL
public static final String PAGEMODE_USENONE
public static final String PAGEMODE_USEOUTLINES
public static final String PAGEMODE_USETHUMBS
public static final String PAGEMODE_FULLSCREEN
public static final String PAGEMODE_USEOC
public static final String PAGEMODE_USEATTACHMENTS
public static final String PAGELAYOUT_SINGLEPAGE
public static final String PAGELAYOUT_ONECOLUMN
public static final String PAGELAYOUT_TWOCOLUMNLEFT
public static final String PAGELAYOUT_TWOPAGELEFT
public PDFAssemble() throws PDFException
PDFException
public PDFAssemble(InputStream inStream, IPassword password) throws PDFException
inStream
- InputStream to read the PDF document.password
- An object that provides passwords to open the document, leave null if not needed.
When working with documents that have no passwords, the host application should pass null for the
value of this parameter. When documents are known to have passwords, the host application should
pass an instance of the PDFPassword
class that can hold a single
password or a list of passwords.PDFException
public PDFAssemble(String fileName, IPassword password) throws PDFException
fileName
- Name of the PDF file.password
- An object that provides passwords to open the document, leave null if not needed.
When working with documents that have no passwords, the host application should pass null for the
value of this parameter. When documents are known to have passwords, the host application should
pass an instance of the PDFPassword
class that can hold a single
password or a list of passwords.PDFException
public PDFAssemble(URL url, IPassword password) throws PDFException
url
- Location of the PDF document.password
- An object that provides passwords to open the document, leave null if not needed.
When working with documents that have no passwords, the host application should pass null for the
value of this parameter. When documents are known to have passwords, the host application should
pass an instance of the PDFPassword
class that can hold a single
password or a list of passwords.PDFException
public void close()
public int getPageCount()
public DocumentInfo getDocumentInfo()
public static String getVersion()
public void appendDocument(PDFAssemble appendDoc) throws PDFException
appendDoc
- Document to be appended.PDFException
public void appendPage(PDFAssemble source, int pageIndex) throws PDFException
source
- The document from which to append the page.pageIndex
- The index of the page to append from the source document.PDFException
public void insertPage(PDFAssemble sourceDoc, int srcPageIndex, int dstPageIndex) throws PDFException
sourceDoc
- The document from which to append the page.srcPageIndex
- The index of the page to append from the source document.\dstPageIndex
- The index of the page at which to insert the new page.PDFException
public void deletePage(int pageIndex) throws PDFException
pageIndex
- Index of the page to remove.PDFException
public void deletePages(int startIndex, int endIndex) throws PDFException
startIndex
- The index of the first page to delete.endIndex
- The index of the last page to delete, inclusive.PDFException
public PDFAssemble extractPages(int startIndex, int endIndex, String outputFile) throws IOException, PDFException
startIndex
- The first page to include in the new document.endIndex
- The last page to include in the new document.outputFile
- The path to the file to save the PDF document in.IOException
- Any errors writing the filePDFException
- Any errors extracting the pagespublic PDFAssemble extractPages(int startIndex, int endIndex, OutputStream outStream) throws IOException, PDFException
startIndex
- The first page to include in the new document.endIndex
- The last page to include in the new document.outStream
- The output stream to write the new document to.IOException
- Any errors writing the filePDFException
- Any errors extracting the pagespublic Bookmark createRootBookmark() throws PDFException
PDFException
public Bookmark getRootBookmark()
public void saveDocument(String fileName) throws IOException, PDFException
fileName
- Name of the file to save the document.IOException
PDFException
public void saveDocument(OutputStream outStream) throws IOException, PDFException
outStream
- OutputStream where the document will be written to.IOException
PDFException
public static boolean setAppletKey(String key, Applet applet)
key
- Production key.public static boolean setKey(String key)
key
- Production key.public static void loadLicense(InputStream licenseStream) throws LicenseException
licenseStream
- The input stream for the license file contents.LicenseException
- If there are any problems with the license filepublic static void loadLicense(String licenseFile) throws LicenseException, IOException
licenseFile
- The full path to the license file.LicenseException
- If there are any problems with the license fileIOException
public boolean usePermissionsPassword(String ownerPassword) throws PDFException
ownerPassword
- The permissions passwordPDFException
public final AllPDFPermissions getPDFPermissions()
public void setInitialPageMode(String pageMode) throws PDFException
pageMode
- The new page mode. This value has to be one of:PDFException
public void setInitialPageLayout(String pageLayout) throws PDFException
pageLayout
- The new page mode. This value has to be one of:PDFException
public void setInitialPage(int pageIndex, String scale) throws PDFException
pageIndex
- The index of the page (0 based) to display upon opening the document. If this value is -1, this method will clear
the initial page entry.scale
- The scale to use when displaying the page. This argument can be one of the followingPDFException
public void addGoToPage(Bookmark bookmark, int pageNum) throws PDFException
bookmark
- The Bookmark to add the GotoPage Action topageNum
- The page number to display with this bookmarkPDFException
public void addGoToPage(Bookmark bookmark, int pageNum, int x, int y, double scale) throws PDFException
bookmark
- The Bookmark to add the GotoPage Action topageNum
- The page number to display with this bookmarkx
- The x coordinate to display of the pagey
- The y coordinate to display of the pagescale
- The zoom scale as a decimal. 0.5 will be 50% zoom, 5 will be 500%. Set to -1 or 0 to retain the current zoom valuePDFException
public void addGoToPage(Bookmark bookmark, int pageNum, int zoomMode) throws PDFException
bookmark
- The Bookmark to add the GotoPage Action topageNum
- The page number to display with this bookmarkzoomMode
- A type of zoom defined by the following constants:PDFException
public Bookmark createBookmark(Bookmark parent, int pageNum) throws PDFException
parent
- The parent Bookmark of the Bookmark to be createdpageNum
- The page number to display with this bookmarkPDFException
public Bookmark createBookmark(Bookmark parent, int pageNum, int x, int y, double scale) throws PDFException
parent
- The parent Bookmark of the Bookmark to be createdpageNum
- The page number to display with this bookmarkx
- The x coordinate to display of the pagey
- The y coordinate to display of the pagescale
- The zoom scale as a decimal. 0.5 will be 50% zoom, 5 will be 500%. Set to -1 or 0 to retain the current zoom valuePDFException
public Bookmark createBookmark(Bookmark parent, int pageNum, int zoomMode) throws PDFException
parent
- The parent Bookmark of the Bookmark to be createdpageNum
- The page number to display with this bookmarkzoomMode
- A type of zoom defined by the following constants:PDFException