CPDFDocument Class Reference

Inherits from NSObject
Declared in CPDFDocument.h

Overview

An object that represents a PDF file and defines methods for writing, searching, and selecting PDF data.

The other utility classes are either instantiated from methods in CPDFDocument, as are CPDFPage and CPDFOutline; or support it, as do CPDFWatermark and CPDFDestination. You initialize a CPDFDocument object with a URL to a PDF file. You can then ask for the page count, add or delete pages, perform a find, or parse selected content into an NSString object.

Other Methods

– init

Initializes a CPDFDocument object with new PDF.

- (instancetype)init

Discussion

Initializes a CPDFDocument object with new PDF.

Declared In

CPDFDocument.h

– initWithURL:

Initializes a CPDFDocument object with the contents at the specified URL.

- (instancetype)initWithURL:(NSURL *)url

Discussion

Initializes a CPDFDocument object with the contents at the specified URL.

Declared In

CPDFDocument.h

  delegate

The object acting as the delegate for the CPDFDocument object.

@property (nonatomic, assign) id<CPDFDocumentDelegate> delegate

Discussion

The object acting as the delegate for the CPDFDocument object.

Declared In

CPDFDocument.h

  documentURL

The URL for the document.

@property (nonatomic, readonly) NSURL *documentURL

Discussion

The URL for the document.

May return NULL if the document was created from an new object.

Declared In

CPDFDocument.h

  password

The password for the document.

@property (nonatomic, readonly) NSString *password

Discussion

The password for the document.

May return NULL if the document is not an encrypted document.

Declared In

CPDFDocument.h

  error

Error message for the document loading.

@property (nonatomic, readonly) NSError *error

Discussion

Error message for the document loading.

To determine the error type, use the code to obtain error of type CPDFDocumentErrorDomain. Except for the CPDFDocumentPasswordError error, other errors cannot open the document. If CPDFDocumentPasswordError, reading the document requires a password.

Declared In

CPDFDocument.h

  isEncrypted

A Boolean value specifying whether the document is encrypted.

@property (nonatomic, readonly) BOOL isEncrypted

Discussion

A Boolean value specifying whether the document is encrypted.

Whether the PDF is encrypted. With the right password, a PDF can be unlocked - nonetheless, the PDF still indicates that it is encrypted - just no longer locked. Some PDF’s may be encrypted but can be unlocked with the empty string. These are unlocked automatically.

Declared In

CPDFDocument.h

  isLocked

A Boolean value indicating whether the document is locked.

@property (nonatomic, readonly) BOOL isLocked

Discussion

A Boolean value indicating whether the document is locked.

Only encrypted documents can be locked. Use the unlockWithPassword: method to unlock a document using a password.

Declared In

CPDFDocument.h

– unlockWithPassword:

Attempts to unlock an encrypted document.

- (BOOL)unlockWithPassword:(NSString *)password

Parameters

password

The password to unlock an encrypted document (you cannot lock an unlocked PDF document by using an incorrect password).

Discussion

Attempts to unlock an encrypted document.

If the password is correct, this method returns YES, and a CPDFDocumentDidUnlockNotification notification is sent. Once unlocked, you cannot use this function to relock the document.

Declared In

CPDFDocument.h

– checkOwnerPassword:

Whether the owner password is correct.

- (BOOL)checkOwnerPassword:(NSString *)password

Parameters

password

Owner password.

Return Value

Whether the password is correct.

Discussion

Whether the owner password is correct.

Declared In

CPDFDocument.h

– isCheckOwnerUnlocked

Whether the secured PDF document is unlocked.

- (BOOL)isCheckOwnerUnlocked

Return Value

Return the result of whether the secured PDF document is unlocked.

Discussion

Whether the secured PDF document is unlocked.

Declared In

CPDFDocument.h

  majorVersion

The major version of the document.

@property (nonatomic, readonly) NSInteger majorVersion

Discussion

The major version of the document.

PDF version of the PDF file (example: major version = 1; PDF v1.4).

Declared In

CPDFDocument.h

  minorVersion

The minor version of the document.

@property (nonatomic, readonly) NSInteger minorVersion

Discussion

The minor version of the document.

