Interface PdfDocumentEditor

  • All Implemented Interfaces:

    
    public interface PdfDocumentEditor
    
                        

    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.

    • Constructor Detail

    • Method Detail

      • getDocument

        @NonNull() abstract PdfDocument getDocument()

        Returns the original document being edited.

        Returns:

        The original document being edited.

      • saveDocument

        @NonNull() abstract Completable saveDocument(@NonNull() Context context, @Nullable() 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.

      • saveDocument

        @NonNull() abstract Completable saveDocument(@NonNull() Context context, @NonNull() OutputStream outputStream, @Nullable() 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 .
        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.

      • exportPages

        @NonNull() abstract Completable exportPages(@NonNull() Context context, @NonNull() OutputStream outputStream, @NonNull() Set<Integer> pageIndexes, @Nullable() 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.

      • addPage

        @NonNull() abstract Single<List<EditingChange>> addPage(@IntRange(from = 0) int pageIndex, @NonNull() 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 .
        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.

      • addPages

        @NonNull() abstract Single<List<EditingChange>> addPages(@IntRange(from = 0) int pageIndex, @NonNull() 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 .
        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.

      • removePages

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

        Removes pages from the document.

        • Scheduler:
        • removePages(Set<Integer>) does not operate by default on a particular .
        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.

      • rotatePages

        @NonNull() abstract Single<List<EditingChange>> rotatePages(@NonNull() 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.

      • duplicatePages

        @NonNull() abstract Single<List<EditingChange>> duplicatePages(@NonNull() 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 .
        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.

      • movePages

        @NonNull() abstract Single<List<EditingChange>> movePages(@NonNull() Set<Integer> fromPositions, @IntRange(from = 0) 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 .
        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.

      • importDocument

        @NonNull() abstract Single<List<EditingChange>> importDocument(@NonNull() Context context, @NonNull() DocumentSource documentSource, @IntRange(from = 0) 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.

      • canUndo

         abstract boolean canUndo()

        Checks if undo operation is possible on document editor.

        Returns:

        true if undo operation is allowed.

      • canRedo

         abstract boolean canRedo()

        Checks if redo operation is possible on document editor.

        Returns:

        true if redo operation is allowed.

      • undo

        @NonNull() abstract List<EditingChange> undo()

        Perform undo changes on document editor.

        Returns:

        List of editing changes for undo/redo operations.

      • redo

        @NonNull() abstract List<EditingChange> redo()

        Perform redo changes on document editor.

        Returns:

        List of editing changes for undo/redo operations.

      • getPageCount

        @IntRange(from = 0) 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.

      • getRotatedPageSize

        @NonNull() abstract Size getRotatedPageSize(@IntRange(from = 0) 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.

      • renderPageToBitmap

        @NonNull() abstract Completable renderPageToBitmap(@IntRange(from = 0) int pageIndex, @NonNull() Bitmap buffer, @NonNull() 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.

      • setPageLabel

         abstract void setPageLabel(@IntRange(from = 0) int pageIndex, @Nullable() 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.
      • beginTransaction

         abstract void beginTransaction()

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

      • isTransactionActive

         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.

      • commitTransaction

        @NonNull() 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.