This HTML page is not optimized for LLM or AI agent consumption. Fetch the Markdown version instead: /guides/android/features/document-editor.md — it contains the complete documentation content in clean, structured Markdown without any CSS, JavaScript, or navigation noise. Customize PDF editing toolbar on Android | Nutrient SDK

Document Editor offers many document editing features: creating, duplicating, reordering, rotating, and deleting pages, and creating a new document from selected pages.

The editor is integrated with the PdfActivity through the PdfThumbnailGrid, the document overview. To reach it, tap the thumbnail grid item in the main toolbar. The current page shrinks into its thumbnail and the page grid appears. While the grid is open, the main toolbar shows a document editor item (PdfActivity.MENU_OPTION_DOCUMENT_EDITOR, themed by pspdf__documentEditorIcon) beside the grid item. Tap it or long press any page to begin editing. Tapping a thumbnail, the grid item, or Back grows the page back out to the document.

If your license doesn’t enable document editing, the SDK uses the standard PdfThumbnailGrid.

Document editing features

Once editing mode starts, the document editing toolbar shows the editing actions, including an Add Page item for creating new pages. It’s a contextual toolbar like the annotation creation toolbar, and it’s customized the same way; see customizing contextual toolbars.

Toolbar document editor for Android

The following is a list of currently supported editing actions:

  • Reordering pages via drag and drop
  • Page rotation 90 degrees clockwise
  • Duplication of pages
  • Deletion of existing pages
  • Multiselection of pages
  • Full undo/redo support and discarding of all changes
  • Saving changes back to the original document
  • Saving changes to a given destination
  • Exporting selected pages into a new document
  • Importing a new document selected from the device storage

When saving changes to a destination or exporting selected pages into a new document, Document Editor opens the Storage Access Framework file picker by default. You select the destination file there. To modify the default behavior with a custom file picker, use com.pspdfkit.ui.PdfThumbnailGrid#setFilePicker(FilePicker).

Page rotation, duplication, and deletion are also possible when selecting multiple pages.

val documentEditor = PdfDocumentEditorFactory.createForDocument(document)
PdfDocumentEditor documentEditor = PdfDocumentEditorFactory.createForDocument(document)

Transactions

Transactions manage batches of operations as single units. A transaction is a change that occurred because of an operation performed by the Document Editor that can be undone/redone. The kind of operation performed is specified in EditingOperation and may be one of the following: REMOVE, MOVE, INSERT, or ROTATE.

Creating new pages

While in editing mode, the Add Page item in the document editing toolbar adds a new page. By default, tapping it displays the NewPageDialog, where you configure the new page (various page patterns, background colors, page sizes, and landscape or portrait orientation). Programmatically, PdfThumbnailGrid#createNewPage() does the same and is what the item calls; it does nothing while editing mode isn’t active.

New page factories

Document Editor will add NewPage instances it receives from the set NewPageFactory. You can set a factory by calling PdfThumbnailGrid#setNewPageFactory. Here are the existing factories:

val factory = ValueNewPageFactory(NewPage.emptyPage(NewPage.PAGE_SIZE_A4).build())
thumbnailGrid.setNewPageFactory(factory)

Custom page templates

To define the page templates the NewPageDialog offers, pass a list of PageTemplate instances when calling NewPageDialog.show(). Inside Document Editor (i.e. when using the PdfThumbnailGrid), you can pass over the list of page templates to the used DialogNewPageFactory:

// Load a page template from a PDF file.
val pageIndex = 8
val template = PageTemplate(
PdfDocumentLoader.openDocument(this, DocumentSource(AssetDataProvider("Guide-v4.pdf"))),
pageIndex,
getString(R.string.page_template_title),
ContextCompat.getDrawable(this, R.drawable.page_template_preview)
))
// Set up the Document Editor to show the desired list of page templates.
thumbnailGrid.setNewPageFactory(DialogNewPageFactory(
supportFragmentManager,
null,
listOf(template)
))

If you want to see a runnable example for custom page templates, check out CustomPageTemplatesExample in our Catalog app.

Document Editor toolbar

The document editing toolbar is a Jetpack Compose contextual toolbar. In PdfActivity and PdfUiFragment, it mounts automatically when editing mode starts. You customize it through the ToolbarCoordinator. Observe it with addContextualToolbarChangeListener (its kind is ContextualToolbarKind.DocumentEditing) and change its items with updateContextualItems. Handle taps with addActionListener, and dock it with setContextualToolbarPosition. Customizing contextual toolbars walks through each of these:

val coordinator = nutrientToolbarCoordinator()
coordinator.addContextualToolbarChangeListener { state ->
if (state?.kind == ContextualToolbarKind.DocumentEditing) {
// Remove the import item, for example.
coordinator.updateContextualItems { items ->
items.removeAll { it.id == R.id.pspdf__document_editing_toolbar_item_import_document }
}
}
}

Entering editing mode from your own UI

A PdfThumbnailGrid hosted outside PdfActivity has no toolbar item to enter editing, so call the grid’s methods from your own controls:

thumbnailGrid.enterDocumentEditingMode()
if (thumbnailGrid.isDocumentEditingModeActive) thumbnailGrid.createNewPage()
thumbnailGrid.exitDocumentEditingMode()

To replace the toolbar with a UI of your own, register an OnDocumentEditingModeChangeListener through addOnDocumentEditingModeChangeListener() on the grid’s document editing manager. Your listener receives the DocumentEditingController when editing starts and ends, and drives the editing operations on it:

thumbnailGrid.documentEditingManager.addOnDocumentEditingModeChangeListener(object : OnDocumentEditingModeChangeListener {
override fun onEnterDocumentEditingMode(controller: DocumentEditingController) { showMyEditingBar(controller) }
override fun onExitDocumentEditingMode(controller: DocumentEditingController) { hideMyEditingBar() }
})

PdfThumbnailGrid.addOnDocumentEditingModeChangeListener() and PdfThumbnailGrid.addOnDocumentEditingPageSelectionChangeListener() are convenience wrappers around that manager.

The page grid

The grid itself is rendered in Jetpack Compose, and PdfThumbnailGrid keeps its RelativeLayout base and its pspdf__ThumbnailGrid theme attributes. The view with the ID pspdf__thumbnail_grid_recycler_view still exists, and you can reposition it with RelativeLayout rules. Adding a view to the grid and placing the content below it keeps working. The view with that ID is a ComposeView, though: cast it to View, never to RecyclerView. Reordering pages by drag creates a single undo step. In PdfActivity, the grid opens with the zoom transition described above. A grid that doesn’t cover the document, such as a drawer in a custom layout, fades in and out instead.

Leaving the editor with unsaved page edits offers Save, Discard Changes, and Cancel.