PDFDocument

public final class PDFDocument

A handle to operate on a document object.

  • Creates a new page and adds it after the last page of the document.

    Declaration

    Swift

    @discardableResult
    public func addPage() -> PDFPage

    Return Value

    A PDFPage object.

  • Creates a new page and adds it after the last page of the document.

    Warning

    The DrawingContext object should not be stored and used outside of the lifetime of the call to the closure.

    Declaration

    Swift

    @discardableResult
    public func addPage(_ draw: (DrawingContext) throws -> Void) rethrows -> PDFPage

    Parameters

    draw

    The drawing operations to perform, or nil if no drawing should be performed.

    Return Value

    A PDFPage object.

  • Creates a new page of the specified width and height and adds it after the last page of the document.

    Declaration

    Swift

    @discardableResult
    public func addPage(width: Float, height: Float) -> PDFPage

    Parameters

    width

    The width of the page.

    height

    The height of the page.

    Return Value

    A PDFPage object.

  • Creates a new page of the specified width and height and adds it after the last page of the document.

    Warning

    The DrawingContext object should not be stored and used outside of the lifetime of the call to the closure.

    Declaration

    Swift

    @discardableResult
    public func addPage(width: Float,
                        height: Float,
                        _ draw: (DrawingContext) throws -> Void) rethrows -> PDFPage

    Parameters

    width

    The width of the page.

    height

    The height of the page.

    draw

    The drawing operations to perform, or nil if no drawing should be performed.

    Return Value

    A PDFPage object.

  • Creates a new page of the specified size and direction and adds it after the last page of the document.

    Declaration

    Swift

    @discardableResult
    public func addPage(size: PDFPage.Size,
                        direction: PDFPage.Direction) -> PDFPage

    Parameters

    size

    A predefined page-size value.

    direction

    The direction of the page (portrait or landscape).

    Return Value

    A PDFPage object.

  • Creates a new page of the specified size and direction and adds it after the last page of the document.

    Warning

    The DrawingContext object should not be stored and used outside of the lifetime of the call to the closure.

    Declaration

    Swift

    @discardableResult
    public func addPage(size: PDFPage.Size,
                        direction: PDFPage.Direction,
                        _ draw: (DrawingContext) throws -> Void) rethrows -> PDFPage

    Parameters

    size

    A predefined page-size value.

    direction

    The direction of the page (portrait or landscape).

    draw

    The drawing operations to perform, or nil if no drawing should be performed.

    Return Value

    A PDFPage object.

  • Creates a new page and inserts it just before the page with the specified index.

    Declaration

    Swift

    @discardableResult
    public func insertPage(atIndex index: Int) -> PDFPage

    Parameters

    index

    The index at which the new page will appear. index must be a valid index of the array pages or equal to its endIndex property.

    Return Value

    A PDFPage object.

  • Creates a new page and inserts it just before the page with the specified index.

    Warning

    The DrawingContext object should not be stored and used outside of the lifetime of the call to the closure.

    Declaration

    Swift

    @discardableResult
    public func insertPage(atIndex index: Int, _ draw: (DrawingContext) throws -> Void) rethrows -> PDFPage

    Parameters

    index

    The index at which the new page will appear. index must be a valid index of the array pages or equal to its endIndex property.

    draw

    The drawing operations to perform, or nil if no drawing should be performed.

    Return Value

    A PDFPage object.

  • Creates a new page of the specified width and height and inserts it just before the page with the specified index.

    Declaration

    Swift

    @discardableResult
    public func insertPage(width: Float, height: Float, atIndex index: Int) -> PDFPage

    Parameters

    width

    The width of the page.

    height

    The height of the page.

    index

    The index at which the new page will appear. index must be a valid index of the array pages or equal to its endIndex property.

    Return Value

    A PDFPage object.

  • Creates a new page of the specified width and height and inserts it just before the page with the specified index.

    Warning

    The DrawingContext object should not be stored and used outside of the lifetime of the call to the closure.

    Declaration

    Swift

    @discardableResult
    public func insertPage(width: Float,
                           height: Float,
                           atIndex index: Int,
                           _ draw: (DrawingContext) throws -> Void) rethrows -> PDFPage

    Parameters

    width

    The width of the page.

    height

    The height of the page.

    index

    The index at which the new page will appear. index must be a valid index of the array pages or equal to its endIndex property.

    draw

    The drawing operations to perform, or nil if no drawing should be performed.

    Return Value

    A PDFPage object.

  • Creates a new page of the specified size and direction and inserts it just before the page with the specified index.

    Declaration

    Swift

    @discardableResult
    public func insertPage(size: PDFPage.Size,
                           direction: PDFPage.Direction,
                           atIndex index: Int) -> PDFPage

    Parameters

    size

    A predefined page-size value.

    direction

    The direction of the page (portrait or landscape).

    index

    The index at which the new page will appear. index must be a valid index of the array pages or equal to its endIndex property.

    Return Value

    A PDFPage object.

  • Creates a new page of the specified size and direction and inserts it just before the page with the specified index.

    Warning

    The DrawingContext object should not be stored and used outside of the lifetime of the call to the closure.

    Declaration

    Swift

    @discardableResult
    public func insertPage(size: PDFPage.Size,
                           direction: PDFPage.Direction,
                           atIndex index: Int,
                           _ draw: (DrawingContext) throws -> Void) rethrows -> PDFPage

    Parameters

    size

    A predefined page-size value.

    direction

    The direction of the page (portrait or landscape).

    index

    The index at which the new page will appear. index must be a valid index of the array pages or equal to its endIndex property.

    draw

    The drawing operations to perform, or nil if no drawing should be performed.

    Return Value

    A PDFPage object.

  • Renders the document and returns its contents.

    Declaration

    Swift

    public func getData() -> Data

    Return Value

    The document’s contents

  • Determines how pages should be displayed. If this attribute is not set, the setting of the viewer application is used.

    Declaration

    Swift

    public var pageLayout: PageLayout { get set }
  • Adds a page labeling range for the document. The page label is shown in the thumbnails view.

    Example:

    document.addPageLabel(.lowerRoman, fromPage: 0, startingWith: 1)
    document.addPageLabel(.decimal, fromPage: 4, startingWith: 1)
    document.addPageLabel(.decimal, fromPage: 7, startingWith: 8, withPrefix: "A-")
    

    Result in a document with pages labeled:

    i, ii, iii, iv, 1, 2, 3, A-8, A-9, …

    Declaration

    Swift

    public func addPageLabel(_ style: PageNumberStyle,
                             fromPage startingPage: Int,
                             startingWith firstPageNumber: Int,
                             withPrefix prefix: String = String())

    Parameters

    style
    startingPage

    The first page that applies this labeling range.

    firstPageNumber

    The first page number to use.

    prefix

    The prefix for the page label. Default is nil.

  • Sets a password for the document. If the password is set, the document contents are encrypted.

    Throws

    PDFError.encryptionInvalidPassword if the owner password is zero length string or same value as the user password; PDFError.invalidEncryptionKeyLength if an invalid key length was specified.

    Declaration

    Swift

    public func setPassword(owner: String,
                            user: String? = nil,
                            permissions: Permissions? = nil,
                            encryptionMode: EncryptionMode? = nil) throws

    Parameters

    owner

    The password for the owner of the document. The owner can change the permission of the document. Zero length string and the same value as user password are not allowed.

    user

    The password for the user of the document. May be set to nil or zero length string.

    permissions

    The permission flags for the document. Default is nil.

    encryptionMode

    The encryption mode. Ups the version of PDF to 1.4 when the mode is set to .r3. Default is nil.

  • The metadata of the document: an author, keywords, creation date etc.

    Declaration

    Swift

    public var metadata: PDFDocument.Metadata
  • The mode of compression for a document.

    See more

    Declaration

    Swift

    public struct CompressionMode : OptionSet
  • The encryption mode to use for a document.

    See more

    Declaration

    Swift

    public enum EncryptionMode
  • This structure encapsulates the metadata of a document.

    See more

    Declaration

    Swift

    public struct Metadata : Equatable
  • Determines how pages in the document should be displayed.

    See more

    Declaration

    Swift

    public enum PageLayout : UInt32
  • Determines a page labeling style of the document.

    See more

    Declaration

    Swift

    public enum PageNumberStyle : UInt32
  • Permission flags to use in a document.

    See more

    Declaration

    Swift

    public struct Permissions : OptionSet