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

PdfProcessor can export pages from one document into another document. You can choose to extract a single page, a range of pages, or even multiple page ranges:

// Page numbers start at 0. This range contains the fifth page of the document.
val task = PdfProcessorTask.fromDocument(document).keepPages(setOf(4))
// Keep pages 5, 6, and 7.
val task = PdfProcessorTask.fromDocument(document).keepPages(setOf(4, 5, 6))
// Remove the first page.
val task = PdfProcessorTask.fromDocument(document).removePages(setOf(0))

After creating PdfProcessorTask, you can start the extraction of the pages by calling the PdfProcessor#processDocumentAsync method or the PdfProcessor#processDocument method. Note that by default, all annotations will be preserved. You can queue multiple operations on a document by calling multiple methods on a PdfProcessorTask object before starting processing. The operations will be executed in the same order as your method calls:

val outputFile = File(getFilesDir(), "extracted-pages.pdf")
// Keep pages 5, 6, and 7.
val task = PdfProcessorTask.fromDocument(document).keepPages(setOf(4, 5, 6))
// The SDK processes the document in the background.
// `lifecycleScope` collects the results on the main thread so we can update the UI.
lifecycleScope.launch {
try {
PdfProcessor.processDocumentAsync(task, outputFile)
.collect { progress: PdfProcessor.ProcessorProgress ->
Toast.makeText(context, "Processing page ${progress.pagesProcessed}/${progress.totalPages}", Toast.LENGTH_SHORT).show()
}
Toast.makeText(context, "Processing has been completed successfully.", Toast.LENGTH_SHORT).show()
} catch (cancellation: CancellationException) {
throw cancellation
} catch (error: Exception) {
Toast.makeText(context, "Processing has failed: ${error.message}", Toast.LENGTH_SHORT).show()
}
}

You can use page extraction to merge pages of two or more documents. All you need to do is load a compound PdfDocument — for example, by using PSPDFKit#openDocuments. Refer to DocumentProcessingExample inside the Catalog app for a demo of this.