PDF version of the PDF file (example: minor version = 4; PDF v1.4).

Declared In

CPDFDocument.h

  permissionsStatus

The permissions status of the PDF document.

@property (nonatomic, readonly) CPDFDocumentPermissions permissionsStatus

Discussion

The permissions status of the PDF document.

Returns the permissions status of the PDF document. You have CPDFDocumentPermissionsNone status for an encrypted document that you have not supplied either a valid user or owner password. For a document with no encryption, you automatically have CPDFDocumentPermissionsUser status.

Declared In

CPDFDocument.h

  allowsPrinting

A Boolean value indicating whether the document allows printing.

@property (nonatomic, readonly) BOOL allowsPrinting

Discussion

A Boolean value indicating whether the document allows printing.

Declared In

CPDFDocument.h

  allowsHighQualityPrinting

A Boolean value indicating whether the document allows printing in high fidelity.

@property (nonatomic, readonly) BOOL allowsHighQualityPrinting

Discussion

A Boolean value indicating whether the document allows printing in high fidelity.

Declared In

CPDFDocument.h

  allowsCopying

A Boolean value indicating whether the document allows copying of content to the Pasteboard.

@property (nonatomic, readonly) BOOL allowsCopying

Discussion

A Boolean value indicating whether the document allows copying of content to the Pasteboard.

Declared In

CPDFDocument.h

  allowsDocumentChanges

A Boolean value indicating whether you can modify the document contents except for document attributes.

@property (nonatomic, readonly) BOOL allowsDocumentChanges

Discussion

A Boolean value indicating whether you can modify the document contents except for document attributes.

Declared In

CPDFDocument.h

  allowsDocumentAssembly

A Boolean value indicating whether you can manage a document by inserting, deleting, and rotating pages.

@property (nonatomic, readonly) BOOL allowsDocumentAssembly

Discussion

A Boolean value indicating whether you can manage a document by inserting, deleting, and rotating pages.

Declared In

CPDFDocument.h

  allowsCommenting

A Boolean value indicating whether you can create or modify document annotations, including form field entries.

@property (nonatomic, readonly) BOOL allowsCommenting

Discussion

A Boolean value indicating whether you can create or modify document annotations, including form field entries.

Declared In

CPDFDocument.h

  allowsFormFieldEntry

A Boolean value indicating whether you can modify form field entries even if you can’t edit document annotations.

@property (nonatomic, readonly) BOOL allowsFormFieldEntry

Discussion

A Boolean value indicating whether you can modify form field entries even if you can’t edit document annotations.

Declared In

CPDFDocument.h

  encryptionLevel

@property (nonatomic, readonly) CPDFDocumentEncryptionLevel encryptionLevel

– isModified

A Boolean value indicating whether the document has been modified.

- (BOOL)isModified

Discussion

A Boolean value indicating whether the document has been modified.

Declared In

CPDFDocument.h

– writeToURL:

Writes the document to a location specified by the passed-in URL.

- (BOOL)writeToURL:(NSURL *)url

Discussion

Writes the document to a location specified by the passed-in URL.

Declared In

CPDFDocument.h

– writeToURL:withOptions:

Writes the document to the specified URL with the specified options.

- (BOOL)writeToURL:(NSURL *)url withOptions:(NSDictionary<CPDFDocumentWriteOption,id> *)options

Parameters

options

CPDFDocumentOwnerPasswordOption, CPDFDocumentUserPasswordOption.

Discussion

Writes the document to the specified URL with the specified options.

Set the password to the document by setting options.

Declared In

CPDFDocument.h

– writeFlattenToURL:

Writes the document to the specified URL after flattening.

- (BOOL)writeFlattenToURL:(NSURL *)url

Discussion

Writes the document to the specified URL after flattening.

Declared In

CPDFDocument.h

– writeContentToURL:

Writes the document to the specified URL after removing annotions and form field entries.

- (BOOL)writeContentToURL:(NSURL *)url

Discussion

Writes the document to the specified URL after removing annotions and form field entries.

Declared In

CPDFDocument.h

– writeDecryptToURL:

Writes the document to the specified URL after removing permissions.

