Class PdfProcessorTask

    • Constructor Detail

    • Method Detail

      • newPage

        @NonNull() static PdfProcessorTask newPage(@NonNull() NewPage newPage)

        Creates a new processing task for creating a new single-page document from scratch.

        Note: This call requires document editing feature in your license.

        Parameters:
        newPage - NewPage options for the first page of the new document.
      • keepPages

         PdfProcessorTask keepPages(@NonNull() Set<Integer> pagesToKeep)

        Keeps only passed pages from document.

        Note: This will shift page indices for any other operation accepting page index as a parameter after this!

        Parameters:
        pagesToKeep - Pages to keep in the document.
      • removePages

         PdfProcessorTask removePages(@NonNull() Set<Integer> pagesToRemove)

        Removes passed pages from document.

        Note: This will shift page indices for any other operation accepting page index as a parameter after this!

        Parameters:
        pagesToRemove - 0-indexed set of page indexes of pages to remove.
      • movePages

         PdfProcessorTask movePages(@NonNull() Set<Integer> pagesToMove, @IntRange(from = 0) int destinationIndex)

        Moves passed pages to a new index in the document. The order of pages in new location is retained.

        Note: This will shift page indices for any other operation accepting page index as a parameter after this!

        Parameters:
        pagesToMove - 0-indexed set of page indexes of pages to remove.
        destinationIndex - Index of position where pages should be moved to in source document.
      • stripEmptyPages

         PdfProcessorTask stripEmptyPages(boolean stripEmptyPages)

        Strip empty pages at the end of processing.

        Parameters:
        stripEmptyPages - true if empty pages should be stripped when writing processed document.
      • addNewPage

         PdfProcessorTask addNewPage(@NonNull() NewPage newPage, @IntRange(from = 0) int destinationPageIndex)

        Adds a new page to the document at passed index.

        Note: This call requires document editing feature in your license.

        Parameters:
        newPage - Configuration setting size and rotation of the new page.
        destinationPageIndex - Page index position of the destination where page should be added.
      • setPageBox

         PdfProcessorTask setPageBox(@IntRange(from = 0) int pageIndex, @NonNull() PdfBox boxToChange, @NonNull() RectF rectF)

        Changes one of the page boxes for the passed page.

        Note: This call requires document editing feature in your license.

        Parameters:
        pageIndex - 0-indexed page index of the page to be rotated.
        boxToChange - Current PDF box to be changed.
        rectF - New box position in PDF coordinates.
      • rotatePage

         PdfProcessorTask rotatePage(@IntRange(from = 0) int pageIndex, @IntRange(from = "-270", to = 270) int rotation)

        Rotates the selected page for passed degrees. The pages can only be rotated for 0, 90, 180 or 270.

        Note: This call requires document editing feature in your license.

        Parameters:
        pageIndex - 0-indexed page index of the page to be rotated.
        rotation - Rotation in degrees.
      • resizePage

         PdfProcessorTask resizePage(@IntRange(from = 0) int pageIndex, @NonNull() Size pageSize)

        Re-sizes the selected page to pageSize. The content of the page will be resized with kept aspect ratio. NOTE: This call requires document editing feature in your license.

        Parameters:
        pageIndex - 0-indexed page index of the page to be rotated.
        pageSize - Size of the scaled page.
      • addImageToPage

         PdfProcessorTask addImageToPage(@NonNull() PageImage image, int destinationPageIndex)

        Adds an image on top (or below) the destination page content.

        Parameters:
        image - Image to be added to the page.
        destinationPageIndex - Page index of page to add image to.
      • addCanvasDrawingToPage

         PdfProcessorTask addCanvasDrawingToPage(@NonNull() PageCanvas pageCanvas, int destinationPageIndex)

        Merges content of canvas drawing on top (or below) the destination page content.

        Parameters:
        pageCanvas - Canvas drawing to be merged.
        destinationPageIndex - Page index of page to add PDF to.
      • mergePage

        @NonNull() PdfProcessorTask mergePage(@NonNull() PagePdf pagePdf, int destinationPageIndex)

        Merges a page with a page of the task's document.

        Parameters:
        pagePdf - PDF page to be merged.
        destinationPageIndex - Index of the destination document's page the source page should be merged into.
      • mergePage

        @NonNull() PdfProcessorTask mergePage(@NonNull() PagePdf pagePdf, int destinationPageIndex, @NonNull() BlendMode blendMode)

        Merges a page with a page of the task's document by using specified BlendMode.

        Note: This call requires document comparison feature in your license.

        Parameters:
        pagePdf - PDF page to be merged.
        destinationPageIndex - Index of the destination document's page the source page should be merged into.
        blendMode - Defines how the two pages should be blended into each other.
      • changeStrokeColorOnPage

        @NonNull() PdfProcessorTask changeStrokeColorOnPage(int pageIndex, @ColorInt() int color)

        Adjusts color of all strokes on the given page.

        Note: This call requires document comparison features in your license.

        Parameters:
        pageIndex - Index of the page, whose stroke color should be changed.
        color - The new color used to change the strokes.
      • setPageLabel

         PdfProcessorTask setPageLabel(@IntRange(from = 0) int pageIndex, @Nullable() String label)

        Sets a label on the page. Most viewers will show the page label instead of its page number in both the document view and table of contents.

        Parameters:
        pageIndex - 0-indexed page index of the page to set the label to.
        label - Label to be set for the page.
      • setFormFieldNameMappings

         PdfProcessorTask setFormFieldNameMappings(@NonNull() Map<String, String> formFieldNameMappings)

        Renames form fields as described in a mapping.

        NOTE: This requires the Document Editor component license to use.

        Parameters:
        formFieldNameMappings - Map of old name - new name pairs for this document.
      • setFormMappingNameMappings

         PdfProcessorTask setFormMappingNameMappings(@NonNull() Map<String, String> formMappingNameMappings)

        Renames form mapping names as described in this mapping.

        NOTE: This requires the Document Editor component license to use.

        Parameters:
        formMappingNameMappings - Map of old name - new name pairs for this document.
      • applyRedactions

         PdfProcessorTask applyRedactions()

        Applies the redact annotations for the given page index. Applying a redact annotation means removing the text that is underneath them, and removing the redact annotations themselves.

        NOTE: This requires the Redaction component license to use.

      • performOcrOnPages

         PdfProcessorTask performOcrOnPages(@NonNull() Set<Integer> pageIndexes, @NonNull() OcrLanguage ocrLanguage)

        Performs optical character recognition on the provided set of pages in the PDF document.

        In order to use this feature, you need to include the PSPDFKit OCR dependencies in your framework. If using Gradle, you can add to your build.gradle file:

        
        final String pspdfkit_version = {@value com.pspdfkit.PSPDFKit#VERSION};
        dependencies {
            // Add the OCR component to your app.
            implementation "com.pspdfkit:pspdfkit-ocr:$pspdfkit_version"
            // Add one or multiple language packs for OCR.
            implementation "com.pspdfkit:pspdfkit-ocr-english:$pspdfkit_version"
        }
        

        NOTE: In order to use this, your license requires to have the OCR component enabled. Also, the language you pass in as a parameter needs to have a respective OCR language pack added to the dependencies. See OcrLanguage for a list of available languages.

        For additional guidance on how to integrate and use OCR inside your app, please visit https://pspdfkit.com/guides/android/current/ocr/getting-started.

        Parameters:
        pageIndexes - Pages that should be used in OCR processing.
        ocrLanguage - OcrLanguage for OCR processing.