public class

PDFDoc

extends Doc
implements AutoCloseable
java.lang.Object
   ↳ com.pdftron.sdf.Doc
     ↳ com.pdftron.pdf.PDFDoc
Known Direct Subclasses

Class Overview

PDFDoc is a high-level class describing a single PDF (Portable Document Format) document. Most applications using PDFNet will use this class to open existing PDF documents, or to create new PDF documents from scratch.

The class offers a number of entry points into the document. For example:

  • To access pages use pdfdoc.getPageIterator() or pdfdoc.getPage(page_num).
  • To access form fields use pdfdoc.getFieldIterator(), pdfdoc.getFieldIterator(name) or pdfdoc.getField(name).
  • To access document's meta-data use pdfdoc.GetDocInfo().
  • To access the outline tree use pdfdoc.GetFirstBookmark().
  • To access low-level Document Catalog use pdfdoc.GetRoot(). ...

The class also offers utility methods to slit and merge PDF pages, to create new pages, to flatten forms, to change security settings, etc.

Summary

Nested Classes
enum PDFDoc.ActionTriggerMode  
enum PDFDoc.FlattenMode  
enum PDFDoc.InsertBookmarkMode  
enum PDFDoc.SignaturesVerificationStatus  
Constants
int e_action_trigger_doc_did_print This constant is deprecated. use DOC_DID_PRINT instead.
int e_action_trigger_doc_did_save This constant is deprecated. use DOC_DID_SAVE instead.
int e_action_trigger_doc_will_close This constant is deprecated. use DOC_WILL_CLOSE instead.
int e_action_trigger_doc_will_print This constant is deprecated. use ActionTriggerMode#DOC_will_PRINT instead.
int e_action_trigger_doc_will_save This constant is deprecated. use DOC_WILL_SAVE instead.
int e_annots_only
int e_both
int e_flatten_all This constant is deprecated. use ALL instead.
int e_flatten_annots_only This constant is deprecated. use ANNOTS instead.
int e_flatten_forms_only This constant is deprecated. use FORMS instead.
int e_flatten_link_only This constant is deprecated. use LINK instead.
int e_forms_only
int e_insert_bookmark This constant is deprecated. use INSERT instead.
int e_none This constant is deprecated. use NONE instead.
Fields
public Filter mCustomFilter
Public Constructors
PDFDoc()
Default constructor.
PDFDoc(SDFDoc sdfdoc)
Create a PDF document from an existing SDF/Cos document.
PDFDoc(String filepath)
Open an existing PDF document.
PDFDoc(Filter stream)
Open an existing PDF document.
PDFDoc(byte[] buf)
Open a SDF/Cos document from a memory buffer.
PDFDoc(InputStream stream)
Open an existing PDF document from an InputStream.
PDFDoc(InputStream stream, int size)
Open an existing PDF document from an InputStream.
Public Methods
static PDFDoc __Create(long impl)
long __GetHandle()
void addFileAttachment(String file_key, FileSpec embedded_file)
Associates a file attachment with the document.
void addHighlights(String hilite)
AddHighlights is used to highlight text in a document using 'Adobe's Highlight File Format' (Technical Note #5172 ).
void addRootBookmark(Bookmark root_bookmark)
Adds/links the specified Bookmark to the root level of document's outline tree.
long addSignatureHandler(SignatureHandler signature_handler)
Adds a signature handler to the signature manager.
long addStdSignatureHandler(byte[] pkcs12_keybuffer, String pkcs12_keypass)
Adds a standard (built-in) signature handler to the signature manager.
long addStdSignatureHandler(String pkcs12_keyfile, String pkcs12_keypass)
Adds a standard (built-in) signature handler to the signature manager.
int appendTextDiff(PDFDoc doc1, PDFDoc doc2)
Imports two external PDFs and highlights the differences between them.
int appendTextDiff(PDFDoc doc1, PDFDoc doc2, TextDiffOptions options)
Imports two external PDFs and highlights the differences between them.
int appendTextDiff(Page page1, Page page2)
Imports two external pages and highlights the differences between them.
void appendVisualDiff(Page p1, Page p2, DiffOptions opts)
Generates a PDF diff of the given pages by overlaying and blending them on top of each other, then appends that diff as a new page in this document.
void close()
Destructor.
DigitalSignatureField createDigitalSignatureField()
DigitalSignatureField createDigitalSignatureField(String in_sig_field_name)
Creates an unsigned digital signature form field inside the document.
Obj createIndirectArray()
Create the indirect array.
Obj createIndirectBool(boolean value)
Create the indirect boolean.
Obj createIndirectDict()
Create the indirect dictionary
Obj createIndirectName(String name)
Create SDF/Cos indirect name Unlike direct objects, indirect objects can be referenced by more than one object (i.e.
Obj createIndirectNull()
Create the indirect null.
Obj createIndirectNumber(double value)
Create the indirect number.
Obj createIndirectStream(FilterReader data)
Create the indirect stream.
Obj createIndirectStream(FilterReader data, Filter filter_chain)
Create the indirect stream.
Obj createIndirectStream(byte[] data)
Create the indirect stream.
Obj createIndirectStream(byte[] data, Filter filter_chain)
Create the indirect stream.
Obj createIndirectString(byte[] value)
Create the indirect string from buffer
Obj createIndirectString(String str)
Create the indirect string.
FDFDoc fdfExtract(int extractFlag)
Extract form data and/or annotations to FDF
FDFDoc fdfExtract(Annot[] annotations)
Extract annotations to FDF
FDFDoc fdfExtract()
Extract form data to FDF
FDFDoc fdfExtract(ArrayList<Annot> annot_list)
Extract annotations to FDF
FDFDoc fdfExtract(ArrayList<Annot> annot_added, ArrayList<Annot> annot_modified, ArrayList<Annot> annot_deleted)
Extract annotations to FDF
void fdfMerge(FDFDoc fdf_doc)
Import form data from FDF file to PDF interactive form.
void fdfUpdate(FDFDoc fdf_doc)
Replace existing form and annotation data with those imported from the FDF file.
Field fieldCreate(String field_name, int type, String field_value)
Create a new interactive form field
Field fieldCreate(String field_name, int type, String field_value, String def_field_value)
Create a new interactive form field
Field fieldCreate(String field_name, int type)
Create a new interactive form Field.
Field fieldCreate(String field_name, int type, Obj field_value)
Create a new interactive form field
Field fieldCreate(String field_name, int type, Obj field_value, Obj def_field_value)
Create a new interactive form field
void flattenAnnotations(boolean forms_only)
Flatten all annotations in the document.
void flattenAnnotations()
Flatten all annotations in the document.
void flattenAnnotationsAdvanced(long flags)
This method is deprecated. use flattenAnnotationsAdvanced(FlattenMode[]) instead. Flatten annotations/forms/links in the document.
void flattenAnnotationsAdvanced(FlattenMode[] flattenModes)
Flatten annotations/forms/links in the document.
void generateThumbnails(long size)
Generates thumbnail images for all the pages in this PDF document.
Obj getAcroForm()
Get the AcroForm Dictionary.
DigitalSignatureFieldIterator getDigitalSignatureFieldIterator()
Retrieves an iterator that iterates over digital signature fields.
DigitalSignatureField.DocumentPermissions getDigitalSignaturePermissions()
Retrieves the most restrictive document permissions locking level from all of the signed digital signatures in the document.
PDFDocInfo getDocInfo()
Get the document infomation
long getDownloadedByteCount()
Returns the number of bytes that have been downloaded, when `hasDownloader()` is True.
Field getField(String field_name)
Get the specified field from field name
FieldIterator getFieldIterator(String field_name)
Get specified FieldIterator from field name
FieldIterator getFieldIterator()
An interactive form (sometimes referred to as an AcroForm) is a collection of fields for gathering information interactively from the user.
String getFileName()
Get the file name.
Bookmark getFirstBookmark()
Get the first bookmark.
Config getOCGConfig()
Get the optional group configuration
Obj getOCGs()
Get the optional content groups
Action getOpenAction()
Get the open action.
Page getPage(int page_number)
Get the page object from given page number
int getPageCount()
Get the page count.
PageIterator getPageIterator(int page_number)
Get the page iterator from given page number
PageIterator getPageIterator()
Get the page iterator.
PageLabel getPageLabel(int page_num)
Get the specified page label
Obj getPages()
Get the pages.
Obj getRoot()
Get the root of the document
SDFDoc getSDFDoc()
Get the underlying SDFDoc object.
SecurityHandler getSecurityHandler()
Get the security handler.
SignatureHandler getSignatureHandler(long signature_handler_id)
Gets the associated signature handler instance from the signature manager by looking it up with the handler name.
STree getStructTree()
Get the structure tree root
long getTotalRemoteByteCount()
Returns the document's total size in bytes, when `HasDownloader()` is True.
Obj getTrailer()
Get the document's trailer.
Obj getTriggerAction(PDFDoc.ActionTriggerMode triggerMode)
Get the Action associated with the selected PDFDoc Trigger event.
Obj getTriggerAction(int trigger)
This method is deprecated. use INCREMENTAL instead. Get the Action associated with the selected PDFDoc Trigger event.
UndoManager getUndoManager()
PDFDocViewPrefs getViewPrefs()
Get the view preferences
boolean hasChangesSinceSnapshot()
Call this function to determine whether the document has been modified since the last Undo/Redo snapshot was taken
boolean hasDownloader()
Indicates whether this document was created via the `PDFViewCtrl` method `OpenURLAsync`.
boolean hasOC()
Checks for optional content
boolean hasRepairedXRef()
Checks whether or not the underlying file has an XRef table that had to be repaired when the file was opened.
boolean hasSignatures()
Indicates whether this documents contains any digital signatures.
static int highlightTextDiff(PDFDoc doc1, PDFDoc doc2, TextDiffOptions options)
Highlights the differences between the external PDFs.
Page[] importPages(Page[] pages, boolean import_bookmarks)
Import given pages into current PDFDoc
Page[] importPages(Page[] pages)
The function imports a list of pages to this documents.
boolean initSecurityHandler(Object custom_data)
Initialize the security handler.
boolean initSecurityHandler()
Initializes document's SecurityHandler.
boolean initStdSecurityHandler(String password)
Initializes document's SecurityHandler using the supplied password.
boolean initStdSecurityHandler(byte[] passwordBuffer)
Initializes document's SecurityHandler using the supplied password.
void initializeJSContext()
Initializes the JS context.
void insertPages(int insertBeforeThisPage, PDFDoc sourceDoc, int startPage, int endPage, int insertFlag, ProgressMonitor monitor)
This method is deprecated. use insertPages(int, PDFDoc, int, int, InsertBookmarkMode, ProgressMonitor) instead. Inserts a range of pages from specified PDFDoc
void insertPages(int insertBeforeThisPage, PDFDoc sourceDoc, int startPage, int endPage, PDFDoc.InsertBookmarkMode insertBookmarkMode, ProgressMonitor monitor)
Inserts a range of pages from specified PDFDoc
void insertPages(int insertBeforeThisPage, PDFDoc sourceDoc, PageSet sourcePageSet, int insertFlag, ProgressMonitor monitor)
This method is deprecated. use insertPages(int, PDFDoc, PageSet, InsertBookmarkMode, ProgressMonitor) instead. Inserts a range of pages from specified PDFDoc using PageSet
void insertPages(int insertBeforeThisPage, PDFDoc sourceDoc, PageSet sourcePageSet, PDFDoc.InsertBookmarkMode insertBookmarkMode, ProgressMonitor monitor)
Inserts a range of pages from specified PDFDoc using PageSet
boolean isEncrypted()
Checks if PDFDoc is encrypted.
boolean isLinearized()
Call this function to determine whether the document is represented in linearized (fast web view) format.
boolean isModified()
Call this function to determine whether the document has been modified since it was last saved.
boolean isTagged()
Checks if current document is tagged.
void lock()
Locks the document to prevent competing threads from accessiong the document at the same time.
void lockRead()
Locks the document to prevent competing write threads (using lock()) from accessing the document at the same time.
void mergeXFDF(Filter xfdf_contents, String user_id)
Import form data from XFDF contents into this PDF.
void mergeXFDF(Filter xfdf_contents, MergeXFDFOptions opts)
Merge existing form and annotation data with those imported from the XFDF file.
void mergeXFDFString(String xfdf_contents, MergeXFDFOptions opts)
Merge existing form and annotation data with those imported from the XFDF file.
void mergeXFDFString(String xfdf_contents, String user_id)
Import form data from XFDF contents into this PDF.
void movePages(int moveBeforeThisPage, PDFDoc sourceDoc, PageSet sourcePageSet, int insertFlag, ProgressMonitor monitor)
This method is deprecated. use movePages(int, PDFDoc, PageSet, InsertBookmarkMode, ProgressMonitor) instead. Moves a range of pages from specified PDFDoc. Pages are deleted from source document after move.

Note: MovePages function does not save sourceDoc. It merely delete pages in memory. For permanent changes, PDFDoc::Save should be used to save sourceDoc after function exists.

void movePages(int moveBeforeThisPage, PDFDoc sourceDoc, PageSet sourcePageSet, PDFDoc.InsertBookmarkMode insertBookmarkMode, ProgressMonitor monitor)
Moves a range of pages from specified PDFDoc.
void movePages(int moveBeforeThisPage, PDFDoc sourceDoc, int startPage, int endPage, PDFDoc.InsertBookmarkMode insertBookmarkMode, ProgressMonitor monitor)
Moves a range of pages from specified PDFDoc.
void movePages(int moveBeforeThisPage, PDFDoc sourceDoc, int startPage, int endPage, int insertFlag, ProgressMonitor monitor)
This method is deprecated. use #movePages(int, PDFDoc, PDFDoc, int, int, InsertBookmarkMode, ProgressMonitor) instead. Moves a range of pages from specified PDFDoc. Pages are deleted from source document after move.

Note: MovePages function does not save sourceDoc. It merely delete pages in memory. For permanent changes, PDFDoc::Save should be used to save sourceDoc after function exists.

Page pageCreate(Rect media_box)
Create page with given media box
Page pageCreate()
Create a new, empty page in the document.
void pageInsert(PageIterator where, Page page)
Insert/Import a single page at a specific location in the page sequence.
void pagePushBack(Page page)
Adds a page to the end of a documents's page sequence.
void pagePushFront(Page page)
Adds a page to the beginning of a documents's page sequence.
void pageRemove(PageIterator page_itr)
Remove specified page
void refreshAnnotAppearances(RefreshOptions opts)
Generates the appearance stream for annotations in the document using the specified options.
void refreshAnnotAppearances()
Generates the appearance stream for annotations in the document using the default options.
void refreshFieldAppearances()
Regenerates the appearance stream for every widget annotation in the document Call this method if you modified field's value and would like to update field's appearances.
void removePageLabel(int page_num)
Removes the page label that is attached to the specified page, effectively merging the specified range with the previous page label sequence.
void removeSecurity()
Removes all security for the document.
void removeSignatureHandler(long signature_handler_id)
Removes a signature handler from the signature manager.
void save(Filter output_filter, long flags)
This method is deprecated. use save(Filter, SDFDoc.SaveMode) instead. Saves the document to a CustomFilter.

Note: Save will modify the PDFDoc object's internal representation. As such, the user should acquire a write lock before calling save.

void save(OutputStream stream, SaveMode[] saveModes, ProgressMonitor progress)
Saves the document to an OutputStream.
byte[] save(SaveMode[] saveModes, ProgressMonitor progress)
Saves the document to a memory buffer.
void save(long flags)
This method is deprecated. use save() instead. Saves the document incrementally to the same location as it was opened from. This function only works if the PDFDoc was opened using a FileDescriptorFilter.

Note: If the original pdf has a corrupt xref table (see HasRepairedXref or http://www.pdftron.com/kb_corrupt_xref), then this save can not be used.

byte[] save(SDFDoc.SaveMode saveMode, ProgressMonitor progress)
Saves the document to a memory buffer.
byte[] save(long flags, ProgressMonitor progress)
This method is deprecated. use save(SDFDoc.SaveMode, ProgressMonitor) instead. Saves the document to a memory buffer.

Note: - Save will modify the PDFDoc object's internal representation. As such, the user should acquire a write lock before calling save.

void save(OutputStream stream, SDFDoc.SaveMode saveMode, ProgressMonitor progress, int size)
Saves the document to an OutputStream.
void save(OutputStream stream, long flags, ProgressMonitor progress)
This method is deprecated. use save(OutputStream, SDFDoc.SaveMode, ProgressMonitor) instead. Saves the document to an OutputStream.

Note: - Save will modify the PDFDoc object's internal representation. As such, the user should acquire a write lock before calling save.

void save(OutputStream stream, SDFDoc.SaveMode saveMode, ProgressMonitor progress)
Saves the document to an OutputStream.
void save(OutputStream stream, long flags, ProgressMonitor progress, int size)
This method is deprecated. use save(OutputStream, SDFDoc.SaveMode, ProgressMonitor, int) instead. Saves the document to an OutputStream. Note: - Save will modify the PDFDoc object's internal representation. As such, the user should acquire a write lock before calling save.

void save(String path, long flags, ProgressMonitor progress)
This method is deprecated. use save(String, SDFDoc.SaveMode, ProgressMonitor) instead. Saves the document to a file. If a full save is requested to the original path, the file is saved to a file system-determined temporary file, the old file is deleted, and the temporary file is renamed to path. A full save with remove unused or linearization option may re-arrange object in the cross reference table. Therefore all pointers and references to document objects and resources should be re acquired in order to continue document editing. In order to use incremental save the specified path must match original path and e_incremental flag bit should be set.

Note: In a multi-threaded environment, the user is expected to acquire a write lock before attempting to save the document.

Note: - Save will modify the PDFDoc object's internal representation. As such, the user should acquire a write lock before calling save.

Note: - If the original pdf has a corrupt xref table (see HasRepairedXref or http://www.pdftron.com/kb_corrupt_xref), then it can not be saved using the e_incremental flag.

void save(String path, SaveMode[] saveModes, ProgressMonitor progress)
Saves the document to a file.
void save(String path, SDFDoc.SaveMode saveMode, ProgressMonitor progress)
Saves the document to a file.
void save(Filter output_filter, SDFDoc.SaveMode saveMode)
Saves the document to a CustomFilter.
void save(OutputStream stream, SaveMode[] saveModes, ProgressMonitor progress, int size)
Saves the document to an OutputStream.
void save()
Saves the document incrementally to the same location as it was opened from.
void save(Filter output_filter, SaveMode[] saveModes)
Saves the document to a file.
void saveCustomSignature(byte[] in_signature, DigitalSignatureField in_field, Filter output_filter)
Saves a custom signature Contents to a document which has been prepared to receive it.
void saveCustomSignature(byte[] in_signature, DigitalSignatureField in_field, String in_path)
Saves a custom signature Contents to a document which has been prepared to receive it.
boolean saveIncrementalData(String path)
Saves only the incremental portion of the PDFDoc to path Works like saving using INCREMENTAL but only writes the portion that would have been appended to path.
void saveViewerOptimized(String path, ViewerOptimizedOptions opts)
Applies optimizations to improve viewing speed and saves the document to the specified file.
byte[] saveViewerOptimized(ViewerOptimizedOptions opts)
Applies optimizations to improve viewing speed and saves the document to a memory buffer.
void setOpenAction(Action action)
Set the Action that will be triggered when the document is opened.
void setPageLabel(int page_num, PageLabel label)
Attaches a label to a page.
void setSecurityHandler(SecurityHandler handler)
The function sets a new SecurityHandler as the current security handler.
boolean timedLock(int milliseconds)
Try locking the document, waiting no longer than specified number of milliseconds.
boolean timedLockRead(int milliseconds)
Tries to obtain a read lock the document for milliseconds duration, and returns true if the lock was successfully acquired
boolean tryLock()
Try locking the document in non-blocking manner.
boolean tryLockRead()
Try obtaining a read lock on the document in non-blocking manner.
void unlock()
Unlock the document.
void unlockRead()
Removes the read lock from the document.
PDFDoc.SignaturesVerificationStatus verifySignedDigitalSignatures(VerificationOptions in_opts)
Attempts to verify all signed cryptographic digital signatures in the document, ignoring unsigned signatures.
[Expand]
Inherited Methods
From class com.pdftron.sdf.Doc
From class java.lang.Object
From interface java.lang.AutoCloseable

Constants

public static final int e_action_trigger_doc_did_print

This constant is deprecated.
use DOC_DID_PRINT instead.

Triggered after printing a document

Constant Value: 21 (0x00000015)

public static final int e_action_trigger_doc_did_save

This constant is deprecated.
use DOC_DID_SAVE instead.

Triggered after saving a document

Constant Value: 19 (0x00000013)

public static final int e_action_trigger_doc_will_close

This constant is deprecated.
use DOC_WILL_CLOSE instead.

Triggered before closing a document

Constant Value: 17 (0x00000011)

public static final int e_action_trigger_doc_will_print

This constant is deprecated.
use ActionTriggerMode#DOC_will_PRINT instead.

Triggered before printing a document

Constant Value: 20 (0x00000014)

public static final int e_action_trigger_doc_will_save

This constant is deprecated.
use DOC_WILL_SAVE instead.

Triggered before saving a document

Constant Value: 18 (0x00000012)

public static final int e_annots_only

Constant Value: 1 (0x00000001)

public static final int e_both

Constant Value: 2 (0x00000002)

public static final int e_flatten_all

This constant is deprecated.
use ALL instead.

flatten all

Constant Value: 8 (0x00000008)

public static final int e_flatten_annots_only

This constant is deprecated.
use ANNOTS instead.

flatten only annots

Constant Value: 2 (0x00000002)

public static final int e_flatten_forms_only

This constant is deprecated.
use FORMS instead.

flatten only forms

Constant Value: 1 (0x00000001)

public static final int e_flatten_link_only

This constant is deprecated.
use LINK instead.

flatten only links

Constant Value: 4 (0x00000004)

public static final int e_forms_only

Constant Value: 0 (0x00000000)

public static final int e_insert_bookmark

This constant is deprecated.
use INSERT instead.

insert bookmark

Constant Value: 1 (0x00000001)

public static final int e_none

This constant is deprecated.
use NONE instead.

do not insert bookmark

Constant Value: 0 (0x00000000)

Fields

public Filter mCustomFilter

Public Constructors

public PDFDoc ()

Default constructor. Creates an empty new document.

public PDFDoc (SDFDoc sdfdoc)

Create a PDF document from an existing SDF/Cos document.

Note: the SDFDoc will become invalid. If you would like to access the low level document use GetSDFDoc

Parameters
sdfdoc a pointer to the SDF document. Created PDFDoc will take the ownership of the low-level document.

public PDFDoc (String filepath)

Open an existing PDF document.

Note: Make sure to call InitSecurityHandler() after PDFDoc(...) in case a document is encrypted

Parameters
filepath - pathname to the file.

public PDFDoc (Filter stream)

Open an existing PDF document.

Note: if the input stream doesn't support Seek() operation the document will load whole data stream in memory before parsing. In case of linearized PDF, the document may be parsed on-the-fly while it is being loaded in memory. Note that since StdFile implements Seek() interface, the document does not have to be fully in memory before it is used.

Note: Make sure to call InitSecurityHandler() after PDFDoc(...) for encrypted documents.

Parameters
stream - input stream containing a serialized document. The input stream may be a random-access file, memory buffer, slow HTTP connection etc.

public PDFDoc (byte[] buf)

Open a SDF/Cos document from a memory buffer.

Note: the document should be fully loaded in the memory buffer.

Parameters
buf - a memory buffer containing the serialized document

public PDFDoc (InputStream stream)

Open an existing PDF document from an InputStream.

Note: Make sure to call InitSecurityHandler() after FDFDoc(...) for encrypted documents.

Parameters
stream - input stream containing a serialized document.
Throws
PDFNetException
IOException Signals that an I/O exception has occurred.
PDFNetException

public PDFDoc (InputStream stream, int size)

Open an existing PDF document from an InputStream.

Note: Make sure to call InitSecurityHandler() after FDFDoc(...) for encrypted documents.

Parameters
stream - input stream containing a serialized document.
size - the expected size of the input stream.
Throws
PDFNetException
IOException Signals that an I/O exception has occurred.
PDFNetException

Public Methods

public static PDFDoc __Create (long impl)

public long __GetHandle ()

public void addFileAttachment (String file_key, FileSpec embedded_file)

Associates a file attachment with the document. The file attachment will be displayed in the user interface of a viewer application (in Acrobat this is File Attachment tab). The function differs from Annot.CreateFileAttachment() because it associates the attachment with the whole document instead of an annotation on a specific page.

Note: Another way to associate a file attachment with the document is using SDF::NameTree: {@code SDF.NameTree names = SDF.NameTree.Create(doc, "EmbeddedFiles"); names.put(file_key, file_keysz, embedded_file.GetSDFObj());

Parameters
file_key A key/name under which the attachment will be stored.
embedded_file the embedded file
Throws
PDFNetException }

public void addHighlights (String hilite)

AddHighlights is used to highlight text in a document using 'Adobe's Highlight File Format' (Technical Note #5172 ). The method will parse the character offset data and modify the current document by adding new highlight annotations.

Parameters
hilite filename for the highlight file or a data buffer containing XML data.

public void addRootBookmark (Bookmark root_bookmark)

Adds/links the specified Bookmark to the root level of document's outline tree.

Parameters
root_bookmark root bookmark. It must not be linked (must not be belong) to a bookmark tree.

public long addSignatureHandler (SignatureHandler signature_handler)

Adds a signature handler to the signature manager. There can only be one signature handler of a given name that can exist in the signature manager. A signature handler which name already exists in the signature manager cannot be added.

Parameters
signature_handler The signature handler instance to add to the signature manager.
Returns
  • A unique ID representing the SignatureHandler within the SignatureManager.

public long addStdSignatureHandler (byte[] pkcs12_keybuffer, String pkcs12_keypass)

Adds a standard (built-in) signature handler to the signature manager. This method will use cryptographic algorithm based on Adobe.PPKLite/adbe.pkcs7.detached filter to sign a PDF.

Parameters
pkcs12_keybuffer The private key certificate store to use. (As an array of bytes).
pkcs12_keypass The passphrase for the provided private key.
Returns
  • A unique ID representing the SignatureHandler within the SignatureManager.

public long addStdSignatureHandler (String pkcs12_keyfile, String pkcs12_keypass)

Adds a standard (built-in) signature handler to the signature manager. This method will use cryptographic algorithm based on Adobe.PPKLite/adbe.pkcs7.detached filter to sign a PDF.

Parameters
pkcs12_keyfile The private key certificate store to use.
pkcs12_keypass The passphrase for the provided private key.
Returns
  • A unique ID representing the SignatureHandler within the SignatureManager.

public int appendTextDiff (PDFDoc doc1, PDFDoc doc2)

Imports two external PDFs and highlights the differences between them. This function appends alternating pages from the two input documents into the current document. Note: Each contiguous block of change is considered a single difference. A deletion immediately followed by an insertion is considered a single edit.

Parameters
doc1 is the before document, the basis of the comparison (read-only)
doc2 is the after document, to which the basis is compared (read-only)
Returns
  • the total number of differences found

public int appendTextDiff (PDFDoc doc1, PDFDoc doc2, TextDiffOptions options)

Imports two external PDFs and highlights the differences between them. This function appends alternating pages from the two input documents into the current document. Note: Each contiguous block of change is considered a single difference. A deletion immediately followed by an insertion is considered a single edit.

Parameters
doc1 is the before document, the basis of the comparison (read-only)
doc2 is the after document, to which the basis is compared (read-only)
options processing options (optional)
Returns
  • the total number of differences found

public int appendTextDiff (Page page1, Page page2)

Imports two external pages and highlights the differences between them. This function adds two new pages to the current document. The two input pages are typically coming from two different PDF files. Note: Each contiguous block of change is considered a single difference. A deletion immediately followed by an insertion is considered a single edit.

Parameters
page1 is the before page, the basis of the comparison (read-only)
page2 is the after page, to which the basis is compared (read-only)
Returns
  • the total number of differences found

public void appendVisualDiff (Page p1, Page p2, DiffOptions opts)

Generates a PDF diff of the given pages by overlaying and blending them on top of each other, then appends that diff as a new page in this document.

public void close ()

Destructor. Close PDFDoc.

public DigitalSignatureField createDigitalSignatureField ()

public DigitalSignatureField createDigitalSignatureField (String in_sig_field_name)

Creates an unsigned digital signature form field inside the document.

Parameters
in_sig_field_name The fully-qualified name to give the digital signature field. If one is not provided, a unique name is created automatically.
Returns
  • A DigitalSignatureField object representing the created digital signature field.

public Obj createIndirectArray ()

Create the indirect array.

Returns
  • the created indirect array

public Obj createIndirectBool (boolean value)

Create the indirect boolean.

Returns
  • the created indirect boolean

public Obj createIndirectDict ()

Create the indirect dictionary

Returns
  • the created indirect dictionary

public Obj createIndirectName (String name)

Create SDF/Cos indirect name Unlike direct objects, indirect objects can be referenced by more than one object (i.e. indirect objects they can be shared).

Returns
  • the created indirect name

public Obj createIndirectNull ()

Create the indirect null.

Returns
  • the created indirect null

public Obj createIndirectNumber (double value)

Create the indirect number.

Returns
  • the created indirect number

public Obj createIndirectStream (FilterReader data)

Create the indirect stream.

Returns
  • the created indirect stream

public Obj createIndirectStream (FilterReader data, Filter filter_chain)

Create the indirect stream.

Returns
  • the created indirect stream

public Obj createIndirectStream (byte[] data)

Create the indirect stream.

Returns
  • the created indirect stream

public Obj createIndirectStream (byte[] data, Filter filter_chain)

Create the indirect stream.

Returns
  • the created indirect stream

public Obj createIndirectString (byte[] value)

Create the indirect string from buffer

Parameters
value input buffer
Returns
  • the created indirect string

public Obj createIndirectString (String str)

Create the indirect string.

Parameters
str value of the indirect string
Returns
  • the created indirect string

public FDFDoc fdfExtract (int extractFlag)

Extract form data and/or annotations to FDF

Parameters
extractFlag specifies extract options
Returns
  • a pointer to the newly created FDF file with an interactive data.

public FDFDoc fdfExtract (Annot[] annotations)

Extract annotations to FDF

Parameters
annotations specifies the array of annotations
Returns
  • the newly created FDF file with an interactive data.

public FDFDoc fdfExtract ()

Extract form data to FDF

Returns
  • a pointer to the newly created FDF file with an interactive data.

public FDFDoc fdfExtract (ArrayList<Annot> annot_list)

Extract annotations to FDF

Parameters
annot_list specifies the array of annotations
Returns
  • a pointer to the newly created FDF file with an interactive data.

public FDFDoc fdfExtract (ArrayList<Annot> annot_added, ArrayList<Annot> annot_modified, ArrayList<Annot> annot_deleted)

Extract annotations to FDF

Parameters
annot_added specifies the array of added annotations
annot_modified specifies the array of modified annotations
annot_deleted specifies the array of deleted annotations
Returns
  • a pointer to the newly created FDF file with an interactive data.

public void fdfMerge (FDFDoc fdf_doc)

Import form data from FDF file to PDF interactive form.

Parameters
fdf_doc - a pointer to the FDF file

public void fdfUpdate (FDFDoc fdf_doc)

Replace existing form and annotation data with those imported from the FDF file. It will make annotations in the FDF match those in the PDF. Since this method avoids updating annotations unnecessarily it works well with incremental save and can sometimes preserve annotation appearances, but it requires that the annotations intended to be in the final document be in the provided FDF file.

Note: Some PDF viewers (like Chrome) cannot display annotations that don't already have an appearance, so it is often desirable to call PDFDoc.RefreshAnnotAppearances after this method to ensure these annotations can still be displayed in those applications.

Note: This method is not suitable for realtime collaboration.

Parameters
fdf_doc - a pointer to the FDF file

public Field fieldCreate (String field_name, int type, String field_value)

Create a new interactive form field

Parameters
field_name name of the field (e.g. "employee.name.first"). field_name must be either a unique name or equal to an existing terminal field name.
type field type (e.g. Field::e_text, Field::e_button, etc.)
Returns
  • the field

public Field fieldCreate (String field_name, int type, String field_value, String def_field_value)

Create a new interactive form field

Parameters
field_name name of the field (e.g. "employee.name.first"). field_name must be either a unique name or equal to an existing terminal field name.
type field type (e.g. Field::e_text, Field::e_button, etc.)
Returns
  • the new form Field.

public Field fieldCreate (String field_name, int type)

Create a new interactive form Field.

Parameters
field_name name of the field (e.g. "employee.name.first"). field_name must be either a unique name or equal to an existing terminal field name.
type field type (e.g. Field::e_text, Field::e_button, etc.)
Returns
  • the new form Field.

public Field fieldCreate (String field_name, int type, Obj field_value)

Create a new interactive form field

Parameters
field_name name of the field (e.g. "employee.name.first"). field_name must be either a unique name or equal to an existing terminal field name.
type field type (e.g. Field::e_text, Field::e_button, etc.)
Returns
  • the new form Field.

public Field fieldCreate (String field_name, int type, Obj field_value, Obj def_field_value)

Create a new interactive form field

Parameters
field_name name of the field (e.g. "employee.name.first"). field_name must be either a unique name or equal to an existing terminal field name.
type field type (e.g. Field::e_text, Field::e_button, etc.)
Returns
  • the new form Field.

public void flattenAnnotations (boolean forms_only)

Flatten all annotations in the document.

Parameters
forms_only if false flatten all annotations, otherwise flatten only form fields.

public void flattenAnnotations ()

Flatten all annotations in the document.

public void flattenAnnotationsAdvanced (long flags)

This method is deprecated.
use flattenAnnotationsAdvanced(FlattenMode[]) instead. Flatten annotations/forms/links in the document.

Parameters
flags - A bit field composed of an OR of the following values:

public void flattenAnnotationsAdvanced (FlattenMode[] flattenModes)

Flatten annotations/forms/links in the document.

Parameters
flattenModes An array of flatten modes (See PDFDoc.FlattenMode).

public void generateThumbnails (long size)

Generates thumbnail images for all the pages in this PDF document.

Parameters
size The maximum dimension (width or height) that thumbnails will have.

public Obj getAcroForm ()

Get the AcroForm Dictionary.

Returns
  • the AcroForm dictionary located in "/Root" or NULL if dictionary is not present.

public DigitalSignatureFieldIterator getDigitalSignatureFieldIterator ()

Retrieves an iterator that iterates over digital signature fields.

Returns
  • An iterator that iterates over digital signature fields.

public DigitalSignatureField.DocumentPermissions getDigitalSignaturePermissions ()

Retrieves the most restrictive document permissions locking level from all of the signed digital signatures in the document.

Returns
  • An enumerated value representing the most restrictive document permission level found in the document.

public PDFDocInfo getDocInfo ()

Get the document infomation

Returns
  • The class representing document information metadata. (i.e. entries in the document information dictionary).

public long getDownloadedByteCount ()

Returns the number of bytes that have been downloaded, when `hasDownloader()` is True.

Returns
  • The number bytes downloaded.
Throws
PDFNetException if 'hasDownloader()` returns False, calling this method will result in an exception.

public Field getField (String field_name)

Get the specified field from field name

Parameters
field_name - name of the field (e.g. "employee.name.first").
Returns
  • the new form Field.

public FieldIterator getFieldIterator (String field_name)

Get specified FieldIterator from field name

Parameters
field_name - name of the field (e.g. "employee.name.first").
Returns
  • a FieldIterator referring to an interactive Field or to invalid field if the field name was not found. If a given field name was not found itr.HasNext() will return false. For example:
Throws
PDFNetException FieldIterator itr = pdfdoc.getFieldIterator("name"); if (itr.hasNext()) { string name = itr.current().getName()); else { ...field was not found... } }

public FieldIterator getFieldIterator ()

An interactive form (sometimes referred to as an AcroForm) is a collection of fields for gathering information interactively from the user. A PDF document may contain any number of fields appearing on any combination of pages, all of which make up a single, global interactive form spanning the entire document. The following methods are used to access and manipulate Interactive form fields (sometimes referred to as AcroForms).

Returns
  • an iterator to the first Field in the document. The list of all Fields present in the document can be traversed as follows:
Throws
PDFNetException FieldIterator itr = pdfdoc.getFieldIterator(); for(; itr.hasNext(); itr.next()) { Field field = itr.current(); string s = field.getName(); //For a full sample, please refer to 'InteractiveForms' sample project. }

public String getFileName ()

Get the file name.

Returns
  • The filename of the document if the document is loaded from disk, or empty string if the document is not yet saved or is loaded from a memory buffer.

public Bookmark getFirstBookmark ()

Get the first bookmark.

Returns
  • - the first Bookmark from the document's outline tree. If the Bookmark tree is empty the underlying SDF/Cos Object is null and returned Bookmark is not valid (i.e. Bookmark::IsValid() returns false).

public Config getOCGConfig ()

Get the optional group configuration

Returns
  • the default optional-content configuration for the document from the OCProperties D entry.

public Obj getOCGs ()

Get the optional content groups

Returns
  • the Obj array that contains optional-content groups (OCGs) for the document, or NULL if the document does not contain any OCGs. The order of the groups is not guaranteed to be the creation order, and is not the same as the display order.

public Action getOpenAction ()

Get the open action.

Note: if the document does not nave associated action the returned Action will be null (i.e. Action.IsValid() returns false)

Returns
  • Action that is triggered when the document is opened. The returned action can be either a destination or some other kind of Action (see Section 8.5, 'Actions' in PDF Reference Manual).

public Page getPage (int page_number)

Get the page object from given page number

Parameters
page_number - the page number in document's page sequence. Page numbers in document's page sequence are indexed from 1.
Returns
  • a Page corresponding to a given page number, or null (invalid page) if the document does not contain the given page number.
Throws
PDFNetException Page page = pdfdoc.GetPage(page_num); if (page == null) return; // Page not found

public int getPageCount ()

Get the page count.

Returns
  • the number of pages in the document.

public PageIterator getPageIterator (int page_number)

Get the page iterator from given page number

Parameters
page_number the input page number
Returns
  • the page iterator

public PageIterator getPageIterator ()

Get the page iterator.

Returns
  • an iterator to the first page in the document. Use the Next() method on the returned iterator to traverse all pages in the document. For example:
Throws
PDFNetException PageIterator itr = pdfdoc.getPageIterator(); while (itr.hasNext()) { // Read every page Page page = itr.current(); // ... itr.next() For full sample code, please take a look at ElementReader, PDFPageTest and PDFDraw sample projects. }

public PageLabel getPageLabel (int page_num)

Get the specified page label

Parameters
page_num The page number. Because PDFNet indexes pages starting from 1, page_num must be larger than 0.
Returns
  • the PageLabel that is in effect for the given page. If there is no label object in effect, this method returns an invalid page label object.

public Obj getPages ()

Get the pages.

Returns
  • - A dictionary representing the root of the low level page-tree

public Obj getRoot ()

Get the root of the document

Returns
  • - A dictionary representing the Cos root of the document (/Root entry within the trailer dictionary)

public SDFDoc getSDFDoc ()

Get the underlying SDFDoc object.

Returns
  • document's SDF/Cos document

public SecurityHandler getSecurityHandler ()

Get the security handler.

Note: InitSecurityHandler() should be called before GetSecurityHandler() in order to initialize the handler.

Note: Returned security handler can be modified in order to change the security settings of the existing document. Changes to the current handler will not invalidate the access to the original file and will take effect during document Save().

Note: If the security handler is modified, document will perform a full save even if INCREMENTAL was given in Save() method.

Returns
  • Currently selected SecurityHandler; if there is no security handler selected, returns null.

public SignatureHandler getSignatureHandler (long signature_handler_id)

Gets the associated signature handler instance from the signature manager by looking it up with the handler name. The returned signature handler instance is still owned by the signature manage if found.

Parameters
signature_handler_id The name of the signature handler to get.
Returns
  • The signature handler instance if found, otherwise null.

public STree getStructTree ()

Get the structure tree root

Returns
  • The document's logical structure tree root.

public long getTotalRemoteByteCount ()

Returns the document's total size in bytes, when `HasDownloader()` is True.

Returns
  • The total number of bytes in the remote document.
Throws
PDFNetException if 'hasDownloader()` returns False, calling this method will result in an exception.

public Obj getTrailer ()

Get the document's trailer.

Returns
  • - A dictionary representing the Cos root of the document (document's trailer)

public Obj getTriggerAction (PDFDoc.ActionTriggerMode triggerMode)

Get the Action associated with the selected PDFDoc Trigger event.

Parameters
triggerMode the type of trigger event to get (See PDFDoc.ActionTriggerMode)
Returns
  • The Action Obj if present, otherwise NULL

public Obj getTriggerAction (int trigger)

This method is deprecated.
use INCREMENTAL instead. Get the Action associated with the selected PDFDoc Trigger event.

Parameters
trigger the type of trigger event to get
Returns
  • The Action Obj if present, otherwise NULL

public UndoManager getUndoManager ()

Returns
  • The UndoManager object (one-to-one mapped to document)

public PDFDocViewPrefs getViewPrefs ()

Get the view preferences

Returns
  • Viewer preferences for this document. PDFDocViewPrefs is a high-level utility class that can be used to control the way the document is to be presented on the screen or in print.

public boolean hasChangesSinceSnapshot ()

Call this function to determine whether the document has been modified since the last Undo/Redo snapshot was taken

Returns
  • - true if document was modified, false otherwise

public boolean hasDownloader ()

Indicates whether this document was created via the `PDFViewCtrl` method `OpenURLAsync`.

Returns
  • True if the document was created via the `PDFViewCtrl` method `OpenURLAsync`; False otherwise.

public boolean hasOC ()

Checks for optional content

Returns
  • true if the optional content (OC) feature is associated with the document. The document is considered to have optional content if there is an OCProperties dictionary in the document's catalog, and that dictionary has one or more entries in the OCGs array.

public boolean hasRepairedXRef ()

Checks whether or not the underlying file has an XRef table that had to be repaired when the file was opened. If the document had an invalid XRef table when opened, PDFNet will have repaired the XRef table for its working representation of the document. Note: If this function returns true, it is not possible to incrementally save the document (see http://www.pdftron.com/kb_corrupt_xref)

Returns
  • - true if document was found to be corrupted, and was repaired, during opening and has not been saved since.

public boolean hasSignatures ()

Indicates whether this documents contains any digital signatures.

Returns
  • True if a field or signature dictionary is found.

public static int highlightTextDiff (PDFDoc doc1, PDFDoc doc2, TextDiffOptions options)

Highlights the differences between the external PDFs. The highlights are added directly to the inputs. This function directly adds the highlights to the two input documents. Note: Each contiguous block of change is considered a single difference. A deletion immediately followed by an insertion is considered a single edit.

Parameters
doc1 is the before document, the basis of the comparison
doc2 is the after document, to which the basis is compared
options processing options (optional)
Returns
  • the total number of differences found

public Page[] importPages (Page[] pages, boolean import_bookmarks)

Import given pages into current PDFDoc

Parameters
pages pages to import
import_bookmarks whether to import bookmarks
Returns
  • imported pages

public Page[] importPages (Page[] pages)

The function imports a list of pages to this documents. Although a list of pages can be imported using repeated calls to PageInsert(), PageImport will not import duplicate copies of resources that are shared across pages (such as fonts, images, colorspaces etc). Therefore this method is recommended when a page import list consists of several pages that share the same resources.

Parameters
pages A list of pages to import. All pages should belong to the same source document.
Returns
  • a list of imported pages. Note that imported pages are not placed in the document page sequence. This can be done using methods such as PageInsert(), PagePushBack(), etc.

public boolean initSecurityHandler (Object custom_data)

Initialize the security handler.

Parameters
custom_data specify custom data that should be passed in SecurityHandler::Initialize() callback.
Returns
  • true, if successful

public boolean initSecurityHandler ()

Initializes document's SecurityHandler. This version of InitSecurityHandler() works with Standard and Custom PDF security and can be used in situations where the password is obtained dynamically via user feedback. See EncTest sample for example code. This function should be called immediately after an encrypted document is opened. The function does not have any side effects on documents that are not encrypted. If the security handler was successfully initialized it can be later obtained using GetSecurityHandler() method.

Returns
  • true if the SecurityHandler was successfully initialized (this may include authentication data collection, verification etc.), false otherwise.

public boolean initStdSecurityHandler (String password)

Initializes document's SecurityHandler using the supplied password. This version of InitSecurityHandler() assumes that document uses Standard security and that a password is specified directly. This function should be called immediately after an encrypted document is opened. The function does not have any side effects on documents that are not encrypted. If the security handler was successfully initialized, it can be later obtained using GetSecurityHandler() method.

Parameters
password Specifies the password used to open the document without any user feedback. If you would like to dynamically obtain the password, you need to derive a custom class from StdSecurityHandler() and use InitSecurityHandler() without any parameters. See EncTest sample for example code.
Returns
  • true if the given password successfully unlocked the document, false otherwise.

public boolean initStdSecurityHandler (byte[] passwordBuffer)

Initializes document's SecurityHandler using the supplied password. This version of InitSecurityHandler() assumes that document uses Standard security and that a password is specified directly. This function should be called immediately after an encrypted document is opened. The function does not have any side effects on documents that are not encrypted. If the security handler was successfully initialized, it can be later obtained using GetSecurityHandler() method.

Parameters
passwordBuffer Specifies the password used to open the document without any user feedback. If you would like to dynamically obtain the password, you need to derive a custom class from StdSecurityHandler() and use InitSecurityHandler() without any parameters. See EncTest sample for example code.
Returns
  • true if the given password successfully unlocked the document, false otherwise.

public void initializeJSContext ()

Initializes the JS context.

public void insertPages (int insertBeforeThisPage, PDFDoc sourceDoc, int startPage, int endPage, int insertFlag, ProgressMonitor monitor)

This method is deprecated.
use insertPages(int, PDFDoc, int, int, InsertBookmarkMode, ProgressMonitor) instead. Inserts a range of pages from specified PDFDoc

Parameters
insertBeforeThisPage the destination of the insertion. If less than or equal to 1, the pages are added to the beginning of the document. If larger than the number of pages in the destination document, the pages are appended to the document.
sourceDoc source PDFDoc to insert from
startPage start of the page number to insert
endPage end of the page number to insert
insertFlag specifies insert options
monitor A pointer to the progress interface. NULL if progress tracking is not required.

public void insertPages (int insertBeforeThisPage, PDFDoc sourceDoc, int startPage, int endPage, PDFDoc.InsertBookmarkMode insertBookmarkMode, ProgressMonitor monitor)

Inserts a range of pages from specified PDFDoc

Parameters
insertBeforeThisPage the destination of the insertion. If less than or equal to 1, the pages are added to the beginning of the document. If larger than the number of pages in the destination document, the pages are appended to the document.
sourceDoc source PDFDoc to insert from
startPage start of the page number to insert
endPage end of the page number to insert
insertBookmarkMode specifies insert bookmark option (See PDFDoc.InsertBookmarkMode)
monitor A pointer to the progress interface. NULL if progress tracking is not required.

public void insertPages (int insertBeforeThisPage, PDFDoc sourceDoc, PageSet sourcePageSet, int insertFlag, ProgressMonitor monitor)

This method is deprecated.
use insertPages(int, PDFDoc, PageSet, InsertBookmarkMode, ProgressMonitor) instead. Inserts a range of pages from specified PDFDoc using PageSet

Parameters
insertBeforeThisPage the destination of the insertion. If less than or equal to 1, the pages are added to the beginning of the document. If larger than the number of pages in the destination document, the pages are appended to the document.
sourceDoc source PDFDoc to insert from
sourcePageSet a collection of the page number to insert
insertFlag specifies insert options
monitor A pointer to the progress interface. NULL if progress tracking is not required.

public void insertPages (int insertBeforeThisPage, PDFDoc sourceDoc, PageSet sourcePageSet, PDFDoc.InsertBookmarkMode insertBookmarkMode, ProgressMonitor monitor)

Inserts a range of pages from specified PDFDoc using PageSet

Parameters
insertBeforeThisPage the destination of the insertion. If less than or equal to 1, the pages are added to the beginning of the document. If larger than the number of pages in the destination document, the pages are appended to the document.
sourceDoc source PDFDoc to insert from
sourcePageSet a collection of the page number to insert
insertBookmarkMode specifies insert option (See PDFDoc.InsertBookmarkMode)
monitor A pointer to the progress interface. NULL if progress tracking is not required.

public boolean isEncrypted ()

Checks if PDFDoc is encrypted.

Returns
  • true if the document is/was originally encrypted false otherwise.

public boolean isLinearized ()

Call this function to determine whether the document is represented in linearized (fast web view) format.

Note: Any changes to the document can invalidate linearization. The function will return 'true' only if the original document is linearized and if it is not modified.

In order to provide good performance over relatively slow communication links, PDFNet can generate PDF documents with linearized objects and hint tables that can allow a PDF viewer application to download and view one page of a PDF file at a time, rather than requiring the entire file (including fonts and images) to be downloaded before any of it can be viewed.

To save a document in linearized (fast web view) format you only need to pass LINEARIZED mode in the Save. method.

Returns
  • - true if document is stored in fast web view format, false otherwise.

public boolean isModified ()

Call this function to determine whether the document has been modified since it was last saved.

Returns
  • - true if document was modified, false otherwise

public boolean isTagged ()

Checks if current document is tagged.

Returns
  • true if this document is marked as Tagged PDF, false otherwise.

public void lock ()

Locks the document to prevent competing threads from accessiong the document at the same time. Threads attempting to access the document will wait in suspended state until the thread that owns the lock calls doc.Unlock().

public void lockRead ()

Locks the document to prevent competing write threads (using lock()) from accessing the document at the same time. Other reader threads however, will be allowed to access the document. Threads attempting to obtain write access to the document will wait in suspended state until the thread that owns the lock calls doc.unlockRead(). Note: To avoid deadlocks obtaining a write lock while holding a read lock is not permitted and will throw an exception. If this situation is encountered please either unlock the read lock before the write lock is obtained or acquire a write lock (rather than read lock) in the first place.

public void mergeXFDF (Filter xfdf_contents, String user_id)

Import form data from XFDF contents into this PDF.

Parameters
xfdf_contents - Input Filter which provides the xfdf contents
user_id - The id of the user who is permitting the modifications. This serves to restrict the modifications made to the document, as only annotations with the same user_id can be modified. An empty string allows all modifications.

public void mergeXFDF (Filter xfdf_contents, MergeXFDFOptions opts)

Merge existing form and annotation data with those imported from the XFDF file. It will replace annotations from pdfdocument with matching annotations from XFDF. In order for the annotations to be considered matching, "name" of the xfdf annotation needs to match "NM" of that in pdf. XFDF annotations that don't have a match in the pdf document will be added. For regular xfdf files, no deletions will be made This method also supports command form of xfdf, for those files, deletions will be performed for annotations in "delete" section Since this method avoids updating annotations unnecessarily it works well with incremental save. Note: This method is suitable for realtime collaboration.

Parameters
xfdf_contents - Input Filter which provides the xfdf contents
opts - MergeXFDFOptions object for finer control

public void mergeXFDFString (String xfdf_contents, MergeXFDFOptions opts)

Merge existing form and annotation data with those imported from the XFDF file. It will replace annotations from pdfdocument with matching annotations from XFDF. In order for the annotations to be considered matching, "name" of the xfdf annotation needs to match "NM" of that in pdf. XFDF annotations that don't have a match in the pdf document will be added. For regular xfdf files, no deletions will be made This method also supports command form of xfdf, for those files, deletions will be performed for annotations in "delete" section Since this method avoids updating annotations unnecessarily it works well with incremental save. Note: This method is suitable for realtime collaboration.

Parameters
xfdf_contents - xfdf contents in string form or the path to the xfdf file
opts - MergeXFDFOptions object for finer control

public void mergeXFDFString (String xfdf_contents, String user_id)

Import form data from XFDF contents into this PDF.

Parameters
xfdf_contents - xfdf contents in string form
user_id - The id of the user who is permitting the modifications. This serves to restrict the modifications made to the document, as only annotations with the same user_id can be modified. An empty string allows all modifications.

public void movePages (int moveBeforeThisPage, PDFDoc sourceDoc, PageSet sourcePageSet, int insertFlag, ProgressMonitor monitor)

This method is deprecated.
use movePages(int, PDFDoc, PageSet, InsertBookmarkMode, ProgressMonitor) instead. Moves a range of pages from specified PDFDoc. Pages are deleted from source document after move.

Note: MovePages function does not save sourceDoc. It merely delete pages in memory. For permanent changes, PDFDoc::Save should be used to save sourceDoc after function exists.

Parameters
moveBeforeThisPage the destination of the move. If less than or equal to 1, the pages are moved to the beginning of the document. If larger than the number of pages in the destination document, the pages are moved to the end of document.
sourceDoc source PDFDoc to move from
sourcePageSet a collection of the page number to move
insertFlag specifies insert options
monitor A pointer to the progress interface. NULL if progress tracking is not required.

public void movePages (int moveBeforeThisPage, PDFDoc sourceDoc, PageSet sourcePageSet, PDFDoc.InsertBookmarkMode insertBookmarkMode, ProgressMonitor monitor)

Moves a range of pages from specified PDFDoc. Pages are deleted from source document after move.

Note: MovePages function does not save sourceDoc. It merely delete pages in memory. For permanent changes, PDFDoc::Save should be used to save sourceDoc after function exists.

Parameters
moveBeforeThisPage the destination of the move. If less than or equal to 1, the pages are moved to the beginning of the document. If larger than the number of pages in the destination document, the pages are moved to the end of document.
sourceDoc source PDFDoc to move from
sourcePageSet a collection of the page number to move
insertBookmarkMode specifies insert option (See PDFDoc.InsertBookmarkMode)
monitor A pointer to the progress interface. NULL if progress tracking is not required.

public void movePages (int moveBeforeThisPage, PDFDoc sourceDoc, int startPage, int endPage, PDFDoc.InsertBookmarkMode insertBookmarkMode, ProgressMonitor monitor)

Moves a range of pages from specified PDFDoc. Pages are deleted from source document after move.

Note: MovePages function does not save sourceDoc. It merely delete pages in memory. For permanent changes, PDFDoc::Save should be used to save sourceDoc after function exists.

Parameters
moveBeforeThisPage the destination of the move. If less than or equal to 1, the pages are moved to the beginning of the document. If larger than the number of pages in the destination document, the pages are moved to the end of document.
sourceDoc source PDFDoc to move from
startPage start of the page number to move
endPage end of the page number to move
insertBookmarkMode specifies insert option (See PDFDoc.InsertBookmarkMode)
monitor A pointer to the progress interface. NULL if progress tracking is not required.

public void movePages (int moveBeforeThisPage, PDFDoc sourceDoc, int startPage, int endPage, int insertFlag, ProgressMonitor monitor)

This method is deprecated.
use #movePages(int, PDFDoc, PDFDoc, int, int, InsertBookmarkMode, ProgressMonitor) instead. Moves a range of pages from specified PDFDoc. Pages are deleted from source document after move.

Note: MovePages function does not save sourceDoc. It merely delete pages in memory. For permanent changes, PDFDoc::Save should be used to save sourceDoc after function exists.

Parameters
moveBeforeThisPage the destination of the move. If less than or equal to 1, the pages are moved to the beginning of the document. If larger than the number of pages in the destination document, the pages are moved to the end of document.
sourceDoc source PDFDoc to move from
startPage start of the page number to move
endPage end of the page number to move
insertFlag specifies insert options
monitor A pointer to the progress interface. NULL if progress tracking is not required.

public Page pageCreate (Rect media_box)

Create page with given media box

Parameters
media_box the input media box
Returns
  • a new, empty page with given media box

public Page pageCreate ()

Create a new, empty page in the document. You can use PageWriter to fill the page with new content. Finally the page should be inserted at specific place within document page sequence using PageInsert/PagePushFront/PagePushBack methods.

Note: the new page still does not belong to document page sequence and should be subsequently placed at a specific location within the sequence.

Returns
  • A new, empty page.

public void pageInsert (PageIterator where, Page page)

Insert/Import a single page at a specific location in the page sequence.

Note: Invalidates all PageIterators pointing to the document.

Parameters
where - The location in the page sequence indicating where to insert the page. The page is inserted before the specified location.
page - A page to insert.

public void pagePushBack (Page page)

Adds a page to the end of a documents's page sequence.

Note: Invalidates all PageIterators pointing to the document.

Parameters
page - a page to append to the document

public void pagePushFront (Page page)

Adds a page to the beginning of a documents's page sequence.

Parameters
page - a page to prepend to the document Invalidates all PageIterators pointing to the document.

public void pageRemove (PageIterator page_itr)

Remove specified page

Parameters
page_itr - the PageIterator to the page that should be removed A PageIterator for the given page can be obtained using PDFDoc::Find(page_num) or using direct iteration through document's page sequence.

public void refreshAnnotAppearances (RefreshOptions opts)

Generates the appearance stream for annotations in the document using the specified options. A common use case is to generate appearances only for missing annotations, which can be accomplished using the default options.

public void refreshAnnotAppearances ()

Generates the appearance stream for annotations in the document using the default options. A common use case is to generate appearances only for missing annotations, which can be accomplished using the default options.

public void refreshFieldAppearances ()

Regenerates the appearance stream for every widget annotation in the document Call this method if you modified field's value and would like to update field's appearances.

public void removePageLabel (int page_num)

Removes the page label that is attached to the specified page, effectively merging the specified range with the previous page label sequence.

Parameters
page_num The page from which the page label is removed. Because PDFNet indexes pages starting from 1, page_num must be larger than 0.

public void removeSecurity ()

Removes all security for the document.

public void removeSignatureHandler (long signature_handler_id)

Removes a signature handler from the signature manager.

Parameters
signature_handler_id The unique id of the signature handler to remove.

public void save (Filter output_filter, long flags)

This method is deprecated.
use save(Filter, SDFDoc.SaveMode) instead. Saves the document to a CustomFilter.

Note: Save will modify the PDFDoc object's internal representation. As such, the user should acquire a write lock before calling save.

Parameters
output_filter A output_filter filter where the document should be saved to.
flags - A bit field composed of an OR of the following values:
Throws
PDFNetException
IOException Signals that an I/O exception has occurred.
PDFNetException

public void save (OutputStream stream, SaveMode[] saveModes, ProgressMonitor progress)

Saves the document to an OutputStream. See save(OutputStream, SDFDoc.SaveMode, ProgressMonitor)

Throws
IOException
PDFNetException

public byte[] save (SaveMode[] saveModes, ProgressMonitor progress)

Saves the document to a memory buffer. See save(SDFDoc.SaveMode, ProgressMonitor)

public void save (long flags)

This method is deprecated.
use save() instead. Saves the document incrementally to the same location as it was opened from. This function only works if the PDFDoc was opened using a FileDescriptorFilter.

Note: If the original pdf has a corrupt xref table (see HasRepairedXref or http://www.pdftron.com/kb_corrupt_xref), then this save can not be used.

Parameters
flags - [REMOVE] Must be e_incremental
Throws
PDFNetException
IOException Signals that an I/O exception has occurred.
PDFNetException

public byte[] save (SDFDoc.SaveMode saveMode, ProgressMonitor progress)

Saves the document to a memory buffer.

Note: - Save will modify the PDFDoc object's internal representation. As such, the user should acquire a write lock before calling save.

Parameters
saveMode - save mode (See SDFDoc.SaveMode).
progress - A pointer to the progress interface. NULL if progress tracking is not required.
Returns
  • buffer containing the serialized version of the document.

public byte[] save (long flags, ProgressMonitor progress)

This method is deprecated.
use save(SDFDoc.SaveMode, ProgressMonitor) instead. Saves the document to a memory buffer.

Note: - Save will modify the PDFDoc object's internal representation. As such, the user should acquire a write lock before calling save.

Parameters
flags - A bit field composed of an OR of the following values:
progress - A pointer to the progress interface. NULL if progress tracking is not required.
Returns
  • buffer containing the serialized version of the document.

public void save (OutputStream stream, SDFDoc.SaveMode saveMode, ProgressMonitor progress, int size)

Saves the document to an OutputStream. Note: - Save will modify the PDFDoc object's internal representation. As such, the user should acquire a write lock before calling save.

Parameters
stream An OutputStream where the document should be serialized.
saveMode - save mode (See SDFDoc.SaveMode).
progress - A pointer to the progress interface. NULL if progress tracking is not required.
size The expected size of the output stream.
Throws
PDFNetException
IOException Signals that an I/O exception has occurred.
PDFNetException

public void save (OutputStream stream, long flags, ProgressMonitor progress)

This method is deprecated.
use save(OutputStream, SDFDoc.SaveMode, ProgressMonitor) instead. Saves the document to an OutputStream.

Note: - Save will modify the PDFDoc object's internal representation. As such, the user should acquire a write lock before calling save.

Parameters
stream An OutputStream where the document should be serialized.
flags - A bit field composed of an OR of the following values:
progress - A pointer to the progress interface. NULL if progress tracking is not required.
Throws
PDFNetException
IOException Signals that an I/O exception has occurred.
PDFNetException

public void save (OutputStream stream, SDFDoc.SaveMode saveMode, ProgressMonitor progress)

Saves the document to an OutputStream.

Note: - Save will modify the PDFDoc object's internal representation. As such, the user should acquire a write lock before calling save.

Parameters
stream An OutputStream where the document should be serialized.
saveMode - save mode (See SDFDoc.SaveMode).
progress - A pointer to the progress interface. NULL if progress tracking is not required.
Throws
PDFNetException
IOException Signals that an I/O exception has occurred.
PDFNetException

public void save (OutputStream stream, long flags, ProgressMonitor progress, int size)

This method is deprecated.
use save(OutputStream, SDFDoc.SaveMode, ProgressMonitor, int) instead. Saves the document to an OutputStream. Note: - Save will modify the PDFDoc object's internal representation. As such, the user should acquire a write lock before calling save.

Parameters
stream An OutputStream where the document should be serialized.
flags - A bit field composed of an OR of the following values:
progress - A pointer to the progress interface. NULL if progress tracking is not required.
size The expected size of the output stream.
Throws
PDFNetException
IOException Signals that an I/O exception has occurred.
PDFNetException

public void save (String path, long flags, ProgressMonitor progress)

This method is deprecated.
use save(String, SDFDoc.SaveMode, ProgressMonitor) instead. Saves the document to a file. If a full save is requested to the original path, the file is saved to a file system-determined temporary file, the old file is deleted, and the temporary file is renamed to path. A full save with remove unused or linearization option may re-arrange object in the cross reference table. Therefore all pointers and references to document objects and resources should be re acquired in order to continue document editing. In order to use incremental save the specified path must match original path and e_incremental flag bit should be set.

Note: In a multi-threaded environment, the user is expected to acquire a write lock before attempting to save the document.

Note: - Save will modify the PDFDoc object's internal representation. As such, the user should acquire a write lock before calling save.

Note: - If the original pdf has a corrupt xref table (see HasRepairedXref or http://www.pdftron.com/kb_corrupt_xref), then it can not be saved using the e_incremental flag.

Parameters
path - The full path name to which the file is saved.
flags - A bit field composed of an OR of the following values:
progress - A pointer to the progress interface. NULL if progress tracking is not required.

public void save (String path, SaveMode[] saveModes, ProgressMonitor progress)

Saves the document to a file. See save(String, SDFDoc.SaveMode, ProgressMonitor)

public void save (String path, SDFDoc.SaveMode saveMode, ProgressMonitor progress)

Saves the document to a file. If a full save is requested to the original path, the file is saved to a file system-determined temporary file, the old file is deleted, and the temporary file is renamed to path. A full save with remove unused or linearization option may re-arrange object in the cross reference table. Therefore all pointers and references to document objects and resources should be re acquired in order to continue document editing. In order to use incremental save the specified path must match original path and INCREMENTAL should be given.

Note: In a multi-threaded environment, the user is expected to acquire a write lock before attempting to save the document.

Note: - Save will modify the PDFDoc object's internal representation. As such, the user should acquire a write lock before calling save.

Note: - If the original pdf has a corrupt xref table (see HasRepairedXref or http://www.pdftron.com/kb_corrupt_xref), then it can not be saved using the INCREMENTAL mode.

Parameters
path - The full path name to which the file is saved.
saveMode - save mode (See SDFDoc.SaveMode).
progress - A pointer to the progress interface. NULL if progress tracking is not required.

public void save (Filter output_filter, SDFDoc.SaveMode saveMode)

Saves the document to a CustomFilter.

Note: Save will modify the PDFDoc object's internal representation. As such, the user should acquire a write lock before calling save.

Parameters
output_filter A output_filter filter where the document should be saved to.
saveMode - save mode (See SDFDoc.SaveMode).
Throws
PDFNetException
IOException Signals that an I/O exception has occurred.
PDFNetException

public void save (OutputStream stream, SaveMode[] saveModes, ProgressMonitor progress, int size)

Saves the document to an OutputStream. See save(OutputStream, SDFDoc.SaveMode, ProgressMonitor, int)

Throws
IOException
PDFNetException

public void save ()

Saves the document incrementally to the same location as it was opened from.

Note: If the original pdf has a corrupt xref table (see HasRepairedXref or http://www.pdftron.com/kb_corrupt_xref), then this save can not be used.

Throws
PDFNetException
IOException Signals that an I/O exception has occurred.
PDFNetException

public void save (Filter output_filter, SaveMode[] saveModes)

Saves the document to a file. See save(Filter, SDFDoc.SaveMode)

Throws
IOException
PDFNetException

public void saveCustomSignature (byte[] in_signature, DigitalSignatureField in_field, Filter output_filter)

Saves a custom signature Contents to a document which has been prepared to receive it. No changes should be made to document in meantime. The output goes into a Filter.

Note: This method ignores e_incremental flag. Save will modify the PDFDoc object's internal representation. As such, the user should acquire a write lock before calling save.

Parameters
in_signature The signature Contents to write
in_field The signature field to which to write
output_filter The output filter where to write data
Throws
PDFNetException
IOException Signals that an I/O exception has occurred.
PDFNetException

public void saveCustomSignature (byte[] in_signature, DigitalSignatureField in_field, String in_path)

Saves a custom signature Contents to a document which has been prepared to receive it. No changes should be made to document in meantime. The output goes into a file at the provided path.

Parameters
in_signature The signature Contents to write
in_field The signature field to which to write
in_path The full path name to which the file is saved.
Throws
PDFNetException
IOException Signals that an I/O exception has occurred.
PDFNetException

public boolean saveIncrementalData (String path)

Saves only the incremental portion of the PDFDoc to path Works like saving using INCREMENTAL but only writes the portion that would have been appended to path.

Parameters
path - The full path name to which the incremental data is saved.
Throws
PDFNetException
IOException Signals that an I/O exception has occurred.
PDFNetException

public void saveViewerOptimized (String path, ViewerOptimizedOptions opts)

Applies optimizations to improve viewing speed and saves the document to the specified file. The main optimizations used are linearization and embedding thumbnails for the first page and any complex pages.

Parameters
path The full path name to which the file is saved.
opts The optimization options
Throws
PDFNetException - if the file can't be opened for saving or if there is a problem during Save an Exception object will be thrown.

public byte[] saveViewerOptimized (ViewerOptimizedOptions opts)

Applies optimizations to improve viewing speed and saves the document to a memory buffer. The main optimizations used are linearization and embedding thumbnails for the first page and any other pages that are slow to render.

Parameters
opts The optimization options
Returns
  • The buffer containing the serialized version of the document.
Throws
PDFNetException if the file can't be opened for saving or if there is a problem during Save an Exception object will be thrown.

public void setOpenAction (Action action)

Set the Action that will be triggered when the document is opened.

Parameters
action A new Action that will be triggered when the document is opened. An example of such action is a GoTo Action that takes the user to a given location in the document.

public void setPageLabel (int page_num, PageLabel label)

Attaches a label to a page. This establishes the numbering scheme for that page and all following it, until another page label is encountered. This label allows PDF producers to define a page numbering system other than the default.

Parameters
page_num The number of the page to label. If page_num is less than 1 or greater than the number of pages in the document, the method does nothing.
label page label input PageLabel

public void setSecurityHandler (SecurityHandler handler)

The function sets a new SecurityHandler as the current security handler.

Note: Setting a new security handler will not invalidate the access to the original file and will take effect during document Save().

Note: If the security handler is modified, document will perform a full save even if INCREMENTAL was given in Save() method.

Parameters
handler the new security handler

public boolean timedLock (int milliseconds)

Try locking the document, waiting no longer than specified number of milliseconds.

Parameters
milliseconds maximum time to wait
Returns
  • true if the document is locked for multi-threaded access, false otherwise.

public boolean timedLockRead (int milliseconds)

Tries to obtain a read lock the document for milliseconds duration, and returns true if the lock was successfully acquired

Parameters
milliseconds maximum time to wait
Returns
  • true if the document is locked for multi-threaded access, false otherwise.

public boolean tryLock ()

Try locking the document in non-blocking manner.

Returns
  • true if the document is locked for multi-threaded access, false otherwise.

public boolean tryLockRead ()

Try obtaining a read lock on the document in non-blocking manner.

Returns
  • true if the document is locked for multi-threaded access, false otherwise.

public void unlock ()

Unlock the document.

public void unlockRead ()

Removes the read lock from the document.

public PDFDoc.SignaturesVerificationStatus verifySignedDigitalSignatures (VerificationOptions in_opts)

Attempts to verify all signed cryptographic digital signatures in the document, ignoring unsigned signatures.

Returns
  • an enumeration value representing the state of the document's signatures