- (BOOL)writeDecryptToURL:(NSURL *)url

Discussion

Writes the document to the specified URL after removing permissions.

Declared In

CPDFDocument.h

– documentAttributes

A dictionary of document metadata.

- (NSDictionary<CPDFDocumentAttribute,id> *)documentAttributes

Discussion

A dictionary of document metadata.

Metadata is optional for PDF documents. The dictionary may be empty, or only some of the keys may have associated values.

Declared In

CPDFDocument.h

– setDocumentAttributes:

- (void)setDocumentAttributes:(NSDictionary<CPDFDocumentAttribute,id> *)documentAttributes

– outlineRoot

The document’s root outline to a PDF outline object.

- (CPDFOutline *)outlineRoot

Discussion

The document’s root outline to a PDF outline object.

When a PDF document is saved, the outline tree structure is written out to the destination PDF file.

Declared In

CPDFDocument.h

– setNewOutlineRoot

Create a root outline for the document.

- (CPDFOutline *)setNewOutlineRoot

Discussion

Create a root outline for the document.

Declared In

CPDFDocument.h

– bookmarks

A array of document’s bookmarks.

- (NSArray<CPDFBookmark*> *)bookmarks

Discussion

A array of document’s bookmarks.

Declared In

CPDFDocument.h

– addBookmark:forPageIndex:

Add a bookmark at the specified index number.

- (BOOL)addBookmark:(NSString *)label forPageIndex:(NSUInteger)pageIndex

Discussion

Add a bookmark at the specified index number.

Indexes are zero based. This method raises an exception if index is out of bounds.

Declared In

CPDFDocument.h

– removeBookmarkForPageIndex:

Remove the bookmark at the specified index number.

- (BOOL)removeBookmarkForPageIndex:(NSUInteger)pageIndex

Discussion

Remove the bookmark at the specified index number.

Indexes are zero based. This method raises an exception if index is out of bounds.

Declared In

CPDFDocument.h

– bookmarkForPageIndex:

Returns the bookmark at the specified index number.

- (CPDFBookmark *)bookmarkForPageIndex:(NSUInteger)pageIndex

Discussion

Returns the bookmark at the specified index number.

Indexes are zero based. This method raises an exception if index is out of bounds.

Declared In

CPDFDocument.h

– watermarks

A array of document’s watermarks.

- (NSArray<CPDFWatermark*> *)watermarks

Discussion

A array of document’s watermarks.

Declared In

CPDFDocument.h

– addWatermark:

Add a watermark.

- (BOOL)addWatermark:(CPDFWatermark *)watermark

Parameters

watermark

A PDF watermark object.

Discussion

Add a watermark.

Declared In

CPDFDocument.h

– removeWatermark:

Remove the watermark.

- (BOOL)removeWatermark:(CPDFWatermark *)watermark

Parameters

watermark

The PDF watermark object from document’s watermarks.

Discussion

Remove the watermark.

Declared In

CPDFDocument.h

– updateWatermark:

Update the watermark.

- (BOOL)updateWatermark:(CPDFWatermark *)watermark

Parameters

watermark

The PDF watermark object from document’s watermarks.

Discussion

Update the watermark.

Declared In

CPDFDocument.h

– headerFooter

Gets the header & footer of the document.

- (CPDFHeaderFooter *)headerFooter

Discussion

Gets the header & footer of the document.

Declared In

CPDFDocument.h

– bates

Gets the bates numbers of the document.

- (CPDFBates *)bates

Discussion

Gets the bates numbers of the document.

Declared In

CPDFDocument.h

– background

Gets the background of the document.

- (CPDFBackground *)background

Discussion

Gets the background of the document.

Declared In

CPDFDocument.h

– signatures

Get the current signature list.

- (NSArray<CPDFSignature*> *)signatures

Discussion

Get the current signature list.

Declared In

CPDFDocument.h

– removeSignature:

Delete the corresponding signature

- (void)removeSignature:(CPDFSignature *)signature

Discussion

Delete the corresponding signature

Declared In

CPDFDocument.h

– writeSignatureToURL:withWidget:PKCS12Cert:password:location:reason:permissions:

Add a signature to a document.

