---
title: "Generate PDF from template in Flutter | Nutrient SDK"
canonical_url: "https://www.nutrient.io/guides/flutter/pdf-generation/from-template/"
md_url: "https://www.nutrient.io/guides/flutter/pdf-generation/from-template.md"
last_updated: "2026-05-23T00:08:18.095Z"
description: "Nutrient Flutter SDK enables you to create a new PDF document from a template. The template can be a page pattern or a page from an existing PDF document."
---

# Generate a PDF from a template in Flutter

Nutrient Flutter SDK enables you to create a new PDF document from a template. The template can be a [page pattern](https://github.com/PSPDFKit/pspdfkit-flutter/blob/master/lib/src/processor/page_pattern.dart) or a [page from an existing PDF document](https://github.com/PSPDFKit/pspdfkit-flutter/blob/master/lib/src/processor/pdf_page.dart).

## License

To generate a PDF from a template, [contact Sales](https://www.nutrient.io/contact-sales) to add the PDF Generation component to your license.

## Predefined page patterns

The table below summarizes the predefined list of [page patterns](https://github.com/PSPDFKit/pspdfkit-flutter/blob/master/lib/src/processor/page_pattern.dart).

| Template       | Page pattern constant   |
| -------------- | ----------------------- |
| Blank          | `PagePattern.blank`     |
| Dots 5&nbsp;mm | `PagePattern.dots_5mm`  |
| Grid 5&nbsp;mm | `PagePattern.grid_5mm`  |
| Line 5&nbsp;mm | `PagePattern.lines_5mm` |
| Line 7&nbsp;mm | `PagePattern.lines_7mm` |

## Creating custom tiled templates

In addition to using the predefined patterns, you can build customized page templates from your own PDF documents. To do this, use the `PagePattern.fromDocument` method that takes a file URI as its parameter.

Many use cases for page templates require the background to be tiled/patterned. A page is tiled when there are one or more images repeated on the page.

Creating a tiled page template requires the source document to be exported correctly. This means that the source PDF needs to contain a pattern itself. If a [`PagePattern`](https://github.com/PSPDFKit/pspdfkit-flutter/blob/master/lib/src/processor/page_pattern.dart) is instantiated using `PagePattern.fromDocument` and the source document doesn’t contain a pattern, the rendering will fail silently.

To use a PDF as a source for a tiled page template, ensure it has the pattern path information embedded. To do this, use Adobe Illustrator or any other vector editing tool.

When creating your own patterns, consider the following:

- The path information is embedded in the PDF rendered on the page, and not the actual PDF.

- If your custom pattern requires spacing between tiles, include this information in the pattern information.

For testing purposes, use this [sample template](/assets/images/blog/2018/custom-pdf-page-templates-with-ios/template_sample.pdf).

## Generating PDFs from page patterns

To generate a PDF from page patterns, create a [`NewPage` object](https://github.com/PSPDFKit/pspdfkit-flutter/blob/master/lib/src/processor/new_page.dart) with the `NewPage.fromPattern()` method that takes [`PagePattern`](https://github.com/PSPDFKit/pspdfkit-flutter/blob/master/lib/src/processor/page_pattern.dart) as its parameter:

```dart

/// Custom tiled page PDF document.
File patternTilesDocument = File('<readable-tiled-document-path');

String outputPath = '<writable-file-path>';

List<NewPage> pages = [

    // Nutrient predefined patterns.
    NewPage.fromPattern(PagePattern.blank),
    NewPage.fromPattern(PagePattern.grid5mm),
    NewPage.fromPattern(PagePattern.line5mm),
    NewPage.fromPattern(PagePattern.dots5mm),

    // Page from a custom tiled page PDF document.
    NewPage.fromPattern(
        PagePattern.fromDocument(patternTilesDocument.uri, 0)),
];

// Generate PDF from page templates and save it at `[outputPath]`.
var filePath = await Nutrient.generatePdf(pages, outputPath);

```

## Generating PDFs from existing PDF document pages

[`PdfPage`](https://github.com/PSPDFKit/pspdfkit-flutter/blob/master/lib/src/processor/pdf_page.dart) enables you to generate a PDF from existing PDF document pages. This is useful for generating a PDF by merging pages from different PDF document pages.

`PdfPage` is different from the `PagePattern.fromDocument` creation method of the `PagePattern` class. Unlike `PagePattern`, `PdfPage` expects a standard PDF document and a page index for the source document.

To generate a PDF from existing PDF document pages, create a [`NewPage` object](https://github.com/PSPDFKit/pspdfkit-flutter/blob/master/lib/src/processor/new_page.dart) with the `NewPage.fromPdfPage()` method that takes [`PdfPage`](https://github.com/PSPDFKit/pspdfkit-flutter/blob/master/lib/src/processor/pdf_page.dart) as its parameter:

```dart

// Source document file.
File sourceDocument = File('readable-output-path');

String outputPath = '<writable-output-path>';

List<NewPage> pages = [
    // New page from an existing document page.
    NewPage.fromPdfPage(
        PdfPage(
            sourceDocumentUri: sourceDocument.uri,
            pageIndex: 4,
        )
    )
];

var filePath = await Nutrient.generatePdf(pages, outputPath);

```

For more information on generating PDF files from HTML strings and URLs, see the [`Nutrient`](https://pub.dev/documentation/nutrient_flutter/latest/nutrient_flutter/Nutrient-class.html) API reference and the [PDF Generation Example](https://github.com/PSPDFKit/pspdfkit-flutter/blob/master/example/lib/pdf_generation_example.dart) from the [Catalog app](https://github.com/PSPDFKit/pspdfkit-flutter).
---

## Related pages

- [Generate a blank PDF in Flutter](/guides/flutter/pdf-generation/blank-pdf.md)
- [PDF Generation library for Flutter](/guides/flutter/pdf-generation.md)
- [Create PDFs from HTML in Flutter](/guides/flutter/pdf-generation/from-html.md)
- [Generate a PDF from an image in Flutter](/guides/flutter/pdf-generation/from-images.md)

