Redacting PDFs in Android Viewer

In addition to being able to create redactions programmatically, you can create and customize redactions via the UI PSPDFKit provides.

Adding Redactions

Adding a redaction to a document can be done by selecting the redaction tool on the annotation toolbar. This will enable the redaction mode and allow you to select text by dragging along. A redaction annotation will be created once you lift your finger.

Another way of creating a redaction is by first selecting text and then tapping the redaction item on the menu.

Once a redaction is added to the document, its properties and appearance can be customized via the annotation inspector.

Applying Redactions

Once there are redactions in the document, a floating redaction info button is shown in the user interface view. Tapping this button reveals a UI to apply redactions in the document. Tapping the Apply Redactions button will allow you to overwrite the current document or save the redacted version to a new location and remove the content in the area of the redaction annotations irreversibly. Tapping the Clear Redactions button will remove all redaction annotations. This can be undone using the regular undo button. In the process of redacting the content, all redaction annotations are removed from the document.

Note that when opening a document with existing redactions, there may be a delay before showing the button, since we need to check the document for redactions.

Previewing Redactions

Redactions can be previewed by tapping on the floating redaction info button. When switching the preview mode on, all redaction annotations in a document will be rendered in their redacted state appearance (as opposed to the marked state that is otherwise always shown by default). This can be changed without having any content removed from the document. It’s just for previewing purposes, and the actual removal of the document content will only happen when tapping the Apply Redactions button.

Custom Redaction UI

If you want to customize the UI to preview and apply redactions, you can disable the floating redaction info button in the user interface view via PdfActivityConfiguration.Builder#setRedactionUiEnabled(). Then you can roll your own UI to indicate uncommitted redactions and handle previewing and applying redactions in your own way instead.