PSPDFDocumentEditor


@interface PSPDFDocumentEditor : NSObject

Manages document editing. Supports operations such as remove, move, rotate and add page. - note: This class requires the Document Editor component to be enabled for your license.

  • Starts an editing session on the document or a new blank editing session. - parameter: document The document used to initialize the document editor or nil. If nil, the document editor is initialized with zero pages. If a document is used, it must be a valid document. The changes won’t be visible on the document until the document editor is saved. - warning: Document editing is currently only supported for documents that contain no annotations or have all annotations embedded in the PDF file. Other annotation providers are not yet supported.

    Declaration

    Objective-C

    - (nullable instancetype)initWithDocument:(nullable PSPDFDocument *)document;

    Swift

    init?(document: PSPDFDocument?)

    Parameters

    document

    The document used to initialize the document editor or nil. If nil, the document editor is initialized with zero pages. If a document is used, it must be a valid document. The changes won’t be visible on the document until the document editor is saved.

  • Creates a document editor without a document. Use this to create a new document from scratch. - note: You need to add at least one page before saving with saveToPath:withCompletionBlock:. An empty document has 0 pages, which does not constitute a valid PDF document. - see: initWithDocument:

    Declaration

    Objective-C

    - (nonnull instancetype)init;

    Swift

    convenience init()
  • Reference to the backing document. Will remain nonnull if initWithDocument: with a document was used. - see: initWithDocument:

    Declaration

    Objective-C

    @property (readonly, nonatomic, nullable) PSPDFDocument *document;

    Swift

    var document: PSPDFDocument? { get }
  • Allows you to set security options for saving.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic, nullable)
        PSPDFProcessorSaveOptions *saveOptions;

    Swift

    var saveOptions: PSPDFProcessorSaveOptions? { get set }
  • Adds a document editor delegate to the subscriber list. - note: Delegates are weakly retained, but be a good citizen and manually deregister.

    Declaration

    Objective-C

    - (void)addDelegate:(nonnull id<PSPDFDocumentEditorDelegate>)delegate;

    Swift

    func add(_ delegate: PSPDFDocumentEditorDelegate)
  • Removes a document editor delegate from the subscriber list.

    Declaration

    Objective-C

    - (BOOL)removeDelegate:(nonnull id<PSPDFDocumentEditorDelegate>)delegate;

    Swift

    func remove(_ delegate: PSPDFDocumentEditorDelegate) -> Bool
  • Returns the page count of the edited Document. If you remove or add pages, this will reflect that change.

    Declaration

    Objective-C

    @property (readonly, nonatomic) NSUInteger pageCount;

    Swift

    var pageCount: UInt { get }
  • Returns the page size, already rotated.

    Declaration

    Objective-C

    - (CGSize)pageSizeForPageAtIndex:(NSUInteger)pageIndex;

    Swift

    func pageSizeForPage(at pageIndex: UInt) -> CGSize
  • Adds a new page at the specified page index, with the configuration options specified in configuration.

    Declaration

    Objective-C

    - (nonnull NSArray<PSPDFEditingChange *> *)
            addPageAt:(NSUInteger)index
    withConfiguration:(nonnull PSPDFNewPageConfiguration *)configuration;

    Swift

    func addPage(at index: UInt, with configuration: PSPDFNewPageConfiguration) -> [PSPDFEditingChange]
  • Moves pages at the given page indexes to a new page index.

    Declaration

    Objective-C

    - (nonnull NSArray<PSPDFEditingChange *> *)movePages:
                                                   (nonnull NSIndexSet *)pageIndexes
                                                      to:(NSUInteger)destination;

    Swift

    func movePages(_ pageIndexes: IndexSet, to destination: UInt) -> [PSPDFEditingChange]
  • Removes pages at the given page indexes.

    Declaration

    Objective-C

    - (nonnull NSArray<PSPDFEditingChange *> *)removePages:
        (nonnull NSIndexSet *)pageIndexes;

    Swift

    func removePages(_ pageIndexes: IndexSet) -> [PSPDFEditingChange]
  • Duplicates pages at the given page indexes. The duplicated pages will be inserted exactly after the original page.

    Declaration

    Objective-C

    - (nonnull NSArray<PSPDFEditingChange *> *)duplicatePages:
        (nonnull NSIndexSet *)pageIndexes;

    Swift

    func duplicatePages(_ pageIndexes: IndexSet) -> [PSPDFEditingChange]
  • Rotates the pages with the given page indexes. Rotation can be 0, 90, 180 and 270. Clockwise and counter-clockwise (depending on the sign). The rotation is added to the current page rotation value.

    Declaration

    Objective-C

    - (nonnull NSArray<PSPDFEditingChange *> *)rotatePages:
                                                   (nonnull NSIndexSet *)pageIndexes
                                                  rotation:(NSInteger)rotation;

    Swift

    func rotatePages(_ pageIndexes: IndexSet, rotation: Int) -> [PSPDFEditingChange]
  • Undoes the last action and returns information about what changed.

    Declaration

    Objective-C

    - (nullable NSArray<PSPDFEditingChange *> *)undo;

    Swift

    func undo() -> [PSPDFEditingChange]?
  • Redo the last undo and returns information about what changed.

    Declaration

    Objective-C

    - (nullable NSArray<PSPDFEditingChange *> *)redo;

    Swift

    func redo() -> [PSPDFEditingChange]?
  • Checks if you can redo.

    Declaration

    Objective-C

    @property (readonly, nonatomic) BOOL canRedo;

    Swift

    var canRedo: Bool { get }
  • Checks if you can undo.

    Declaration

    Objective-C

    @property (readonly, nonatomic) BOOL canUndo;

    Swift

    var canUndo: Bool { get }
  • Specifies if it is possible to overwrite the PDF file represented by document by invoking -[PSPDFDocumentEditor save]. Returns YES if the document is backed by a single document provider with a valid and writable file path.

    Declaration

    Objective-C

    @property (readonly, nonatomic) BOOL canSave;

    Swift

    var canSave: Bool { get }
  • Overwrites the document PDF file and clears the document caches. - note: If the PSPDFDocument referenced by document is currently displayed on a PDFViewController, you should call -[PDFViewController reloadData] after saving. - warning: Don’t make any assumptions about the execution context of block. Can be called on a background queue. - parameter: block If successful, returns a reference to the current document with cleared caches. Otherwise an error will be available. - see: canSave

    Declaration

    Objective-C

    - (void)saveWithCompletionBlock:(nullable PSPDFDocumentEditorSaveBlock)block;

    Swift

    func save(completionBlock block: PSPDFDocumentEditorSaveBlock? = nil)

    Parameters

    block

    If successful, returns a reference to the current document with cleared caches. Otherwise an error will be available.

  • Saves the modified document to a new PDF file at path. - note: This does not affect the PSPDFDocument referenced by document. - warning: Don’t make any assumptions about the execution context of block. Can be called on a background queue. - parameter: path The destination path for the new document. Should be a directory to which the application can write to. - parameter: block If successful, returns a new document that is configured for the given path. Otherwise an error will be available.

    Declaration

    Objective-C

    - (void)saveToPath:(nonnull NSString *)path
        withCompletionBlock:(nullable PSPDFDocumentEditorSaveBlock)block;

    Swift

    func save(toPath path: String, withCompletionBlock block: PSPDFDocumentEditorSaveBlock? = nil)

    Parameters

    path

    The destination path for the new document. Should be a directory to which the application can write to.

    block

    If successful, returns a new document that is configured for the given path. Otherwise an error will be available.

  • Saves the pages listed in pageIndexes to a new PDF at path. - note: This does not affect the PSPDFDocument referenced by document. - warning: Don’t make any assumptions about the execution context of block. Can be called on a background queue. - parameter: pageIndexes A set of indexes corresponding to pages that should copied to the new document. All indexes need to be bounded by pageCount. - parameter: path The destination path for the new document. Should be a directory to which the application can write to. - parameter: block If successful, returns a new document that is configured for the given path. Otherwise an error will be available.

    Declaration

    Objective-C

    - (void)exportPages:(nonnull NSIndexSet *)pageIndexes
                     toPath:(nonnull NSString *)path
        withCompletionBlock:(nullable PSPDFDocumentEditorSaveBlock)block;

    Swift

    func exportPages(_ pageIndexes: IndexSet, toPath path: String, withCompletionBlock block: PSPDFDocumentEditorSaveBlock? = nil)

    Parameters

    pageIndexes

    A set of indexes corresponding to pages that should copied to the new document. All indexes need to be bounded by pageCount.

    path

    The destination path for the new document. Should be a directory to which the application can write to.

    block

    If successful, returns a new document that is configured for the given path. Otherwise an error will be available.

  • Returns the rendered page as an UIImage with custom scale.

    Declaration

    Objective-C

    - (nullable UIImage *)imageForPageAtIndex:(NSUInteger)pageIndex
                                         size:(CGSize)size
                                        scale:(CGFloat)scale;

    Swift

    func imageForPage(at pageIndex: UInt, size: CGSize, scale: CGFloat) -> UIImage?