Convert images to PDF on iOS

Images are widely used to display content and graphics, but sometimes a PDF format is necessary. Use the Processor API to convert a UIImage into a PDF file with minimal code.

Information

To convert an image to PDF, your license must include the Document Editor component, and to annotate images, your license must include the Image Document component.
Contact our Sales team for assistance.

Converting a single image to a PDF

Follow the steps below to convert an image to a PDF.

The following code sample demonstrates how to convert a single image to a PDF:

let image: UIImage = ...
let outputFileURL: URL = ... // Writable file URL.
let pageTemplate = PageTemplate(pageType: .emptyPage, identifier: nil)
let newPageConfiguration = PDFNewPageConfiguration(pageTemplate: pageTemplate) { builder in
    builder.item = ProcessorItem(image: image, jpegCompressionQuality: 0.7, builderBlock: nil)
    builder.pageSize = image.size
}

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

do {
    try Processor(configuration: configuration, securityOptions: nil).write(toFileURL: outputFileURL)
} catch {
    print("Could not create PDF file: \(error)")
}

Converting multiple images to a PDF

Follow the steps below to convert multiple images to a PDF.

configuration.addNewPage(at: 0, configuration: newPageConfiguration0)
configuration.addNewPage(at: 1, configuration: newPageConfiguration1)
configuration.addNewPage(at: 2, configuration: newPageConfiguration2)
...