- (BOOL)writeSignatureToURL:(NSURL *)url withWidget:(CPDFSignatureWidgetAnnotation *)widget PKCS12Cert:(NSString *)path password:(NSString *)password location:(NSString *)location reason:(NSString *)reason permissions:(CPDFSignaturePermissions)permissions

Parameters

url

Save path for the signature file.

widget

Signature widget.

path

Certificate file path.

password

Certificate file password

location

The hostname or physical location of the CPU which was used to sign the document.

reason

Signature reason.

type

Modify permission type. See more types by CPDFSignaturePermissions

Return Value

Return true: Write signature successfully. Return false: Write signature failed.

Discussion

Add a signature to a document.

Declared In

CPDFDocument.h

  pageCount

The number of pages in the document.

@property (nonatomic, readonly) NSUInteger pageCount

Discussion

The number of pages in the document.

Declared In

CPDFDocument.h

– pageSizeAtIndex:

Returns the page size at the specified index number.

- (CGSize)pageSizeAtIndex:(NSUInteger)index

Discussion

Returns the page size at the specified index number.

Indexes are zero based. This method raises an exception if index is out of bounds.

Declared In

CPDFDocument.h

– pageAtIndex:

Returns a CPDFPage object representing the page at index.

- (CPDFPage *)pageAtIndex:(NSUInteger)index

Discussion

Returns a CPDFPage object representing the page at index.

Indexes are zero based. This method raises an exception if index is out of bounds.

Declared In

CPDFDocument.h

– indexForPage:

Gets the index number for the specified page.

- (NSUInteger)indexForPage:(CPDFPage *)page

Discussion

Gets the index number for the specified page.

Given a CPDFPage, returns the pages index within the document. Indices are zero-based.

Declared In

CPDFDocument.h

– insertPage:atIndex:

Inserts a blank page at the specified index point.

- (BOOL)insertPage:(CGSize)pageSize atIndex:(NSUInteger)index

Discussion

Inserts a blank page at the specified index point.

Indexes are zero based. The index must lie within bounds, or be equal to the length of bounds.

Declared In

CPDFDocument.h

– insertPage:withImage:atIndex:

Inserts a blank page with image at the specified index point.

- (BOOL)insertPage:(CGSize)pageSize withImage:(NSString *)imagePath atIndex:(NSUInteger)index

Discussion

Inserts a blank page with image at the specified index point.

Indexes are zero based. The index must lie within bounds, or be equal to the length of bounds.

Declared In

CPDFDocument.h

– removePageAtIndexSet:

Removes page(s) at the specified index set.

- (BOOL)removePageAtIndexSet:(NSIndexSet *)indexSet

Discussion

Removes page(s) at the specified index set.

Declared In

CPDFDocument.h

– movePageAtIndex:withPageAtIndex:

Move one page to another.

- (BOOL)movePageAtIndex:(NSUInteger)indexA withPageAtIndex:(NSUInteger)indexB

Discussion

Move one page to another.

This method raises an exception if either index value is out of bounds.

Declared In

CPDFDocument.h

– exchangePageAtIndex:withPageAtIndex:

Exchanges one page with another.

- (BOOL)exchangePageAtIndex:(NSUInteger)indexA withPageAtIndex:(NSUInteger)indexB

Discussion

Exchanges one page with another.

This method raises an exception if either index value is out of bounds.

Declared In

CPDFDocument.h

– importPages:fromDocument:atIndex:

Import page(s) from another document at the specified index point.

- (BOOL)importPages:(NSIndexSet *)indexSet fromDocument:(CPDFDocument *)document atIndex:(NSUInteger)index

Discussion

Import page(s) from another document at the specified index point.

This method raises an exception if either index value is out of bounds.

Declared In

CPDFDocument.h

– exportAnnotationToXFDFPath:

Export annotation to XFDF document.

- (BOOL)exportAnnotationToXFDFPath:(NSString *)xfdfPath

Discussion

Export annotation to XFDF document.

Declared In

CPDFDocument.h

– importAnnotationFromXFDFPath:

Import annotations from XFDF document.

- (BOOL)importAnnotationFromXFDFPath:(NSString *)xfdfPath

Discussion

