---
title: "Generate PDF from template on Android | Nutrient SDK"
canonical_url: "https://www.nutrient.io/guides/android/pdf-generation/from-template/"
md_url: "https://www.nutrient.io/guides/android/pdf-generation/from-template.md"
last_updated: "2026-05-15T19:10:04.912Z"
description: "Nutrient Android SDK enables you to create a new PDF document from a template. Our SDK ships with a predefined list of page patterns."
---

# Generate PDFs from a template on Android

Nutrient Android SDK enables you to create a new PDF document from a template. Our SDK ships with a predefined list of [page patterns](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.document.processor/-page-pattern/index.html).

| Template | [`PagePattern`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.document.processor/-page-pattern/index.html) Constant |
| -------- | -------------------------- |
| Blank    | [`BLANK`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.document.processor/-page-pattern/-b-l-a-n-k.html)                |
| Dots 5mm | [`DOTS_5MM`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.document.processor/-page-pattern/-d-o-t-s_5-m-m.html)             |
| Grid 5mm | [`GRID_5MM`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.document.processor/-page-pattern/-g-r-i-d_5-m-m.html)             |
| Line 5mm | [`LINES_5MM`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.document.processor/-page-pattern/-l-i-n-e-s_5-m-m.html)            |
| Line 7mm | [`LINES_7MM`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.document.processor/-page-pattern/-l-i-n-e-s_7-m-m.html)            |

In addition to these built-in patterns, you can use the [`PagePattern`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.document.processor/-page-pattern/index.html) constructors, which can take either a [`DataProvider`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.document.providers/-data-provider/index.html) or a file [`Uri`](http://developer.android.com/reference/android/net/Uri.html) to build customized page templates from your own PDF documents.

This feature requires the Document Editor component to be enabled in your license.

## The PageTemplate class

[`PageTemplate`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.document.editor.page/-page-template/index.html) has two constructors you can use depending on what you’re trying to achieve:

- [`PageTemplate(PdfDocument sourceDocument, int pageIndex, String templateName, Drawable previewImage)`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.document.editor.page/-page-template/-page-template.html) will instantiate a template that takes the source document’s page at the provided index.

- [`PageTemplate(PagePattern pagePattern, String templateName, Drawable previewImage)`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.document.editor.page/-page-template/-page-template.html) will instantiate a template that’s intended to be used as a tiled pattern. If you want to add a page with a repeating pattern to a document, this is the initializer you’ll use.

> **ℹ️ Note**: Creating a tiled pattern page template requires the source document to be exported correctly. This means that the source PDF needs to contain a pattern itself. If a [`PageTemplate`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.document.editor.page/-page-template/index.html) is instantiated using the tiled pattern initializer and the source document doesn’t contain a pattern, the rendering will fail silently.

Check out [`CustomPageTemplatesExample.java`](https://github.com/PSPDFKit/pspdfkit-android-catalog/blob/9eac1be5767cdeb5a58d879d0749c2338d4f77fb/app/src/main/java/com/pspdfkit/catalog/examples/java/CustomPageTemplatesExample.java) in the [Catalog app](https://github.com/PSPDFKit/pspdfkit-android-catalog) to see [`PageTemplate`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.document.editor.page/-page-template/index.html) in action.

## Custom tiled templates

Many use cases for page templates require the background being tiled (or patterned).

A page is considered tiled if there are one or more images repeated on the page.

For a PDF to be able to work as a source for a tiled page template using [`PageTemplate(PagePattern pagePattern, String templateName, Drawable previewImage)`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.document.editor.page/-page-template/-page-template.html), it has to have actual pattern path information embedded.

To accomplish this, you can use Adobe Illustrator or any other vector editing tool.

When creating your own patterns, consider the following points:

1. What’s rendered on the page is the path information embedded in the PDF and not the actual PDF.

2. If your custom pattern needs certain spacing between tiles, that information needs to be included within the pattern information as well. Currently, there’s no way to specify spacing between tiles from the Nutrient API.

[Click here to download a custom sample template](/assets/images/blog/2018/custom-pdf-page-templates-with-ios/template_sample.pdf).

## Using PageTemplate

Create a [`NewPage`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.document.processor/-new-page/index.html) object using the [`emptyPage`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.document.processor/-new-page/empty-page.html) method of its builder. The [`NewPage.Builder`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.document.processor/-new-page/-builder/index.html) type allows you to customize various properties of the page, such as the background color or page size:

### KOTLIN

```kotlin

// Create a configuration for an empty A4 size page with a white background color.
val newPage = NewPage.emptyPage(NewPage.PAGE_SIZE_A4).backgroundColor(Color.WHITE).build()

```

### JAVA

```java

// Create a configuration for an empty A4 size page with a white background color.
final NewPage newPage = NewPage.emptyPage(NewPage.PAGE_SIZE_A4).backgroundColor(Color.WHITE).build();

```

## Using PdfProcessor

The [`PdfProcessor`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.document.processor/-pdf-processor/index.html) class allows you to use [`PdfProcessorTask`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.document.processor/-pdf-processor-task/index.html)s to perform many types of operations on PDF documents. These operations include document creation, merging, and modification.

After configuring a page as described in the first section, you can create a [`PdfProcessor`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.document.processor/-pdf-processor/index.html) and add the [`NewPage`] to it. Feeding that task into the [`PdfProcessor`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.document.processor/-pdf-processor/index.html) will then generate the actual PDF.

The example below shows how to generate a PDF using the [`PdfProcessor`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.document.processor/-pdf-processor/index.html) API:

### KOTLIN

```kotlin

val outputFile: File =...
val pdfProcessorTask = PdfProcessorTask.newPage(newPage)
val disposable = PdfProcessor.processDocumentAsync(pdfProcessorTask, outputFile).subscribe { progress ->  }

```

### JAVA

```java

final File outputFile =...
final PdfProcessorTask pdfProcessorTask = PdfProcessorTask.newPage(newPage);
final Disposable disposable = PdfProcessor.processDocumentAsync(pdfProcessorTask, outputFile).subscribe(progress -> { });

```
---

## Related pages

- [Generate blank PDFs on Android](/guides/android/features/document-creation.md)
- [Generate PDFs from HTML on Android](/guides/android/pdf-generation/from-html.md)
- [PDF generation library for Android](/guides/android/pdf-generation.md)
- [Effortlessly generate PDFs from images on Android](/guides/android/pdf-generation/from-images.md)
- [Generate PDF reports on Android](/guides/android/generating-pdfs/generating-pdf-reports.md)
- [Generate PDFs programmatically on Android](/guides/android/pdf-generation/programmatically.md)
- [Effortlessly generate PDF thumbnails on Android](/guides/android/pdf-generation/thumbnail-preview.md)

