Class PdfProcessorTask
-
- All Implemented Interfaces:
public final class PdfProcessorTask
Represents a processing task for PdfProcessor.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public enum
PdfProcessorTask.AnnotationProcessingMode
Describes how an annotation will be processed by a processor.
-
Method Summary
Modifier and Type Method Description static PdfProcessorTask
fromDocument(@NonNull() PdfDocument sourceDocument)
Creates a new processing task for the PdfProcessor. static PdfProcessorTask
newPage(@NonNull() NewPage newPage)
Creates a new processing task for creating a new single-page document from scratch. static PdfProcessorTask
empty()
Creates a new empty processing task for the PdfProcessor. PdfProcessorTask
keepPages(@NonNull() Set<Integer> pagesToKeep)
Keeps only passed pages from document. PdfProcessorTask
removePages(@NonNull() Set<Integer> pagesToRemove)
Removes passed pages from document. PdfProcessorTask
movePages(@NonNull() Set<Integer> pagesToMove, @IntRange(from = 0) int destinationIndex)
Moves passed pages to a new index in the document. PdfProcessorTask
stripEmptyPages(boolean stripEmptyPages)
Strip empty pages at the end of processing. PdfProcessorTask
changeAnnotationsOfType(@NonNull() AnnotationType annotationType, @NonNull() PdfProcessorTask.AnnotationProcessingMode processingMode)
Changes all annotation of a certain type according to the passed in processing mode. PdfProcessorTask
changeFormsOfType(@NonNull() FormType formType, @NonNull() PdfProcessorTask.AnnotationProcessingMode processingMode)
Changes all form annotations of a certain type according to the passed in processing mode. PdfProcessorTask
changeAnnotations(@NonNull() List<Annotation> annotations, @NonNull() PdfProcessorTask.AnnotationProcessingMode processingMode)
Changes passed annotations according to passed AnnotationProcessingMode. PdfProcessorTask
changeAllAnnotations(@NonNull() PdfProcessorTask.AnnotationProcessingMode processingMode)
Changes ALL annotations in document according to AnnotationProcessingMode. PdfProcessorTask
addNewPage(@NonNull() NewPage newPage, @IntRange(from = 0) int destinationPageIndex)
Adds a new page to the document at passed index. PdfProcessorTask
setPageBox(@IntRange(from = 0) int pageIndex, @NonNull() PdfBox boxToChange, @NonNull() RectF rectF)
Changes one of the page boxes for the passed page. PdfProcessorTask
rotatePage(@IntRange(from = 0) int pageIndex, @IntRange(from = "-270", to = 270) int rotation)
Rotates the selected page for passed degrees. PdfProcessorTask
resizePage(@IntRange(from = 0) int pageIndex, @NonNull() Size pageSize)
Re-sizes the selected page to pageSize
.PdfProcessorTask
withMetadata(@NonNull() HashMap<String, String> metadata)
Sets metadata for the output document. PdfProcessorTask
addImageToPage(@NonNull() PageImage image, int destinationPageIndex)
Adds an image on top (or below) the destination page content. PdfProcessorTask
addCanvasDrawingToPage(@NonNull() PageCanvas pageCanvas, int destinationPageIndex)
Merges content of canvas drawing on top (or below) the destination page content. PdfProcessorTask
mergePage(@NonNull() PagePdf pagePdf, int destinationPageIndex)
Merges a page with a page of the task's document. 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. PdfProcessorTask
changeStrokeColorOnPage(int pageIndex, @ColorInt() int color)
Adjusts color of all strokes on the given page. PdfProcessorTask
clearPageLabels()
Removes all page labels in the document. PdfProcessorTask
setPageLabel(@IntRange(from = 0) int pageIndex, @Nullable() String label)
Sets a label on the page. PdfProcessorTask
setFormFieldNameMappings(@NonNull() Map<String, String> formFieldNameMappings)
Renames form fields as described in a mapping. PdfProcessorTask
setFormMappingNameMappings(@NonNull() Map<String, String> formMappingNameMappings)
Renames form mapping names as described in this mapping. PdfProcessorTask
applyRedactions()
Applies the redact annotations for the given page index. PdfProcessorTask
performOcrOnPages(@NonNull() Set<Integer> pageIndexes, @NonNull() OcrLanguage ocrLanguage)
Performs optical character recognition on the provided set of pages in the PDF document. -
-
Method Detail
-
fromDocument
@NonNull() static PdfProcessorTask fromDocument(@NonNull() PdfDocument sourceDocument)
Creates a new processing task for the PdfProcessor. By default the processing task copies all pages and all annotations to the destination document.
Note: This call requires document editing feature in your license.
- Parameters:
sourceDocument
- The processed PdfDocument.
-
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.
-
empty
@NonNull() static PdfProcessorTask empty()
Creates a new empty processing task for the PdfProcessor.
Note: This call requires document editing feature in your license.
-
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.- Returns:
Processor task describing the page processing progress.
-
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.- Returns:
Processor task describing the page processing progress.
-
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.- Returns:
Processor task describing the page processing progress.
-
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.- Returns:
Processor task describing the page processing progress.
-
changeAnnotationsOfType
PdfProcessorTask changeAnnotationsOfType(@NonNull() AnnotationType annotationType, @NonNull() PdfProcessorTask.AnnotationProcessingMode processingMode)
Changes all annotation of a certain type according to the passed in processing mode.
- Parameters:
annotationType
- Annotation type to change.processingMode
- AnnotationProcessingMode describing how to change annotations.- Returns:
Processor task describing the page processing progress.
-
changeFormsOfType
PdfProcessorTask changeFormsOfType(@NonNull() FormType formType, @NonNull() PdfProcessorTask.AnnotationProcessingMode processingMode)
Changes all form annotations of a certain type according to the passed in processing mode.
- Parameters:
formType
- Form type to change.processingMode
- AnnotationProcessingMode describing how to change annotations.- Returns:
Processor task describing the page processing progress.
-
changeAnnotations
PdfProcessorTask changeAnnotations(@NonNull() List<Annotation> annotations, @NonNull() PdfProcessorTask.AnnotationProcessingMode processingMode)
Changes passed annotations according to passed AnnotationProcessingMode. By default, all annotations are kept (KEEP).
- Parameters:
annotations
- List of annotations to specify processing mode for.processingMode
- Processing mode for annotations in the list.- Returns:
Processor task describing the page processing progress.
-
changeAllAnnotations
PdfProcessorTask changeAllAnnotations(@NonNull() PdfProcessorTask.AnnotationProcessingMode processingMode)
Changes ALL annotations in document according to AnnotationProcessingMode. By default all annotations are kept (KEEP).
- Parameters:
processingMode
- Processing mode for annotations in the document.- Returns:
Processor task describing the page processing progress.
-
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.- Returns:
Processor task describing the page processing progress.
-
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.- Returns:
Processor task describing the page processing progress.
-
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.- Returns:
Processor task describing the page processing progress.
-
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.- Returns:
Processor task describing the page processing progress.
-
withMetadata
PdfProcessorTask withMetadata(@NonNull() HashMap<String, String> metadata)
Sets metadata for the output document. The set metadata will fully replace any existing metadata.
- Returns:
Processor task describing the page processing progress.
-
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.- Returns:
Processor task describing the page processing progress.
-
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.- Returns:
Processor task describing the page processing progress.
-
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.- Returns:
Processor task describing the page processing progress.
-
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.- Returns:
Processor task describing the page processing progress.
-
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.- Returns:
Processor task describing the page processing progress.
-
clearPageLabels
PdfProcessorTask clearPageLabels()
Removes all page labels in the document.
- Returns:
Processor task describing the page processing progress.
-
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.- Returns:
Processor task describing the page processing progress.
-
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.- Returns:
Processor task describing the page processing progress.
-
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.- Returns:
Processor task describing the page processing progress.
-
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.
- Returns:
Processor task describing processing progress.
-
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.- Returns:
This processor task for configuring processing steps.
-
-
-
-