---
title: "Generate PDFs from HTML on iOS"
canonical_url: "https://www.nutrient.io/guides/ios/pdf-generation/from-html/"
md_url: "https://www.nutrient.io/guides/ios/pdf-generation/from-html.md"
last_updated: "2026-06-03T21:45:02.503Z"
description: "Learn how to generate PDF files from HTML strings on iOS using a powerful API with both simple and complex HTML support."
---

# Generate PDFs from HTML on iOS

[`Processor`](https://www.nutrient.io/api/ios/documentation/pspdfkit/processor) provides a powerful API for generating PDF files directly from HTML strings. The conversion is fast, but it only supports simple HTML tags, such as `<strong>`, `<a>`, or `<font>`. You can use the following methods for this:

- [`Processor.generatePDF(fromHTMLString:options:completionBlock:)`](https://www.nutrient.io/api/ios/documentation/pspdfkit/processor/generatepdf(fromhtmlstring:options:completionblock:)) — generates a PDF from an HTML string and keeps it in memory

- [`Processor.generatePDF(fromHTMLString:outputFileURL:options:completionBlock:)`](https://www.nutrient.io/api/ios/documentation/pspdfkit/processor/generatepdf(fromhtmlstring:outputfileurl:options:completionblock:)) — generates a PDF from an HTML string and saves it to disk at the provided `outputFileURL`

## Generating PDF files from complex HTML

If you want to generate a PDF file from more complex HTML, you can use another technique — first, save your HTML to a temporary local file, and then generate a PDF file from that URL. Nutrient utilizes the full power of WebKit when generating PDF files from URLs, allowing you to use CSS, embed images, and take advantage of a variety of tags and modern HTML constructs. This is something that isn’t possible with simple HTML-to-PDF conversion.

Using these APIs requires the HTML-to-PDF Conversion component in your license.

```swift

let htmlURL: URL =... // URL to save temporary HTML file to.
let pdfURL: URL =... // URL to save converted PDF file to.

let html = """
<html>
    <head>
        <style type="text/css">
            h1 {
                color: red;
            }
        </style>
    </head>
    <body>
        <h1>Hello, world!</h1>
    </body>
</html>
"""

do {
    try html.data(using:.utf8)!.write(to: htmlURL)
} catch {
    // Handle the error.
}

Processor.generatePDF(from: htmlURL, outputFileURL: pdfURL, options: nil) { outputURL, error in
    if let outputURL = outputURL {
        let document = Document(url: outputURL)
        // Handle the document.
    } else if let error = error {
        // Handle the error.
    }
}

```

Generating PDF files from URLs is a more time- and memory-consuming operation than regular HTML-to-PDF conversion. Make sure to perform the conversion and opt to do simple HTML-to-PDF conversion if possible.

For more details about how to generate PDF files from HTML strings, URLs, and attributed strings, take a look at the [`Processor`] documentation and [`ConvertHTMLToPDFExample`](https://github.com/PSPDFKit/pspdfkit-ios-catalog/blob/master/Catalog/Examples/DocumentGeneration/ConvertHTMLToPDFExample.swift) from our [Catalog app](https://www.nutrient.io/guides/ios/getting-started/example-projects.md#nutrient-catalog).
---

## 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 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 PDFs programmatically on iOS](/guides/ios/pdf-generation/programmatically.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)