Import annotations from XFDF document.

Declared In

CPDFDocument.h

– removeAllSignature

Remove all signatures.

- (BOOL)removeAllSignature

Discussion

Remove all signatures.

Declared In

CPDFDocument.h

– hasAnnotations

A Boolean value indicating whether the document contains annotations.

- (BOOL)hasAnnotations

Discussion

A Boolean value indicating whether the document contains annotations.

Declared In

CPDFDocument.h

– resetForm

Reset all forms in PDF document.

- (void)resetForm

Discussion

Reset all forms in PDF document.

Declared In

CPDFDocument.h

– extractImageFromPages:toPath:

Extract image at the specified index set.

- (NSUInteger)extractImageFromPages:(NSIndexSet *)indexSet toPath:(NSString *)path

Discussion

Extract image at the specified index set.

Declared In

CPDFDocument.h

– cancelExtractImage

Cancels a extract initiated with extractImageFromPages:toPath:.

- (void)cancelExtractImage

Discussion

Cancels a extract initiated with extractImageFromPages:toPath:.

Declared In

CPDFDocument.h

– summaryHTML

- (NSString *)summaryHTML

– type

Gets PDF/A conformance levels.

- (CPDFType)type

Discussion

Gets PDF/A conformance levels.

See Also

Declared In

CPDFDocument.h

– writePDFAToURL:withType:

Converts existing PDF files to PDF/A compliant documents, including PDF/A-1a and PDF/A-1b only.

- (BOOL)writePDFAToURL:(NSURL *)url withType:(CPDFType)type

Discussion

Converts existing PDF files to PDF/A compliant documents, including PDF/A-1a and PDF/A-1b only.

The conversion option analyzes the content of existing PDF files and performs a sequence of modifications in order to produce a PDF/A compliant document. Features that are not suitable for long-term archiving (such as encryption, obsolete compression schemes, missing fonts, or device-dependent color) are replaced with their PDF/A compliant equivalents. Because the conversion process applies only necessary changes to the source file, the information loss is minimal.

See Also

Declared In

CPDFDocument.h

  isFinding

Returns a Boolean value indicating whether an asynchronous find operation is in progress.

@property (nonatomic, readonly) BOOL isFinding

Discussion

Returns a Boolean value indicating whether an asynchronous find operation is in progress.

Declared In

CPDFDocument.h

– findString:withOptions:

Synchronously finds all instances of the specified string in the document.

- (NSArray<NSArray<CPDFSelection*> *> *)findString:(NSString *)string withOptions:(CPDFSearchOptions)options

Discussion

Synchronously finds all instances of the specified string in the document.

Each hit gets added to an NSArray object as a CPDFSelection object. If there are no hits, this method returns an empty array. Use this method when the complete search process will be brief and when you don’t need the flexibility or control offered by beginFindString:withOptions:.

Declared In

CPDFDocument.h

– beginFindString:withOptions:

Asynchronously finds all instances of the specified string in the document.

- (void)beginFindString:(NSString *)string withOptions:(CPDFSearchOptions)options

Discussion

Asynchronously finds all instances of the specified string in the document.

This method returns immediately. It causes delegate methods to be called when searching begins and ends, on each search hit, and when the search proceeds to a new page.

Declared In

CPDFDocument.h

– cancelFindString

Cancels a search initiated with beginFindString:withOptions:.

- (void)cancelFindString

Discussion

Cancels a search initiated with beginFindString:withOptions:.

Declared In

CPDFDocument.h

– findEditAllPageString:withOptions:

Synchronously finds all instances of the specified string in the document.

- (NSArray<NSArray<CPDFSelection*> *> *_Nullable)findEditAllPageString:(NSString *_Nonnull)string withOptions:(CPDFSearchOptions)options

Discussion

Synchronously finds all instances of the specified string in the document.

Each hit gets added to an NSArray object as a CPDFSelection object. If there are no hits, this method returns an empty array. Call only in Content Editing

Declared In

CPDFDocument.h

– findEditFindPages:withString:withOptions:

Synchronously finds all instances of the specified string in the document.

