Class

PDFDocument

A PDFDocument object represents PDF data or a PDF file and defines methods for writing, searching, and selecting PDF data.

Overview

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.

Symbols

Initializing Documents

init?(data: Data)

Initializes a PDFDocument object with the passed-in data.

init?(url: URL)

Initializes a PDFDocument object with the contents at the specified URL (if the URL is invalid, this method returns NULL).

Accessing Document Information

var documentURL: URL?

Returns the URL for the document.

var majorVersion: Int32

Returns the major version of the document.

var minorVersion: Int32

Returns the minor version of the document.

var string: String?

Returns a string representing the textual content for the entire document.

func outlineItem(for: PDFSelection)

Returns the most likely parent PDF outline object for the selection.

var outlineRoot: PDFOutline?

Sets the document’s root outline to a PDF outline object.

var documentAttributes: [AnyHashable : Any]?

Returns a dictionary of document metadata.

Managing Document Security

var isEncrypted: Bool

Returns a Boolean value specifying whether the document is encrypted.

var isLocked: Bool

Returns a Boolean value indicating whether the document is locked.

func unlock(withPassword: String)

Attempts to unlock an encrypted document.

var allowsCopying: Bool

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

var allowsPrinting: Bool

Returns a Boolean value indicating whether the document allows printing.

Writing Out the PDF Data

func dataRepresentation()

Returns a representation of the document as an NSData object.

func write(toFile: String)

Writes the document to a file at the specified path.

func write(toFile: String, withOptions: [AnyHashable : Any]? = nil)

Writes the document to a file at the specified path with the specified options.

func write(to: URL)

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

func write(to: URL, withOptions: [AnyHashable : Any]? = nil)

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

Working with Pages

var pageCount: Int

Returns the number of pages in the document.

func page(at: Int)

Returns the page at the specified index number.

func index(for: PDFPage)

Gets the index number for the specified page.

func insert(PDFPage, at: Int)

Inserts a page at the specified index point.

func removePage(at: Int)

Removes the page at the specified index point.

Managing Find Operations

func findString(String, withOptions: Int)

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

func beginFindString(String, withOptions: Int)

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

func beginFind([String], withOptions: Int)

Asynchronously finds all instances of the specified array of strings in the document.

func findString(String, from: PDFSelection?, withOptions: Int)

Synchronously finds the next occurance of a string after the specified selection (or before the selection if you specified NSBackwardsSearch as a search option.

var isFinding: Bool

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

Working with Selections

func selection(from: PDFPage, atCharacterIndex: Int, to: PDFPage, atCharacterIndex: Int)

Returns the specified selection based on starting and ending character indexes.

func selection(from: PDFPage, at: NSPoint, to: PDFPage, at: NSPoint)

Returns the specified selection based on starting and ending points.

var selectionForEntireDocument: PDFSelection?

Returns a selection representing the textual content of the entire document.

Setting the Delegate

var delegate: AnyObject?

Returns the object acting as the delegate for the PDFDocument object.

Searching Documents

func didMatchString(PDFSelection)

Called for every match found during a find operation.

func documentDidBeginDocumentFind(Notification)

Called when the PDFDocumentDidBeginFindNotification notification is posted.

func documentDidBeginPageFind(Notification)

Called when the PDFDocumentDidBeginPageFindNotification notification is posted.

func documentDidEndDocumentFind(Notification)

Called when the PDFDocumentDidEndFindNotification notification is posted.

func documentDidEndPageFind(Notification)

Called when the PDFDocumentDidEndPageFindNotification notification is posted.

func documentDidFindMatch(Notification)

Called when the PDFDocumentDidFindMatchNotification notification is posted.

Unlocking Documents

func documentDidUnlock(Notification)

Called when the PDFDocumentDidUnlockNotification notification is posted.

Determining the Page Class

var pageClass: AnyClass

Returns the class that is allocated and initialized when page objects are created for the document.

Constants

PDFPrintScalingMode

The type of scaling to be used when printing a page (see PDFDocument).

Document Attribute Keys

Keys for the document attributes dictionary. See documentAttributes and setDocumentAttributes(_:).

Notifications

PDFDocument declares and posts the following notifications:

static let PDFDocumentDidBeginPageFind: NSNotification.Name

Posted each time a find operation begins working on a new page of a document.

static let PDFDocumentDidEndPageFind: NSNotification.Name

Posted each time a find operation finishes working on a page in a document.

static let PDFDocumentDidFindMatch: NSNotification.Name

Posted each time a string match is found in a document.

static let PDFDocumentDidBeginWrite: NSNotification.Name

Posted each time a write operation begins working on a document.

static let PDFDocumentDidEndWrite: NSNotification.Name

Posted each time a write operation finishes working on a document.

static let PDFDocumentDidBeginPageWrite: NSNotification.Name

Posted each time a write operation begins working on a page in a document.

static let PDFDocumentDidEndPageWrite: NSNotification.Name

Posted each time a write operation finishes working on a page in a document.

Relationships

Inherits From