Generate Blank PDFs in Android

PSPDFKit can create new blank PDF documents from scratch by using PdfProcessor.

The following example creates a new PdfProcessorTask and passes in a NewPage object. This can define the size of the page, colors, patterns, images, or pages of other documents. After processing, the outputFile will contain the new blank document:

private fun createNewDocument() {
    val outputFile = context.filesDir.resolve("new-document.pdf")

    // Create a new processor task, passing in a new page definition. This can also define colors, images, or pages of other documents.
    val task = PdfProcessorTask.newPage(NewPage.patternPage(NewPage.PAGE_SIZE_A4, PagePattern.LINES_7MM).build())

    // Start document processing, creating a blank file.
    PdfProcessor.processDocument(task, outputFile)
}
private void createNewDocument() {
    final File outputFile = new File(context.getFilesDir(), "new-document.pdf");

    // Create a new processor task, passing in a new page definition. This can also define colors, images, or pages of other documents.
    final PdfProcessorTask task = PdfProcessorTask.newPage(NewPage.patternPage(NewPage.PAGE_SIZE_A4, PagePattern.LINES_7MM).build());

    // Start document processing, creating a blank file.
    PdfProcessor.processDocument(task, outputFile);
}