| Inherits from | |
| Conforms to | |
| Framework | Library/Frameworks/Quartz.framework/Frameworks/PDFKit.framework |
| Availability | Available in Mac OS X v10.4 and later.
|
| Declared in | PDFDocument.h |
PDFDocument, a subclass of NSObject, represents PDF data or a PDF file and defines methods for writing, searching, and selecting PDF data.
A PDFDocument object represents PDF data or a PDF file. The other utility classes are either instantiated from methods in PDFDocument, as are PDFPage and PDFOutline; or support it, as do PDFSelection and PDFDestination.
You initialize a PDFDocument object with PDF data or 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.
– documentURL
– majorVersion
– minorVersion
– string
– outlineItemForSelection:
– outlineRoot
– documentAttributes
– setDocumentAttributes:
– setOutlineRoot:
– dataRepresentation
– writeToFile:
– writeToFile:withOptions:
– writeToURL:
– writeToURL:withOptions:
– pageCount
– pageAtIndex:
– indexForPage:
– insertPage:atIndex:
– removePageAtIndex:
– exchangePageAtIndex:withPageAtIndex:
– findString:withOptions:
– beginFindString:withOptions:
– beginFindStrings:withOptions:
– findString:fromSelection:withOptions:
– isFinding
– cancelFindString
– selectionFromPage:atCharacterIndex:toPage:atCharacterIndex:
– selectionFromPage:atPoint:toPage:atPoint:
– selectionForEntireDocument
– didMatchString: delegate method
– documentDidBeginDocumentFind: delegate method
– documentDidBeginPageFind: delegate method
– documentDidEndDocumentFind: delegate method
– documentDidEndPageFind: delegate method
– documentDidFindMatch: delegate method
– documentDidUnlock: delegate method
Returns a Boolean value indicating whether the document allows copying of content to the Pasteboard.
- (BOOL)allowsCopying
The ability to copy content from a PDF document is an attribute unrelated to whether the document is locked or unlocked. It depends on the PDF permissions set by the document’s author.
This method only determines the desired permissions setting in the PDF document; it is up to the application to enforce (or ignore) the permissions.
This method always returns YES if the document is not encrypted. Note that in many cases an encrypted document may still be readable by all users due to the standard empty string password. For more details about user and owner passwords, see the Adobe PDF specification.
PDFDocument.hReturns a Boolean value indicating whether the document allows printing.
- (BOOL)allowsPrinting
The ability to print a PDF document is an attribute unrelated to whether the document is locked or unlocked. It depends on the PDF permissions set by the document’s author.
This method only determines the desired permissions setting in the PDF document; it is up to the application to enforce (or ignore) the permissions.
This method always returns YES if the document is not encrypted. Note that in many cases an encrypted document may still be readable by all users due to the standard empty string password. For more details about user and owner passwords, see the Adobe PDF specification.
PDFDocument.hAsynchronously finds all instances of the specified string in the document.
- (void)beginFindString:(NSString *)string withOptions:(int)options
This method returns immediately. It causes notifications to be issued when searching begins and ends, on each search hit, and when the search proceeds to a new page. For options, refer to Searching and Comparing Strings.
PDFDocument.hAsynchronously finds all instances of the specified array of strings in the document.
- (void)beginFindStrings:(NSArray *)strings withOptions:(int)options;
This method returns immediately. It causes notifications to be issued when searching begins and ends, on each search hit, and when the search proceeds to a new page. For options, refer to Searching and Comparing Strings.
– beginFindString:withOptions:– findString:withOptions:– isFinding– cancelFindStringPDFDocument.hCancels a search initiated with beginFindString:withOptions:.
- (void)cancelFindString
PDFDocument.hReturns a representation of the document as an NSData object.
- (NSData *)dataRepresentation
PDFDocument.hReturns the object acting as the delegate for the PDFDocument object.
- (id)delegate
PDFDocument.hReturns a dictionary of document metadata.
- (NSDictionary *)documentAttributes
The dictionary of document metadata. The dictionary may be empty, or only some of the keys may have associated values. See “Constants” for a list of possible key words.
Metadata is optional for PDF documents.
PDFDocument.hReturns the URL for the document.
- (NSURL *)documentURL
The URL for the document; may return NULL if the document was created from an NSData object.
PDFDocument.hSwaps one page with another.
- (void)exchangePageAtIndex:(NSUInteger)indexA withPageAtIndex:(NSUInteger)indexB
This method raises an exception if either index value is out of bounds.
PDFDocument.hSynchronously finds the next occurance of a string after the specified selection (or before the selection if you specified NSBackwardsSearch as a search option.
- (PDFSelection *)findString:(NSString *)string fromSelection:(PDFSelection *)selection withOptions:(int)options
Matches are returned as a PDFSelection object. If the search reaches the end (or beginning) of the document without any hits, this method returns NULL.
If you pass NULL for the selection, this method begins searching from the beginning of the document (or the end, if you specified NSBackwardsSearch).
You can use this method to implement “Find Again” behavior. For options, refer to Searching and Comparing Strings.
PDFDocument.hSynchronously finds all instances of the specified string in the document.
- (NSArray *)findString:(NSString *)string withOptions:(int)options
Each hit gets added to an NSArray object as a PDFSelection 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:. For options, refer to Searching and Comparing Strings.
PDFDocument.hGets the index number for the specified page.
- (NSUInteger)indexForPage:(PDFPage *)page
Indexes are zero-based. This method raises an exception and returns NSNotFound if page is not found.
– pageCount– pageAtIndex:– insertPage:atIndex:– removePageAtIndex:– exchangePageAtIndex:withPageAtIndex:PDFDocument.hInitializes a PDFDocument object with the passed-in data.
- (id)initWithData:(NSData *)data
A PDFDocument instance initialized with the passed-in PDF data, or NULL if the object could not be initialized.
The data must be PDF data encapsulated in an NSData object; otherwise this method returns NULL.
PDFDocument.hInitializes a PDFDocument object with the contents at the specified URL (if the URL is invalid, this method returns NULL).
- (id)initWithURL:(NSURL *)url
A PDFDocument instance initialized with the data at the passed-in URL or NULL if the object could not be initialized or if the URL is invalid.
PDFDocument.hInserts a page at the specified index point.
- (void)insertPage:(PDFPage *)page atIndex:(NSUInteger)index
This method raises an exception if index is out of bounds.
Be aware that a PDF viewing application might use the size of the first page in the document as representative of all page sizes when reporting the size of a document. If you need to get the actual size of an individual page, you can use boundsForBox: (note that the size is returned in points, which are typically converted to inches or centimeters by PDF viewing applications).
– pageCount– pageAtIndex:– indexForPage:– removePageAtIndex:– exchangePageAtIndex:withPageAtIndex:PDFDocument.hReturns a Boolean value specifying whether the document is encrypted.
- (BOOL)isEncrypted
YES if the document is encrypted, whether it is locked or unlocked; NO otherwise.
If encrypted, reading the document requires a password.
Encrypted documents whose password is the empty string are unlocked automatically upon opening, because PDF Kit tries the empty string as a password if none is supplied. Use the setPassword: method to unlock a document using a password.
PDFDocument.hReturns a Boolean value indicating whether an asynchronous find operation is in progress.
- (BOOL)isFinding
PDFDocument.hReturns a Boolean value indicating whether the document is locked.
- (BOOL)isLocked
YES if the document is locked; NO otherwise.
Only encrypted documents can be locked. Encrypted documents whose password is the empty string are unlocked automatically upon opening, because PDF Kit tries the empty string as a password if none is supplied. Use the setPassword: method to unlock a document using a password.
PDFDocument.hReturns the major version of the document.
- (int)majorVersion
The major version of the document.
PDFDocument.hReturns the minor version of the document.
- (int)minorVersion
The minor version of the document.
PDFDocument.hReturns the most likely parent PDF outline object for the selection.
- (PDFOutline *)outlineItemForSelection:(PDFSelection *)selection
The area of the document currently selected by the user. A selection can span multiple outline items, but only the point representing the first character is considered.
The PDF outline object that is the most likely parent of the specified selection. Note that only the point representing the first character of the selection is considered in this method.
Typically, outlines represent structural items such as chapters. You can use this method to identify the chapter that a selection falls within.
PDFDocument.hReturns the root PDF outline object for the document.
- (PDFOutline *)outlineRoot
The root outline object or NULL if there is no root outline object. The root outline is the nonvisible top-level container for outline items.
– outlineItemForSelection:– setOutlineRoot:PDFDocument.hReturns the page at the specified index number.
- (PDFPage *)pageAtIndex:(NSUInteger)index
Indexes are zero based. This method raises an exception if index is out of bounds.
– pageCount– indexForPage:– insertPage:atIndex:– removePageAtIndex:– exchangePageAtIndex:withPageAtIndex:PDFDocument.hReturns the class that is allocated and initialized when page objects are created for the document.
- (Class)pageClass
If you want to supply a custom page class, subclass PDFDocument and implement this method to return your custom class. Note that your custom class must be a subclass of PDFPage; otherwise, the behavior is undefined.
The default implementation of pageClass returns [PDFPage class].
PDFDocument.hReturns the number of pages in the document.
- (NSUInteger)pageCount
– pageAtIndex:– indexForPage:– insertPage:atIndex:– removePageAtIndex:– exchangePageAtIndex:withPageAtIndex:PDFDocument.hRemoves the page at the specified index point.
- (void)removePageAtIndex:(NSUInteger)index
This method raises an exception if index is out of bounds.
– pageCount– pageAtIndex:– indexForPage:– insertPage:atIndex:– exchangePageAtIndex:withPageAtIndex:PDFDocument.hReturns a selection representing the textual content of the entire document.
- (PDFSelection *)selectionForEntireDocument
PDFDocument.hReturns the specified selection based on starting and ending character indexes.
- (PDFSelection *)selectionFromPage:(PDFPage *)startPage atCharacterIndex:(NSUInteger)startChar toPage:(PDFPage *)endPage atCharacterIndex:(NSUInteger)endChar
The selection begins at startChar on startPage and ends at endChar on endPage. The starting and ending index values must be in the range of the number of characters (as returned by numberOfCharacters) within the respective PDFPage objects.
PDFDocument.hReturns the specified selection based on starting and ending points.
- (PDFSelection *)selectionFromPage:(PDFPage *)startPage atPoint:(NSPoint)startPt toPage:(PDFPage *)endPage atPoint:(NSPoint)endPt
The selection begins at startPt on startPage and ends at endPt on endPage. The starting and ending points should be specified in page space, relative to their respective pages.
The starting and ending points can be on the same page. In this case, invoking this method is equivalent to sending the selectionFromPoint:toPoint: message to a PDFPage object.
Page space is a 72 dpi coordinate system with the origin at the lower-left corner of the current page.
PDFDocument.hEstablishes the specified object as the delegate for the PDFDocument object.
- (void)setDelegate:(id)anObject
PDFDocument.hSets the document attributes.
- (void)setDocumentAttributes:(NSDictionary *)attributes
A dictionary containing document attributes as key-value pairs. See “Constants” for a list of possible key words.
PDFDocument.hSets the document’s root outline to a PDF outline object.
- (void)setOutlineRoot:(PDFOutline *)outline
The outline to be used as the document’s root outline. Pass NULL to strip the outline from a document.
When a PDF document is saved, the outline tree structure is written out to the destination PDF file.
– outlineRootPDFDocument.hAttempts to unlock an encrypted document.
- (BOOL)setPassword:(NSString *)password
The password to unlock an encrypted document (you cannot lock an unlocked PDF document by using an incorrect password).
YES if the specified password unlocks the document, NO otherwise.
If this method is successful, a PDFDocumentDidUnlockNotification notification is sent.
Returns a string representing the textual content for the entire document.
- (NSString *)string
A string that represents the textual content of the entire document.
Pages are delimited with linefeed characters.
This is a convenience method, equivalent to creating a selection object for the entire document and then invoking the PDFSelection class’s string method.
PDFDocument.hPasses a password to unlock encrypted documents.
- (BOOL)unlockWithPassword:(NSString *)password
If the password is correct, this method returns YES, and a PDFDocumentDidUnlockNotification notification is sent. Once unlocked, you cannot use this function to relock the document.
If you attempt to unlock an already unlocked document, one of the following occurs:
If the document is unlocked with full owner permissions, unlockWithPassword does nothing and returns YES. The password string is ignored.
If the document is unlocked with only user permissions, unlockWithPassword attempts to obtain full owner permissions with the password string. If the string fails, the document maintains its user permissions. In either case, this method returns YES.
PDFDocument.hWrites the document to a file at the specified path.
- (BOOL)writeToFile:(NSString *)path
PDFDocument.hWrites the document to a file at the specified path with the specified options.
- (BOOL)writeToFile:(NSString *)path withOptions:(NSDictionary *)options
The most commonly-used options are kCGPDFContextOwnerPassword, kCGPDFContextUserPassword, kCGPDFContextAllowsCopying and kCGPDFContextAllowsPrinting. For more details about these options, see the “Auxiliary Dictionary Keys” in CGPDFContext Reference, part of the Quartz 2D Reference.
PDFDocument.hWrites the document to a location specified by the passed-in URL.
- (BOOL)writeToURL:(NSURL *)url
PDFDocument.hWrites the document to the specified URL with the specified options.
- (BOOL)writeToURL:(NSURL *)url withOptions:(NSDictionary *)options
PDFDocument.hCalled for every match found during a find operation.
- (void)didMatchString:(PDFSelection *)instance
PDFDocument.hCalled when the PDFDocumentDidBeginFindNotification notification is posted.
- (void)documentDidBeginDocumentFind:(NSNotification *)notification
PDFDocumentDidBeginFindNotification– setDelegate:PDFDocument.hCalled when the PDFDocumentDidBeginPageFindNotification notification is posted.
- (void)documentDidBeginPageFind:(NSNotification *)notification
PDFDocumentDidBeginPageFindNotification– setDelegate:PDFDocument.hCalled when the PDFDocumentDidEndFindNotification notification is posted.
- (void)documentDidEndDocumentFind:(NSNotification *)notification
PDFDocumentDidEndFindNotification– setDelegate:PDFDocument.hCalled when the PDFDocumentDidEndPageFindNotification notification is posted.
- (void)documentDidEndPageFind:(NSNotification *)notification
PDFDocumentDidEndPageFindNotification– setDelegate:PDFDocument.hCalled when the PDFDocumentDidFindMatchNotification notification is posted.
- (void)documentDidFindMatch:(NSNotification *)notification
PDFDocumentDidFindMatchNotification– setDelegate:PDFDocument.hCalled when the PDFDocumentDidUnlockNotification notification is posted.
- (void)documentDidUnlock:(NSNotification *)notification
PDFDocumentDidUnlockNotification– setDelegate:PDFDocument.hThe type of scaling to be used when printing a page (see “PDF Page Scaling Modes for Printing”).
typedef NSInteger PDFPrintScalingMode;
PDFDocument.hKeys for the document attributes dictionary. See documentAttributes and setDocumentAttributes:.
extern NSString *PDFDocumentTitleAttribute; extern NSString *PDFDocumentAuthorAttribute; extern NSString *PDFDocumentSubjectAttribute; extern NSString *PDFDocumentCreatorAttribute; extern NSString *PDFDocumentProducerAttribute; extern NSString *PDFDocumentCreationDateAttribute; extern NSString *PDFDocumentModificationDateAttribute; extern NSString *PDFDocumentKeywordsAttribute;
PDFDocumentTitleAttributeAn optional text string (an NSString) containing the title of the document.
Available in Mac OS X v10.4 and later.
Declared in PDFDocument.h
PDFDocumentAuthorAttributeAn optional text string (an NSString) containing the name of the author of the document.
Available in Mac OS X v10.4 and later.
Declared in PDFDocument.h
PDFDocumentSubjectAttributeAn optional text string (an NSString) containing a description of the subject of the document.
Available in Mac OS X v10.4 and later.
Declared in PDFDocument.h
PDFDocumentCreatorAttributeAn optional text string (an NSString) containing the name of the application that created the document document content.
Available in Mac OS X v10.4 and later.
Declared in PDFDocument.h
PDFDocumentProducerAttributeAn optional text string (an NSString) containing the name of the application that produced the PDF data for the document.
Available in Mac OS X v10.4 and later.
Declared in PDFDocument.h
PDFDocumentCreationDateAttributeAn optional text string (an NSDate) containing the document’s creation date.
Available in Mac OS X v10.4 and later.
Declared in PDFDocument.h
PDFDocumentModificationDateAttributeAn optional text string (an NSDate) containing the document’s last-modified date.
Available in Mac OS X v10.4 and later.
Declared in PDFDocument.h
PDFDocumentKeywordsAttributeAn optional array of text strings (an NSArray of NSString objects) containing keywords for the document.
Available in Mac OS X v10.4 and later.
Declared in PDFDocument.h
PDFDocument.hModes that specify how the page should be scaled when printing. See the PDFView method printWithInfo:autoRotate:pageScaling:.
enum { kPDFPrintPageScaleNone = 0,
kPDFPrintPageScaleToFit = 1,
kPDFPrintPageScaleDownToFit = 2 };
kPDFPrintPageScaleNoneDo not apply scaling to the page when printing.
kPDFPrintPageScaleToFitScale each page up or down to best fit the paper size.
kPDFPrintPageScaleDownToFitScale large pages down to fit the paper size (smaller pages do not get scaled up).
PDFDocument.h
PDFDocument declares and posts the following notifications:
Posted when a document unlocks after a setPassword: message.
The notification object is the PDFDocument object itself.
PDFDocument.h
Posted when the beginFindString:withOptions: or findString:withOptions: method begins finding.
The notification object is the PDFDocument object itself.
PDFDocument.h
Posted when the beginFindString:withOptions: or findString:withOptions: method returns.
The beginFindString:withOptions: method returns immediately, so this notification is posted when the “find” operation is finished.
You can use this notification to know when to close or hide a progress bar.
The notification object is the PDFDocument object itself.
PDFDocument.h
Posted each time a find operation begins working on a new page of a document.
You can use this notification to update a progress bar.
The notification object is the PDFDocument object itself. To determine the page, use the @"PDFDocumentPageIndex" key to obtain userinfo of type NSNumber.
PDFDocument.h
Posted each time a find operation finishes working on a page in a document.
You can use this notification to update a progress bar.
The notification object is the PDFDocument object itself. To determine the page, use the @"PDFDocumentPageIndex" key to obtain userinfo of type NSNumber.
PDFDocument.h
Posted each time a string match is found in a document.
The notification object is the PDFDocument object itself. To determine the string selection found, use the @"PDFDocumentFoundSelection" key to obtain userinfo of type PDFSelection *
PDFDocument.hPosted each time a write operation begins working on a document.
The notification object is the PDFDocument object itself.
PDFDocument.hPosted each time a write operation finishes working on a document.
The notification object is the PDFDocument object itself.
PDFDocument.hPosted each time a write operation begins working on a page in a document.
The notification object is the PDFDocument object itself. To determine the page, use the @"PDFDocumentPageIndex" key to obtain userinfo of type NSNumber.
PDFDocument.hPosted each time a write operation finishes working on a page in a do