public interface

PdfDocumentEditor

com.pspdfkit.document.editor.PdfDocumentEditor

Class Overview

Editor for PDF documents. A document editor can perform operations on a PDF document for page manipulation, reordering and importing documents. Document editor won't directly manipulate the returned document instance but will keep track of all editing steps internally, allowing them to save them back once editing is complete. To create a document editor use createForDocument(PdfDocument).

Summary

Public Methods
abstract Single<List<EditingChange>> addPage(int pageIndex, NewPage newPageConfiguration)
Adds a new page at the specified pageIndex, with the configuration options specified in newPageConfiguration.
abstract Single<List<EditingChange>> addPages(int pageIndex, List<NewPage> newPageConfigurations)
Adds a new collection of pages at the specified pageIndex, with the configuration options specified in newPageConfigurations for every page.
abstract void beginTransaction()
Begins a batch of document editor operations, undoable/redoable as a single unit.
abstract boolean canRedo()
Checks if redo operation is possible on document editor.
abstract boolean canUndo()
Checks if undo operation is possible on document editor.
abstract List<EditingChange> commitTransaction()
Ends a batch of document editor operations and commits them immediately.
abstract List<EditingChange> discardTransaction()
Discards the current batch of document operations.
abstract Single<List<EditingChange>> duplicatePages(Set<Integer> pageIndexes)
Duplicates pages of the document.
abstract Completable exportPages(Context context, OutputStream outputStream, Set<Integer> pageIndexes, DocumentSaveOptions options)
Exports selected pages to an output stream.
abstract PdfDocument getDocument()
Returns the original document being edited.
abstract int getPageCount()
Returns the page count of the edited document.
abstract Size getRotatedPageSize(int pageIndex)
Returns page size of a given page already rotated.
abstract Single<List<EditingChange>> importDocument(Context context, DocumentSource documentSource, int destinationIndex)
Imports all the pages from a given document source to a destination index.
abstract boolean isTransactionActive()
Checks if there's currently an active document editor transaction.
abstract Single<List<EditingChange>> movePages(Set<Integer> fromPositions, int toPosition)
Moves a given set of pages of the document to a specific index.
abstract List<EditingChange> redo()
Perform redo changes on document editor.
abstract Single<List<EditingChange>> removePages(Set<Integer> pageIndexes)
Removes pages from the document.
abstract Completable renderPageToBitmap(int pageIndex, Bitmap buffer, PageRenderConfiguration configuration)
Renders the given page into a Bitmap buffer.
abstract Single<List<EditingChange>> rotatePages(Set<Integer> pageIndexes, int rotation)
Rotate pages of the document.
abstract Completable saveDocument(Context context, DocumentSaveOptions options)
Saves all changes made to the document.
abstract Completable saveDocument(Context context, OutputStream outputStream, DocumentSaveOptions options)
Saves all changes made to the document to a given output stream.
abstract void setPageLabel(int pageIndex, String label)
Sets a new page label for the edited document.
abstract List<EditingChange> undo()
Perform undo changes on document editor.

Public Methods

public abstract Single<List<EditingChange>> addPage (int pageIndex, NewPage newPageConfiguration)

Adds a new page at the specified pageIndex, with the configuration options specified in newPageConfiguration.

Scheduler:
addPage(int, NewPage) does not operate by default on a particular Scheduler.

Parameters
pageIndex Index where the new page will be added.
newPageConfiguration Configuration options specified for the new page.
Returns
  • Single emitting a list of editing changes for undo/redo operations. If a batch operation is in progress, the emitted list will be empty and the actual editing change is generated upon committing the batch.

public abstract Single<List<EditingChange>> addPages (int pageIndex, List<NewPage> newPageConfigurations)

Adds a new collection of pages at the specified pageIndex, with the configuration options specified in newPageConfigurations for every page.

Scheduler:
addPage(int, NewPage) does not operate by default on a particular Scheduler.

Parameters
pageIndex Index where the new pages will be added.
newPageConfigurations List of configuration options specified for the new pages.
Returns
  • Single emitting a list of editing changes for undo/redo operations. If a batch operation is in progress, the emitted list will be empty, and the actual editing change is generated upon committing the batch.

public abstract void beginTransaction ()

Begins a batch of document editor operations, undoable/redoable as a single unit.

public abstract boolean canRedo ()

Checks if redo operation is possible on document editor.

Returns
  • true if redo operation is allowed.

public abstract boolean canUndo ()

Checks if undo operation is possible on document editor.

Returns
  • true if undo operation is allowed.

public abstract List<EditingChange> commitTransaction ()

Ends a batch of document editor operations and commits them immediately.

Returns
  • The list of editing changes that have been applied inside the group.

public abstract List<EditingChange> discardTransaction ()

Discards the current batch of document operations.

Returns
  • Current batch of document operation that are being discarded.

public abstract Single<List<EditingChange>> duplicatePages (Set<Integer> pageIndexes)

Duplicates pages of the document. The duplicated pages will be inserted exactly after the original page.

Scheduler:
duplicatePages(Set<Integer>) does not operate by default on a particular Scheduler.

