---
title: "iOS generate PDF programmatically | Nutrient SDK"
canonical_url: "https://www.nutrient.io/guides/ios/pdf-generation/programmatically/"
md_url: "https://www.nutrient.io/guides/ios/pdf-generation/programmatically.md"
last_updated: "2026-06-08T09:14:14.409Z"
description: "Nutrient iOS SDK offers several different ways to programmatically create PDF files. Check out the following guides for generating a:."
---

# Generate PDFs programmatically on iOS

Nutrient iOS SDK offers several different ways to programmatically create PDF files. Check out the following guides for generating a:

- [Blank PDF](https://www.nutrient.io/guides/ios/features/document-creation.md)

- [PDF from HTML](https://www.nutrient.io/guides/ios/pdf-generation/from-html.md)

- [PDF from images](https://www.nutrient.io/guides/ios/pdf-generation/from-images.md)

- [PDF from a template](https://www.nutrient.io/guides/ios/miscellaneous/custom-page-templates.md)

- [PDF from a form](https://www.nutrient.io/guides/ios/pdf-generation/from-pdf-form.md)

Optionally, you can also use Apple’s built-in APIs provided by [`UIKit`](https://developer.apple.com/documentation/uikit) to generate a PDF.

## Using UIKit

For maximum flexibility, you can write your own UIKit or Core&nbsp;Graphics drawing code to generate PDFs. You need to take care to correctly handle line and page breaks. This is easiest with the [`UIGraphicsPDFRenderer`](https://developer.apple.com/documentation/uikit/uigraphicspdfrenderer) class introduced in iOS&nbsp;10. The documentation is detailed and has easy-to-understand examples.

Here’s an example of using `UIGraphicsPDFRenderer`:

```swift

import UIKit

let outputFileURL: URL =...

let pdfRenderer = UIGraphicsPDFRenderer(bounds: CGRect(x: 0, y: 0, width: 595, height: 842))

do {
    try pdfRenderer.writePDF(to: outputFileURL) { context in
        context.beginPage()

        let attributes: [NSAttributedString.Key: Any] = [.font : UIFont.systemFont(ofSize: 36, weight:.semibold)
        ]

        let text = "This PDF was made using\na tutorial from Nutrient."

        (text as NSString).draw(at: CGPoint(x: 20, y: 20), withAttributes: attributes)
    }
} catch {
    print("Could not create PDF file: \(error)")
}

```

If you already have a view that draws into a graphics context using Core Graphics or UIKit drawing calls, you can reuse that drawing code.
---

## Related pages

- [Generate blank PDFs on iOS](/guides/ios/features/document-creation.md)
- [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)
- [PDF generation library for iOS](/guides/ios/pdf-generation.md)
- [Generate PDFs from templates on iOS](/guides/ios/miscellaneous/custom-page-templates.md)
- [Generate a password-protected PDF on iOS](/guides/ios/pdf-generation/password-protected-pdf.md)
- [Generate PDF thumbnails on iOS](/guides/ios/pdf-generation/thumbnail-preview.md)
- [Generate PDF reports on iOS](/guides/ios/generating-pdfs/generating-pdf-reports.md)