- (NSArray<NSArray<CPDFSelection*> *> *_Nullable)findEditFindPages:(NSIndexSet *_Nonnull)indexSet withString:(NSString *_Nonnull)string withOptions:(CPDFSearchOptions)options

Parameters

indexSet

A collection of page numbers to search Call only in Content Editing

Discussion

Synchronously finds all instances of the specified string in the document.

Each hit gets added to an NSArray object as a CPDFSelection object. If there are no hits, this method returns an empty array.

Declared In

CPDFDocument.h

– startFindEditTextFromPage:withString:options:

Synchronously finds all instances of the specified string in the document.

- (NSArray<NSArray<CPDFSelection*> *> *_Nullable)startFindEditTextFromPage:(CPDFPage *_Nullable)currentPage withString:(NSString *_Nonnull)string options:(CPDFSearchOptions)options

Parameters

currentPage

Which page to start with Call only in Content Editing

Discussion

Synchronously finds all instances of the specified string in the document.

Each hit gets added to an NSArray object as a CPDFSelection object. If there are no hits, this method returns an empty array.

Declared In

CPDFDocument.h

– findEditSelections

Search result Call only in Content Editing

- (NSArray<NSArray<CPDFSelection*> *> *_Nullable)findEditSelections

Discussion

Search result Call only in Content Editing

Declared In

CPDFDocument.h

– findForwardEditText

Previous result Call only in Content Editing

- (CPDFSelection *_Nullable)findForwardEditText

Discussion

Previous result Call only in Content Editing

Declared In

CPDFDocument.h

– findBackwordEditText

Next result Call only in Content Editing

- (CPDFSelection *_Nullable)findBackwordEditText

Discussion

Next result Call only in Content Editing

Declared In

CPDFDocument.h

– cancelFindEditString

Cancels a search initiated with findEditFindPages: Call only in Content Editing

- (void)cancelFindEditString

Discussion

Cancels a search initiated with findEditFindPages: Call only in Content Editing

Declared In

CPDFDocument.h

– replaceWithSelection:searchString:toReplaceString:completionHandler:

Replace the content edit by specifying selection param selection Replaces the specified selection param searchString Searched character param replaceString Replace character get newSelection The replacement results in a new selection

- (BOOL)replaceWithSelection:(CPDFSelection *_Nonnull)selection searchString:(NSString *_Nonnull)searchString toReplaceString:(NSString *_Nullable)replaceString completionHandler:(void ( ^ _Nullable ) ( CPDFSelection *_Nullable newSelection ))handler

Discussion

Replace the content edit by specifying selection param selection Replaces the specified selection param searchString Searched character param replaceString Replace character get newSelection The replacement results in a new selection

Declared In

CPDFDocument.h

– replaceAllEditTextWithString:toReplaceString:

Replace all search results Call only in Content Editing

- (BOOL)replaceAllEditTextWithString:(NSString *_Nonnull)string toReplaceString:(NSString *_Nullable)replaceString

Discussion

Replace all search results Call only in Content Editing

Declared In

CPDFDocument.h

– applyRedactions

Applies redaction annotations in the document.

- (void)applyRedactions

Discussion

Applies redaction annotations in the document.

Declared In

CPDFDocument.h

Deprecated Methods

– findEditString:withOptions:

- (void)findEditString:(NSString *)string withOptions:(CPDFSearchOptions)options

– findEditString:findPages:withOptions:

- (void)findEditString:(NSString *)string findPages:(NSIndexSet *)indexSet withOptions:(CPDFSearchOptions)options

– startFindEditTextWithCurrentPage:withString:withOptions:

- (CPDFSelection *)startFindEditTextWithCurrentPage:(CPDFPage *)currentPage withString:(NSString *)string withOptions:(CPDFSearchOptions)options

– findNextEditTextWithLastlection:withString:withOptions:

- (CPDFSelection *)findNextEditTextWithLastlection:(CPDFSelection *)lastSelection withString:(NSString *)string withOptions:(CPDFSearchOptions)options

– findPrevEditTextWithLastlection:withString:withOptions:

- (CPDFSelection *)findPrevEditTextWithLastlection:(CPDFSelection *)lastSelection withString:(NSString *)string withOptions:(CPDFSearchOptions)options