PTPDFDoc

@interface PTPDFDoc : NSObject

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.PageFind(page_num).
  • To access form fields use pdfdoc.GetFieldIterator() or pdfdoc.FieldFind(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.

  • Default constructor. Creates an empty new document.

    Declaration

    Objective-C

    - (instancetype)init;

    Swift

    init!()
  • Undocumented

    Declaration

    Objective-C

    - (instancetype)initWithSdfdoc: (PTSDFDoc*)sdfdoc;

    Swift

    init!(sdfdoc: PTSDFDoc!)
  • Undocumented

    Declaration

    Objective-C

    - (instancetype)initWithFilepath: (NSString*)filepath;

    Swift

    init!(filepath: String!)
  • Undocumented

    Declaration

    Objective-C

    - (instancetype)initWithStream: (PTFilter*)stream;

    Swift

    init!(stream: PTFilter!)
  • Undocumented

    Declaration

    Objective-C

    - (instancetype)initWithBuf: (NSData*)buf buf_size:  (unsigned long)buf_size;

    Swift

    init!(buf: Data!, buf_size: UInt)
  • Close PDFDoc

    Declaration

    Objective-C

    - (void)Close;

    Swift

    func close()
  • Declaration

    Objective-C

    - (BOOL)IsEncrypted;

    Swift

    func isEncrypted() -> Bool

    Return Value

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

  • 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.

    @exception An exception is thrown if the matching handler for document’s security was not found in the global SecurityManager. In this case, you need to register additional custom security handlers with the global SecurityManager (using SecurityManagerSingleton).

    Declaration

    Objective-C

    - (BOOL)InitSecurityHandler;

    Swift

    func initSecurityHandler() -> Bool

    Parameters

    custom_data

    An optional parameter used to specify custom data that should be passed in SecurityHandler::Initialize() callback.

    Return Value

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

  • 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.

    @exception An exception is thrown if the document’s security Filter is not ‘Standard’. In this case, you need to register additional custom security handlers with the global SecurityManager (SecurityManagerSingleton).

    @remark Deprecated. Use versions that accepts UString or buffer instead.

    Declaration

    Objective-C

    - (BOOL)InitStdSecurityHandlerWithPassword:(NSString *)password
                                   password_sz:(int)password_sz;

    Swift

    func initStdSecurityHandler(withPassword password: String!, password_sz: Int32) -> Bool

    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.

    password_sz

    An optional parameter used to specify the size of the password buffer, in bytes. If the ‘password_sz’ is 0, or if the parameter is not specified, the function assumes that the string is null terminated.

    Return Value

    true if the given password successfully unlocked the document, false otherwise.

  • 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.

    @exception An exception is thrown if the document’s security Filter is not ‘Standard’. In this case, you need to register additional custom security handlers with the global SecurityManager (SecurityManagerSingleton).

    Declaration

    Objective-C

    - (BOOL)InitStdSecurityHandler:(NSString *)password;

    Swift

    func initStdSecurityHandler(_ password: String!) -> Bool

    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.

    Return Value

    true if the given password successfully unlocked the document, false otherwise.

  • 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 e_incremental was given as a flag in Save() method.

    Declaration

    Objective-C

    - (PTSecurityHandler *)GetSecurityHandler;

    Swift

    func getSecurityHandler() -> PTSecurityHandler!

    Return Value

    Currently selected SecurityHandler.

  • 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 e_incremental was given as a flag in Save() method.

    Declaration

    Objective-C

    - (void)SetSecurityHandler:(PTSecurityHandler *)handler;

    Swift

    func setSecurityHandler(_ handler: PTSecurityHandler!)

    Parameters

    handler

    new SecurityHandler

  • This function removes document security.

    Declaration

    Objective-C

    - (void)RemoveSecurity;

    Swift

    func removeSecurity()
  • Indicates whether this documents contains any digital signatures.

    Declaration

    Objective-C

    - (BOOL)HasSignatures;

    Swift

    func hasSignatures() -> Bool

    Return Value

    True if a digital signature is found in this PDFDoc.

  • Adds a signature handler to the signature manager.

    Declaration

    Objective-C

    - (PTSignatureHandlerId)AddSignatureHandler:
        (PTSignatureHandler *)signature_handler;

    Swift

    func add(_ signature_handler: PTSignatureHandler!) -> PTSignatureHandlerId

    Parameters

    signature_handler

    The signature handler instance to add to the signature manager.

    Return Value

    A unique ID representing the SignatureHandler within the SignatureManager.

  • 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.

    Declaration

    Objective-C

    - (unsigned long)AddStdSignatureHandlerFromFile:(NSString *)pkcs12_keyfile
                                     pkcs12_keypass:(NSString *)pkcs12_keypass;

    Swift

    func addStdSignatureHandler(fromFile pkcs12_keyfile: String!, pkcs12_keypass: String!) -> UInt

    Parameters

    pkcs12_file

    The private key certificate store to use.

    pkcs12_pass

    The passphrase for the provided private key.

    Return Value

    A unique ID representing the SignatureHandler within the SignatureManager.

  • 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.

    Declaration

    Objective-C

    - (unsigned long)AddStdSignatureHandlerFromBuffer:(NSData *)pkcs12_keybuffer
                                       pkcs12_keypass:(NSString *)pkcs12_keypass;

    Swift

    func addStdSignatureHandler(fromBuffer pkcs12_keybuffer: Data!, pkcs12_keypass: String!) -> UInt

    Parameters

    pkcs12_keybuffer

    The private key certificate store to use (as a data buffer in an array of bytes).

    pkcs12_pass

    The passphrase for the provided private key.

    Return Value

    A unique ID representing the SignatureHandler within the SignatureManager.

  • Removes a signature handler from the signature manager.

    Declaration

    Objective-C

    - (void)RemoveSignatureHandler:(PTSignatureHandlerId)signature_handler_id;

    Swift

    func removeSignatureHandler(_ signature_handler_id: PTSignatureHandlerId)

    Parameters

    signature_handler_id

    The unique id of the signature handler to remove.

  • Gets the associated signature handler instance from the signature manager by looking it up with the handler name.

    Declaration

    Objective-C

    - (PTSignatureHandler *)GetSignatureHandler:
        (PTSignatureHandlerId)signature_handler_id;

    Swift

    func getSignatureHandler(_ signature_handler_id: PTSignatureHandlerId) -> PTSignatureHandler!

    Parameters

    signature_handler_id

    The unique id of the signature handler to get.

    Return Value

    The signature handler instance if found, otherwise NULL.

  • Declaration

    Objective-C

    - (PTPDFDocInfo *)GetDocInfo;

    Swift

    func getInfo() -> PTPDFDocInfo!

    Return Value

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

  • 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.

    Declaration

    Objective-C

    - (PTPDFDocViewPrefs *)GetViewPrefs;

    Swift

    func getViewPrefs() -> PTPDFDocViewPrefs!

    Return Value

    Viewer preferences for this document.

  • Get the Action associated with the selected Doc Trigger event.

    Declaration

    Objective-C

    - (PTObj *)GetTriggerAction:(PTPDFDocActionTriggerEvent)trigger;

    Swift

    func getTriggerAction(_ trigger: PTPDFDocActionTriggerEvent) -> PTObj!

    Parameters

    trigger

    the type of trigger event to get

    Return Value

    the Action Obj if present, otherwise NULL

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

    Declaration

    Objective-C

    - (BOOL)IsModified;

    Swift

    func isModified() -> Bool

    Return Value

    - true if document was modified, false otherwise

  • 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)

    Declaration

    Objective-C

    - (BOOL)HasRepairedXRef;

    Swift

    func hasRepairedXRef() -> Bool

    Return Value

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

  • 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 ‘Doc.SaveOptions.e_linearized’ flag in the Save method.

    Declaration

    Objective-C

    - (BOOL)IsLinearized;

    Swift

    func isLinearized() -> Bool

    Return Value

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

  • 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.

    @exception - if the file can’t be opened for saving or if there is a problem during Save an Exception object will be thrown.

    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.

    Declaration

    Objective-C

    - (void)SaveToFile:(NSString *)path flags:(unsigned int)flags;

    Swift

    func save(toFile path: String!, flags: UInt32)

    Parameters

    path

    - The full path name to which the file is saved.

    flags

    - A bit field composed of an OR of SDFDoc::SaveOptions values.

    progress

    - A pointer to the progress interface. NULL if progress tracking is not required.

  • Saves the document to a memory buffer.

    @exception - if there is a problem during Save an Exception object will be thrown.

    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.

    Declaration

    Objective-C

    - (NSData *)SaveToBuf:(unsigned int)flags;

    Swift

    func save(toBuf flags: UInt32) -> Data!

    Parameters

    out_buf

    a pointer to the buffer containing the serialized version of the document. (C++ Note) The buffer is owned by a document and the client doesn’t need to do any initialization or cleanup.

    out_buf_size

    the size of the serialized document (i.e. out_buf) in bytes.

    flags

    - A bit field composed of an OR of SDFDoc::SaveOptions values. Note that this method ignores e_incremental flag.

    progress

    - A pointer to the progress interface. NULL if progress tracking is not required.

  • Saves the document to a stream.

    @exception - if there is a problem during Save an Exception object will be thrown.

    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.

    Declaration

    Objective-C

    - (void)Save:(PTFilter *)stream flags:(unsigned int)flags;

    Swift

    func save(_ stream: PTFilter!, flags: UInt32)

    Parameters

    stream

    The output stream where to write data.

    flags

    - A bit field composed of an OR of the SDFDoc::SaveOptions values.

    progress

    - A pointer to the progress interface. NULL if progress tracking is not required.

    header

    - File header. A new file header is set only during full save. See also GetHeader()

  • Use the Next() method on the returned iterator to traverse all pages in the document. For example:

       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.

    Declaration

    Objective-C

    - (PTPageIterator *)GetPageIterator:(unsigned int)page_number;

    Swift

    func getPageIterator(_ page_number: UInt32) -> PTPageIterator!

    Parameters

    page_number

    page to set the iterator on. 1 corresponds to the first page.

    Return Value

    an iterator to the first page in the document.

  • For example:

       Page page = pdfdoc.GetPage(page_num);
       if (page == null) return; //  Page not found
    

    Declaration

    Objective-C

    - (PTPage *)GetPage:(unsigned int)page_number;

    Swift

    func getPage(_ page_number: UInt32) -> PTPage!

    Parameters

    page_number

    - the page number in document’s page sequence. Page numbers in document’s page sequence are indexed from 1.

    Return Value

    a Page corresponding to a given page number, or null (invalid page) if the document does not contain the given page number.

  • Declaration

    Objective-C

    - (void)PageRemove:(PTPageIterator *)page_itr;

    Swift

    func pageRemove(_ page_itr: PTPageIterator!)

    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.

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

    Note

    Invalidates all PageIterators pointing to the document.

    Declaration

    Objective-C

    - (void)PageInsert:(PTPageIterator *)where page:(PTPage *)page;

    Swift

    func pageInsert(_ where: PTPageIterator!, page: PTPage!)

    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.

  • Inserts a range of pages from specified PDFDoc

    Declaration

    Objective-C

    - (void)InsertPages:(int)insert_before_page_number
                src_doc:(PTPDFDoc *)src_doc
             start_page:(int)start_page
               end_page:(int)end_page
                   flag:(PTInsertFlag)flag;

    Swift

    func insertPages(_ insert_before_page_number: Int32, src_doc: PTPDFDoc!, start_page: Int32, end_page: Int32, flag: PTInsertFlag)

    Parameters

    insert_before_page_number

    - 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.

    src_doc

    - source PDFDoc to insert from

    start_page

    - start of the page number to insert

    end_page

    - end of the page number to insert

    flag

    - specifies insert options

    progress

    - A pointer to the progress interface. NULL if progress tracking is not required.

  • Inserts a range of pages from specified PDFDoc using PageSet

    Declaration

    Objective-C

    - (void)InsertPagesWithPageSet:(int)insert_before_page_number
                           src_doc:(PTPDFDoc *)src_doc
                   source_page_set:(PTPageSet *)source_page_set
                              flag:(PTInsertFlag)flag;

    Swift

    func insertPages(withPageSet insert_before_page_number: Int32, src_doc: PTPDFDoc!, source_page_set: PTPageSet!, flag: PTInsertFlag)

    Parameters

    insert_before_page_number

    - 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.

    src_doc

    - source PDFDoc to insert from

    source_page_set

    - a collection of the page number to insert

    flag

    - specifies insert options

    progress

    - A pointer to the progress interface. NULL if progress tracking is not required.

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

    Note

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

    Declaration

    Objective-C

    - (void)MovePages:(int)move_before_page_number
              src_doc:(PTPDFDoc *)src_doc
           start_page:(int)start_page
             end_page:(int)end_page
                 flag:(PTInsertFlag)flag;

    Swift

    func movePages(_ move_before_page_number: Int32, src_doc: PTPDFDoc!, start_page: Int32, end_page: Int32, flag: PTInsertFlag)

    Parameters

    move_before_page_number

    - 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 the document.

    src_doc

    - source PDFDoc to move from

    start_page

    - start of the page number to move

    end_page

    - end of the page number to move

    flag

    - specifies insert options

    progress

    - A pointer to the progress interface. NULL if progress tracking is not required.

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

    Note

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

    Declaration

    Objective-C

    - (void)MovePagesWithPageSet:(int)move_before_page_number
                         src_doc:(PTPDFDoc *)src_doc
                 source_page_set:(PTPageSet *)source_page_set
                            flag:(PTInsertFlag)flag;

    Swift

    func movePages(withPageSet move_before_page_number: Int32, src_doc: PTPDFDoc!, source_page_set: PTPageSet!, flag: PTInsertFlag)

    Parameters

    move_before_page_number

    - 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 the document.

    src_doc

    - source PDFDoc to move from

    source_page_set

    - a collection of the page number to move

    flag

    - specifies insert options

    progress

    - A pointer to the progress interface. NULL if progress tracking is not required.

  • Adds a page to the beginning of a document’s page sequence.

    Declaration

    Objective-C

    - (void)PagePushFront:(PTPage *)page;

    Swift

    func pagePushFront(_ page: PTPage!)

    Parameters

    page

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

  • Adds a page to the end of a document’s page sequence.

    Note

    Invalidates all PageIterators pointing to the document.

    Declaration

    Objective-C

    - (void)PagePushBack:(PTPage *)page;

    Swift

    func pagePushBack(_ page: PTPage!)

    Parameters

    page

    - a page to append to the document

  • The function imports a list of pages to this document. 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.

    Declaration

    Objective-C

    - (PTVectorPage *)ImportPages:(PTVectorPage *)pages
                 import_bookmarks:(BOOL)import_bookmarks;

    Swift

    func importPages(_ pages: PTVectorPage!, import_bookmarks: Bool) -> PTVectorPage!

    Parameters

    pages

    A list of pages to import. All pages should belong to the same source document.

    import_bookmarks

    An optional flag specifying whether any bookmark items pointing to pages in the import list should be merged with the target (i.e. this) document.

    Return Value

    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.

  • 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.

    The following is a listing of some standard U.S. page sizes:

    • Letter = Rect(0, 0, 612, 792)
    • Legal = Rect(0, 0, 612, 1008)
    • Ledger = Rect(0, 0, 1224, 792)
    • Tabloid = Rect(0, 0, 792, 1224)
    • Executive = Rect(0, 0, 522, 756)

    The following is a listing of ISO standard page sizes:

    • 4A0 = Rect(0, 0, 4768, 6741)
    • 2A0 = Rect(0, 0, 3370, 4768)
    • A0 = Rect(0, 0, 2384, 3370)
    • A1 = Rect(0, 0, 1684, 2384)
    • A2 = Rect(0, 0, 1191, 1684)
    • A3 = Rect(0, 0, 842, 1191)
    • A4 = Rect(0, 0, 595, 842)
    • A5 = Rect(0, 0, 420, 595)
    • A6 = Rect(0, 0, 298, 420)
    • A7 = Rect(0, 0, 210, 298)
    • A8 = Rect(0, 0, 147, 210)
    • A9 = Rect(0, 0, 105, 147)
    • A10 = Rect(0, 0, 74, 105)
    • B0 = Rect(0, 0, 2835, 4008)
    • B1 = Rect(0, 0, 2004, 2835)
    • B2 = Rect(0, 0, 1417, 2004)
    • B3 = Rect(0, 0, 1001, 1417)
    • B4 = Rect(0, 0, 709, 1001)
    • B5 = Rect(0, 0, 499, 709)
    • B6 = Rect(0, 0, 354, 499)
    • B7 = Rect(0, 0, 249, 354)
    • B8 = Rect(0, 0, 176, 249)
    • B9 = Rect(0, 0, 125, 176)
    • B10 = Rect(0, 0, 88, 125)
    • C0 = Rect(0, 0, 2599, 3677)
    • C1 = Rect(0, 0, 1837, 2599)
    • C2 = Rect(0, 0, 1298, 1837)
    • C3 = Rect(0, 0, 918, 1298)
    • C4 = Rect(0, 0, 649, 918)
    • C5 = Rect(0, 0, 459, 649)
    • C6 = Rect(0, 0, 323, 459)
    • C7 = Rect(0, 0, 230, 323)
    • C8 = Rect(0, 0, 162, 230)
    • C9 = Rect(0, 0, 113, 162)
    • C10 = Rect(0, 0, 79, 113)

    Declaration

    Objective-C

    - (PTPage *)PageCreate:(PTPDFRect *)media_box;

    Swift

    func pageCreate(_ media_box: PTPDFRect!) -> PTPage!

    Parameters

    media_box

    A rectangle, expressed in default user space units, defining the boundaries of the physical medium on which the page is intended to be displayed or printed. A user space units is 1/72 of an inch. If media_box is not specified the default dimensions of the page are 8.5 x 11 inches (or 8.5*72, 11*72 units).

    Return Value

    A new, empty page.

  • Declaration

    Objective-C

    - (PTBookmark *)GetFirstBookmark;

    Swift

    func getFirstBookmark() -> PTBookmark!

    Return Value

    - 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).

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

    Note

    parameter ‘root_bookmark’ must not be linked (must not be belong) to a bookmark tree.

    Declaration

    Objective-C

    - (void)AddRootBookmark:(PTBookmark *)root_bookmark;

    Swift

    func addRootBookmark(_ root_bookmark: PTBookmark!)

    Parameters

    root_bookmark

    Bookmark to Add/link

  • Declaration

    Objective-C

    - (PTObj *)GetTrailer;

    Swift

    func getTrailer() -> PTObj!

    Return Value

    - A dictionary representing the Cos root of the document (document’s trailer)

  • Declaration

    Objective-C

    - (PTObj *)GetRoot;

    Swift

    func getRoot() -> PTObj!

    Return Value

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

  • Declaration

    Objective-C

    - (PTObj *)GetPages;

    Swift

    func getPages() -> PTObj!

    Return Value

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

  • Declaration

    Objective-C

    - (int)GetPageCount;

    Swift

    func getPageCount() -> Int32

    Return Value

    the number of pages in the document.

  • 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).

    The list of all Fields present in the document can be traversed as follows:

     FieldIterator itr = pdfdoc.GetFieldIterator();
     for(; itr.HasNext(); itr.Next()) {
       Field field = itr.Current();
       Console.WriteLine("Field name: {0}", field.GetName());
      }
    

    For a full sample, please refer to ‘InteractiveForms’ sample project.

    Declaration

    Objective-C

    - (PTFieldIterator *)GetFieldIterator;

    Swift

    func getFieldIterator() -> PTFieldIterator!

    Return Value

    an iterator to the first Field in the document.

  •  FieldIterator itr = pdfdoc.FieldFind("name");
     if (itr.HasNext()) {
       Console.WriteLine("Field name: {0}", itr.Current().GetName());
     }
     else { ...field was not found... }
    

    Declaration

    Objective-C

    - (PTFieldIterator *)GetFieldIteratorWithName:(NSString *)field_name;

    Swift

    func getFieldIterator(withName field_name: String!) -> PTFieldIterator!

    Parameters

    field_name

    - a string representing the fully qualified name of the field (e.g. employee.name.first).

    Return Value

    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:

  • Undocumented

    Declaration

    Objective-C

    - (PTField*)GetField: (NSString*)field_name;

    Swift

    func getField(_ field_name: String!) -> PTField!
  • Create a new interactive form Field.

    @exception if ‘field_name’ is equal to an existing non-terminal field name an exception is thrown.

    Declaration

    Objective-C

    - (PTField *)FieldCreateWithObj:(NSString *)field_name
                               type:(PTFieldType)type
                        field_value:(PTObj *)field_value
                    def_field_value:(PTObj *)def_field_value;

    Swift

    func fieldCreate(withObj field_name: String!, type: PTFieldType, field_value: PTObj!, def_field_value: PTObj!) -> PTField!

    Parameters

    field_name

    a string representing the fully qualified 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.)

    Return Value

    the new form Field.

  • Undocumented

    Declaration

    Objective-C

    - (PTField*)FieldCreate: (NSString*)field_name type:  (PTFieldType)type field_value:  (PTObj*)field_value;

    Swift

    func fieldCreate(_ field_name: String!, type: PTFieldType, field_value: PTObj!) -> PTField!
  • Undocumented

    Declaration

    Objective-C

    - (PTField*)FieldCreateWithString: (NSString*)field_name type:  (PTFieldType)type field_value:  (NSString*)field_value def_field_value:  (NSString*)def_field_value;

    Swift

    func fieldCreate(with field_name: String!, type: PTFieldType, field_value: String!, def_field_value: String!) -> PTField!
  • 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.

    Declaration

    Objective-C

    - (void)RefreshFieldAppearances;

    Swift

    func refreshFieldAppearances()
  • Flatten all annotations in the document.

    Declaration

    Objective-C

    - (void)FlattenAnnotations:(BOOL)forms_only;

    Swift

    func flattenAnnotations(_ forms_only: Bool)

    Parameters

    forms_only

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

  • Declaration

    Objective-C

    - (PTObj *)GetAcroForm;

    Swift

    func getAcroForm() -> PTObj!

    Return Value

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

  • Extract form data and/or annotations to FDF

    Declaration

    Objective-C

    - (PTFDFDoc *)FDFExtract:(PTExtractFlag)flag;

    Swift

    func fdfExtract(_ flag: PTExtractFlag) -> PTFDFDoc!

    Parameters

    flag

    - specifies extract options

    Return Value

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

  • Extract form data and/or annotations to FDF

    Declaration

    Objective-C

    - (PTFDFDoc *)FDFExtractAnnots:(PTVectorAnnot *)annotations;

    Swift

    func fdfExtractAnnots(_ annotations: PTVectorAnnot!) -> PTFDFDoc!

    Parameters

    pages_to_extract

    The set of pages for which to extract interactive data.

    flag

    specifies extract options

    Return Value

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

  • Extract annotations to FDF

    Declaration

    Objective-C

    - (PTFDFDoc *)FDFExtractCommand:(PTVectorAnnot *)annot_added
                     annot_modified:(PTVectorAnnot *)annot_modified
                      annot_deleted:(PTVectorAnnot *)annot_deleted;

    Swift

    func fdfExtractCommand(_ annot_added: PTVectorAnnot!, annot_modified: PTVectorAnnot!, annot_deleted: PTVectorAnnot!) -> PTFDFDoc!

    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

    Return Value

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

  • Import form data from FDF file to PDF interactive form.

    Declaration

    Objective-C

    - (void)FDFMerge:(PTFDFDoc *)fdf_doc;

    Swift

    func fdfMerge(_ fdf_doc: PTFDFDoc!)

    Parameters

    fdf_doc

    - a reference to the FDF file

  • Replace existing form and annotation data with those imported from the FDF file. Since this method avoids updating annotations unnecessarily it is ideal for incremental save.

    Declaration

    Objective-C

    - (void)FDFUpdate:(PTFDFDoc *)fdf_doc;

    Swift

    func fdfUpdate(_ fdf_doc: PTFDFDoc!)

    Parameters

    fdf_doc

    - a reference to the FDF file

  • Note

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

    Declaration

    Objective-C

    - (PTAction *)GetOpenAction;

    Swift

    func getOpenAction() -> PTAction!

    Return Value

    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).

  • Sets the Action that will be triggered when the document is opened.

    Declaration

    Objective-C

    - (void)SetOpenAction:(PTAction *)action;

    Swift

    func setOpen(_ action: PTAction!)

    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.

  • 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:

    SDF::NameTree names = SDF::NameTree::Create(doc, "EmbeddedFiles");
    names.Put(file_key, file_keysz, embedded_file.GetSDFObj());
    

    Declaration

    Objective-C

    - (void)AddFileAttachment:(NSString *)file_key
                embedded_file:(PTFileSpec *)embedded_file;

    Swift

    func addFileAttachment(_ file_key: String!, embedded_file: PTFileSpec!)

    Parameters

    file_key

    A key/name under which the attachment will be stored.

    embedded_file

    Embedded file stream

  • Declaration

    Objective-C

    - (PTPageLabel *)GetPageLabel:(int)page_num;

    Swift

    func getPageLabel(_ page_num: Int32) -> PTPageLabel!

    Parameters

    page_num

    The page number. Because PDFNet indexes pages starting from 1, page_num must be larger than 0.

    Return Value

    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.

  • 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.

    Declaration

    Objective-C

    - (void)SetPageLabel:(int)page_num label:(PTPageLabel *)label;

    Swift

    func setPageLabel(_ page_num: Int32, label: PTPageLabel!)

    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.

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

    Declaration

    Objective-C

    - (void)RemovePageLabel:(int)page_num;

    Swift

    func removePageLabel(_ page_num: Int32)

    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.

  • Declaration

    Objective-C

    - (BOOL)IsTagged;

    Swift

    func isTagged() -> Bool

    Return Value

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

  • Declaration

    Objective-C

    - (PTSTree *)GetStructTree;

    Swift

    func getStructTree() -> PTSTree!

    Return Value

    The document’s logical structure tree root.

  • Declaration

    Objective-C

    - (BOOL)HasOC;

    Swift

    func hasOC() -> Bool

    Return Value

    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.

  • Declaration

    Objective-C

    - (PTObj *)GetOCGs;

    Swift

    func getOCGs() -> PTObj!

    Return Value

    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.

  • Declaration

    Objective-C

    - (PTConfig *)GetOCGConfig;

    Swift

    func getOCGConfig() -> PTConfig!

    Return Value

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

  • 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.

    @exception An exception will be thrown if the XML file is malformed or os out of sync with the document.

    Declaration

    Objective-C

    - (void)AddHighlights:(NSString *)hilite;

    Swift

    func addHighlights(_ hilite: String!)

    Parameters

    hilite

    a string representing the filename for the highlight file or or a data buffer containing XML data.

  • This method creates an SDF/Cos indirect name object

    Unlike direct objects, indirect objects can be referenced by more than one object (i.e. indirect objects can be shared).

    Declaration

    Objective-C

    - (PTObj *)CreateIndirectName:(NSString *)name;

    Swift

    func createIndirectName(_ name: String!) -> PTObj!
  • This method creates an SDF/Cos indirect array object

    Unlike direct objects, indirect objects can be referenced by more than one object (i.e. indirect objects can be shared).

    Declaration

    Objective-C

    - (PTObj *)CreateIndirectArray;

    Swift

    func createIndirectArray() -> PTObj!

    Return Value

    Returns a new indirect array object.

  • This method creates an SDF/Cos indirect boolean object

    Unlike direct objects, indirect objects can be referenced by more than one object (i.e. indirect objects can be shared).

    Declaration

    Objective-C

    - (PTObj *)CreateIndirectBool:(BOOL)value;

    Swift

    func createIndirectBool(_ value: Bool) -> PTObj!

    Parameters

    value

    the value with which to create the boolean object.

    Return Value

    Returns a new indirect boolean object.

  • This method creates an SDF/Cos indirect dict object

    Unlike direct objects, indirect objects can be referenced by more than one object (i.e. indirect objects can be shared).

    Declaration

    Objective-C

    - (PTObj *)CreateIndirectDict;

    Swift

    func createIndirectDict() -> PTObj!

    Return Value

    Returns a new indirect dict object.

  • This method creates an SDF/Cos indirect null object

    Unlike direct objects, indirect objects can be referenced by more than one object (i.e. indirect objects can be shared).

    Declaration

    Objective-C

    - (PTObj *)CreateIndirectNull;

    Swift

    func createIndirectNull() -> PTObj!

    Return Value

    Returns a new indirect null object.

  • This method creates an SDF/Cos indirect number object

    Unlike direct objects, indirect objects can be referenced by more than one object (i.e. indirect objects can be shared).

    Declaration

    Objective-C

    - (PTObj *)CreateIndirectNumber:(double)value;

    Swift

    func createIndirectNumber(_ value: Double) -> PTObj!

    Parameters

    value

    the value with which to create the number object.

    Return Value

    Returns a new indirect number object.

  • This method creates an SDF/Cos indirect string object

    Unlike direct objects, indirect objects can be referenced by more than one object (i.e. indirect objects can be shared).

    Declaration

    Objective-C

    - (PTObj *)CreateIndirectString:(NSData *)value size:(unsigned int)size;

    Swift

    func createIndirectString(_ value: Data!, size: UInt32) -> PTObj!

    Parameters

    value

    Unsigned char pointer with which to create the string object.

    size

    length of string.

    Return Value

    Returns a new indirect string object.

  • This method creates an SDF/Cos indirect stream object

    Unlike direct objects, indirect objects can be referenced by more than one object (i.e. indirect objects can be shared).

    Declaration

    Objective-C

    - (PTObj *)CreateIndirectStream:(PTFilterReader *)data
                       filter_chain:(PTFilter *)filter_chain;

    Swift

    func createIndirectStream(_ data: PTFilterReader!, filter_chain: PTFilter!) -> PTObj!

    Parameters

    data

    reference to a FilterReader object with which to create the stream object.

    filter_chain

    filter object with which to create the stream object. Defaults to Filters::Filter(0,false)

    Return Value

    Returns a new indirect stream object.

  • Declaration

    Objective-C

    - (PTSDFDoc *)GetSDFDoc;

    Swift

    func getSDFDoc() -> PTSDFDoc!

    Return Value

    document’s SDF/Cos document

  • Locks the document to prevent competing threads from accessing 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().

    Declaration

    Objective-C

    - (void)Lock;

    Swift

    func lock()
  • Removes the lock from the document.

    Declaration

    Objective-C

    - (void)Unlock;

    Swift

    func unlock()
  • Try locking the document, waiting no longer than specified number of milliseconds.

    Declaration

    Objective-C

    - (BOOL)TryLock:(int)milliseconds;

    Swift

    func tryLock(_ milliseconds: Int32) -> Bool

    Parameters

    milliseconds

    - max number of milliseconds to wait for the document to lock

    Return Value

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

  • 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.

    Declaration

    Objective-C

    - (void)LockRead;

    Swift

    func lockRead()
  • Removes the read lock from the document.

    Declaration

    Objective-C

    - (void)UnlockRead;

    Swift

    func unlockRead()
  • Tries to obtain a read lock the document for duration, and returns true if the lock was successfully acquired

    Declaration

    Objective-C

    - (BOOL)TryLockRead:(int)milliseconds;

    Swift

    func tryLockRead(_ milliseconds: Int32) -> Bool

    Parameters

    milliseconds

    duration to obtain a read lock for.

    Return Value

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

  • Declaration

    Objective-C

    - (NSString *)GetFileName;

    Swift

    func getFileName() -> String!

    Return Value

    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.

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

    Declaration

    Objective-C

    - (void)GenerateThumbnails:(unsigned int)size;

    Swift

    func generateThumbnails(_ size: UInt32)

    Parameters

    size

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

  • Undocumented

    Declaration

    Objective-C

    + (PTPDFDoc*)CreateInternal: (unsigned long long)impl;

    Swift

    class func createInternal(_ impl: UInt64) -> PTPDFDoc!
  • Undocumented

    Declaration

    Objective-C

    - (unsigned long long)GetHandleInternal;

    Swift

    func getHandleInternal() -> UInt64