---
title: "iOS generate PDF from template | Nutrient SDK"
canonical_url: "https://www.nutrient.io/guides/ios/miscellaneous/custom-page-templates/"
md_url: "https://www.nutrient.io/guides/ios/miscellaneous/custom-page-templates.md"
last_updated: "2026-06-19T07:57:11.444Z"
description: "Nutrient iOS SDK enables you to create a new PDF document from a template. Our SDK ships with a predefined list of page templates, which are ready to use:."
---

# Generate PDFs from templates on iOS

Nutrient iOS SDK enables you to create a new PDF document from a template. Our SDK ships with a predefined list of page templates, which are ready to use:

| Template | PageTemplate.Identifier |
| -------- | ----------------------- |
| Blank    | [`.blank`](https://www.nutrient.io/api/ios/documentation/pspdfkit/pagetemplate/identifier-swift.struct/blank)            |
| Dot 5mm  | [`.dot5mm`](https://www.nutrient.io/api/ios/documentation/pspdfkit/pagetemplate/identifier-swift.struct/dot5mm)           |
| Grid 5mm | [`.grid5mm`](https://www.nutrient.io/api/ios/documentation/pspdfkit/pagetemplate/identifier-swift.struct/grid5mm)          |
| Line 5mm | [`.lines5mm`](https://www.nutrient.io/api/ios/documentation/pspdfkit/pagetemplate/identifier-swift.struct/lines5mm)         |
| Line 7mm | [`.lines7mm`](https://www.nutrient.io/api/ios/documentation/pspdfkit/pagetemplate/identifier-swift.struct/lines7mm)         |
| Image    | [`.image`](https://www.nutrient.io/api/ios/documentation/pspdfkit/pagetemplate/identifier-swift.struct/image)            |

In addition to these built-in templates, you can use the [`PageTemplate`](https://www.nutrient.io/api/ios/documentation/pspdfkit/pagetemplate) class 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/ios/documentation/pspdfkit/pagetemplate) has three initializers you can use depending on what you’re trying to achieve:

- [`PageTemplate(document:sourcePageIndex:)`](https://www.nutrient.io/api/ios/documentation/pspdfkit/pagetemplate/init(document:sourcepageindex:)) will instantiate a template that takes the source document’s page at the provided index.

- [`PageTemplate(tiledPatternFrom:sourcePageIndex:)`](https://www.nutrient.io/api/ios/documentation/pspdfkit/pagetemplate/init(tiledpatternfrom:sourcepageindex:)) 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.

- [`PageTemplate(pageType:identifier:)`](https://www.nutrient.io/api/ios/documentation/pspdfkit/pagetemplate/init(pagetype:identifier:)) will instantiate a page template using the provided `PageTemplate.NewPageType` and `PageTemplate.Identifier`. It should be mainly used to create a copy of the existing default templates. For creating a [`.blank`](https://www.nutrient.io/api/ios/documentation/pspdfkit/pagetemplate/identifier-swift.struct/blank) template or an [`.image`](https://www.nutrient.io/api/ios/documentation/pspdfkit/pagetemplate/identifier-swift.struct/image) template, the [`.emptyPage`](https://www.nutrient.io/api/ios/documentation/pspdfkit/pagetemplate/newpagetype/emptypage) page type should be used. For the rest of the default templates, [`.tiledPatternPage`](https://www.nutrient.io/api/ios/documentation/pspdfkit/pagetemplate/newpagetype/tiledpatternpage) should be used.

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/ios/documentation/pspdfkit/pagetemplate) is instantiated using the tiled pattern initializer and the source document doesn’t contain a pattern, the rendering will fail silently.

Check out [`DocumentEditorCustomTemplatesExample.swift`](https://github.com/PSPDFKit/pspdfkit-ios-catalog/blob/master/Catalog/Examples/DocumentEditing/DocumentEditorCustomTemplatesExample.swift) in the [Catalog app](https://www.nutrient.io/guides/ios/getting-started/example-projects.md#nutrient-catalog) to see [`PageTemplate`](https://www.nutrient.io/api/ios/documentation/pspdfkit/pagetemplate) 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 the [new `PageTemplate(tiledPatternFrom:sourcePageIndex:)` API](https://www.nutrient.io/api/ios/documentation/pspdfkit/pagetemplate/init(tiledpatternfrom:sourcepageindex:)), 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 new [`PDFNewPageConfiguration`](https://www.nutrient.io/api/ios/documentation/pspdfkit/pdfnewpageconfiguration) object with a blank [`PageTemplate`](https://www.nutrient.io/api/ios/documentation/pspdfkit/pagetemplate). Use the [`PageTemplate.blank`](https://www.nutrient.io/api/ios/documentation/pspdfkit/pagetemplate/blank) convenience initializer to simplify the code. The builder block of [`PDFNewPageConfiguration`](https://www.nutrient.io/api/ios/documentation/pspdfkit/pdfnewpageconfiguration)’s initializer enables you to customize various properties of the page, such as the background color or page size:

```swift

// Create a configuration for an empty A4 size page with a white background color.
let newPageConfiguration = PDFNewPageConfiguration(pageTemplate: PageTemplate.blank) {
    $0.backgroundColor = UIColor.white
    $0.pageSize = CGSize(width: 595, height: 842) // A4 in points.
}

```

There are two ways to create the PDF document from `newPageConfiguration`: using the [Document Editor](https://www.nutrient.io/guides/ios/features/document-processing.md), or using [`Processor`](https://www.nutrient.io/api/ios/documentation/pspdfkit/processor). Both of them are explained in detail below.

## Using Document Editor

[Document Editor](https://www.nutrient.io/guides/ios/features/document-processing.md) is a Nutrient component comprised of a set of MVC classes. It provides you and your users with a whole host of page editing features, including new page creation, page duplication, copying and pasting, reordering, rotation, deletion, and the creation of new documents from a subset of selected pages.

To create an empty PDF, initialize [`PDFDocumentEditor`](https://www.nutrient.io/api/ios/documentation/pspdfkit/pdfdocumenteditor) without a [`PDFViewController`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller). You can then use the regular [`PDFDocumentEditor`](https://www.nutrient.io/api/ios/documentation/pspdfkit/pdfdocumenteditor) API to add pages. When done, save the new document to a location on the file system:

```swift

guard let documentEditor = PDFDocumentEditor(document: nil) else { return }
documentEditor.addPages(in: NSRange(location: 0, length: 1), with: newPageConfiguration)

// Save to a new PDF file.
documentEditor.save(toPath: saveToPath) { document, error in
    if let error = error {
        print("Error saving document. Error: \(error)")
    }
}

```

## Using Processor

The [`Processor`](https://www.nutrient.io/api/ios/documentation/pspdfkit/processor) class, as the name suggests, allows you to process PDF documents. These operations include document creation, merging, and modification.

After configuring the page as described in the first section, it’s added to [`Processor.Configuration`](https://www.nutrient.io/api/ios/documentation/pspdfkit/processor/configuration), which in turn is used to create a [`Processor`](https://www.nutrient.io/api/ios/documentation/pspdfkit/processor) object that will generate the actual PDF.

The example below shows how to generate a PDF using the [`Processor`](https://www.nutrient.io/api/ios/documentation/pspdfkit/processor) API:

```swift

let configuration = Processor.Configuration()
configuration.addNewPage(at: 0, configuration: newPageConfiguration)

// Save to a new PDF file.
let processor = Processor(configuration: configuration, securityOptions: nil)
try processor.write(toFileURL: outputFileURL)

```

See [`NewDocumentCreationExample`](https://github.com/PSPDFKit/pspdfkit-ios-catalog/blob/master/Catalog/Examples/DocumentProcessing/NewDocumentCreationExample.swift) from the Catalog app for a complete example of how to generate a new PDF.
---

## Related pages

- [Generate PDFs from images on iOS](/guides/ios/pdf-generation/from-images.md)
- [Generate PDFs from HTML on iOS](/guides/ios/pdf-generation/from-html.md)
- [Generate PDFs from a PDF form in iOS](/guides/ios/pdf-generation/from-pdf-form.md)
- [Generate blank PDFs on iOS](/guides/ios/features/document-creation.md)
- [Generate a password-protected PDF on iOS](/guides/ios/pdf-generation/password-protected-pdf.md)
- [PDF generation library for iOS](/guides/ios/pdf-generation.md)
- [Generate PDFs programmatically on iOS](/guides/ios/pdf-generation/programmatically.md)
- [Generate PDF reports on iOS](/guides/ios/generating-pdfs/generating-pdf-reports.md)
- [Generate PDF thumbnails on iOS](/guides/ios/pdf-generation/thumbnail-preview.md)