Parameters
pageIndexes Page indexes to duplicate, may not be empty.
Returns
  • Single emitting a list of editing changes for undo/redo operations. If a batch operation is in progress, the emitted list will be empty and the actual editing change is generated upon committing the batch.

public abstract Completable exportPages (Context context, OutputStream outputStream, Set<Integer> pageIndexes, DocumentSaveOptions options)

Exports selected pages to an output stream.

Scheduler:
exportPages(OutputStream, Set<Integer>, DocumentSaveOptions) does not operate by default on a particular Scheduler.

Parameters
context The context to use.
outputStream Output stream where the pages will be exported.
pageIndexes Page indexes to export, may not be empty.
options Document saving options, default saving options will be used when null
Returns
  • Completable that finishes once page exporting is done.

public abstract PdfDocument getDocument ()

Returns the original document being edited.

Returns
  • The original document being edited.

public abstract int getPageCount ()

Returns the page count of the edited document. If a page is added or removed, the count will reflect the change. It will always reflect the number of committed pages in the editor after a call to commitTransaction() if this is called inside a group.

Returns
  • the page count of the edited document.

public abstract Size getRotatedPageSize (int pageIndex)

Returns page size of a given page already rotated.

Parameters
pageIndex Page index whose size will be returned.
Returns
  • Page size of a given page already rotated.

public abstract Single<List<EditingChange>> importDocument (Context context, DocumentSource documentSource, int destinationIndex)

Imports all the pages from a given document source to a destination index.

Scheduler:
importDocument(int, DocumentSource) does not operate by default on a particular Scheduler.

Parameters
context The context to use.
documentSource Document source with the pages to import.
destinationIndex Destination index where the pages will be imported.
Returns
  • Single emitting a list of all editing changes of every page for undo/redo operations. If a batch operation is in progress, the emitted list will be empty and the actual editing change is generated upon committing the batch.

public abstract boolean isTransactionActive ()

Checks if there's currently an active document editor transaction.

Returns
  • true if there's an active document editor transaction, false otherwise.

public abstract Single<List<EditingChange>> movePages (Set<Integer> fromPositions, int toPosition)

Moves a given set of pages of the document to a specific index.

Scheduler:
movePages(Set<Integer>, int) does not operate by default on a particular Scheduler.

Parameters
fromPositions Set of page indexes that will be moved, may not be empty.
toPosition Destination index where the pages will be moved.
Returns
  • Single emitting a list of editing changes for undo/redo operations. If a batch operation is in progress, the emitted list will be empty and the actual editing change is generated upon committing the batch.

public abstract List<EditingChange> redo ()

Perform redo changes on document editor.

Returns
  • List of editing changes for undo/redo operations.

public abstract Single<List<EditingChange>> removePages (Set<Integer> pageIndexes)

Removes pages from the document.

Scheduler:
removePages(Set<Integer>) does not operate by default on a particular Scheduler.

Parameters
pageIndexes Page indexes to remove, may not be empty.
Returns
  • Single emitting a list of editing changes for undo/redo operations. If a batch operation is in progress, the emitted list will be empty and the actual editing change is generated upon committing the batch.

public abstract Completable renderPageToBitmap (int pageIndex, Bitmap buffer, PageRenderConfiguration configuration)

Renders the given page into a Bitmap buffer.

Scheduler:
renderPageToBitmap(int, Bitmap, PageRenderConfiguration) does not operate by default on a particular Scheduler.

Parameters
pageIndex Page index to render.
buffer Bitmap buffer where the given page will be rendered.
configuration Configuration rendering options.
Returns
  • Completable that finishes once the rendering is done.

public abstract Single<List<EditingChange>> rotatePages (Set<Integer> pageIndexes, int rotation)

Rotate pages of the document.

Scheduler:
rotatePages(Set<Integer>, int) does not operate by default on a particular Scheduler.

Parameters
pageIndexes Page indexes to rotate, may not be empty.
rotation One of NO_ROTATION, ROTATION_90, ROTATION_180, ROTATION_270.
Returns
  • Single emitting a list of editing changes for undo/redo operations. If a batch operation is in progress, the emitted list will be empty and the actual editing change is generated upon committing the batch.

public abstract Completable saveDocument (Context context, DocumentSaveOptions options)

Saves all changes made to the document. Saving will start as soon as the Completable is subscribed.

Scheduler:
saveDocument() does not operate by default on a particular Scheduler.

Parameters
context The context to use.
options Document saving options, default saving options will be used when null.
Returns
  • Completable that finishes once the document saving is done.

public abstract Completable saveDocument (Context context, OutputStream outputStream, DocumentSaveOptions options)

Saves all changes made to the document to a given output stream. Saving will start as soon as the Completable is subscribed.

Scheduler:
saveDocument(OutputStream) does not operate by default on a particular Scheduler.

Parameters
context The context to use.
outputStream Destination stream where the document will be saved.
options Document saving options, default saving options will be used when null.
Returns
  • Completable that finishes once the document saving is done.

public abstract void setPageLabel (int pageIndex, String label)

Sets a new page label for the edited document.

Parameters
pageIndex Page index whose label to set.
label Label to set for a given page, null to clear it.

public abstract List<EditingChange> undo ()

Perform undo changes on document editor.

Returns
  • List of editing changes for undo/redo operations.