PDF Generation

Available on: iOS Android

Overview

Use the PDF generation module after image processing, once you have the image files that should become pages. You can create single-page or multi-page PDFs, include OCR text layout for search, add metadata, protect the document with a password, and control the physical page size.

Basic PDF Creation

At its simplest, PDF generation takes one or more processed image files and writes a PDF to the output path you provide. The page size is expressed in inches; setting width or height to 0 lets the SDK compute that dimension from the image aspect ratio.

import GSSDK

let page1 = GSKPDFPage(
    filePath: "/path/to/image1.jpg",
    inchesSize: GSKPDFSize(width: 8.27, height: 11.69), // A4 size
    textLayout: nil
)

let page2 = GSKPDFPage(
    filePath: "/path/to/image2.jpg",
    inchesSize: GSKPDFSize(width: 8.27, height: 0), // Fit height
    textLayout: nil
)

let document = GSKPDFDocument(
    title: "My Document",
    password: nil,
    keywords: nil,
    creationDate: Date(),
    lastUpdate: Date(),
    pages: [page1, page2]
)

let configuration = GSKDocumentGeneratorConfiguration.pdf(
    outputFilePath: "/path/to/output.pdf"
)

try GSKDocumentGenerator().generate(document, configuration: configuration)
import com.geniusscansdk.pdf.*
import java.io.File

val page1 = PDFPage(
    File("/path/to/image1.jpg"),
    PDFSize(width = 8.27, height = 11.69) // A4 size
)

val page2 = PDFPage(
    File("/path/to/image2.jpg"),
    PDFSize(width = 8.27, height = 0.0) // Fit height
)

val document = PDFDocument(
    pages = listOf(page1, page2),
    title = "My Document",
)

val configuration = DocumentGenerator.Configuration(outputFile)
DocumentGenerator(context).generatePDFDocument(document, configuration)

Searchable PDFs

Create searchable PDFs by including the text layout returned by OCR. The visible page still comes from the processed image, and the text layout adds an invisible text layer that can be searched and selected.

let ocrConfiguration = GSKOCRConfiguration.configuration(languageTags: ["en-US"])
let ocrResult = try await GSKOCR().recognizeText(
    forImageAtPath: imagePath,
    configuration: ocrConfiguration,
    onProgress: nil
)

let page = GSKPDFPage(
    filePath: imagePath,
    inchesSize: GSKPDFSize(width: 8.27, height: 11.69),
    textLayout: ocrResult.textLayout // Makes PDF searchable
)

let document = GSKPDFDocument(
    title: "Searchable Document",
    password: nil,
    keywords: "invoice, 2024",
    creationDate: Date(),
    lastUpdate: Date(),
    pages: [page]
)

let configuration = GSKDocumentGeneratorConfiguration.pdf(outputFilePath: outputPath)
try GSKDocumentGenerator().generate(document, configuration: configuration)
val ocrResult = ocrProcessor.processImage(imageFile)

val page = PDFPage(
    imageFile,
    PDFSize(width = 8.27, height = 11.69),
    ocrResult.textLayout // Makes PDF searchable
)

val document = PDFDocument(
    pages = listOf(page),
    title = "Searchable Document",
)

val configuration = DocumentGenerator.Configuration(outputFile)
DocumentGenerator(context).generatePDFDocument(document, configuration)

PDF Security

Add password protection when the generated document should require a password to open.

let document = GSKPDFDocument(
    title: "Confidential Document",
    password: "SecurePassword123", // User will need this to open PDF
    keywords: nil,
    creationDate: Date(),
    lastUpdate: Date(),
    pages: pages
)

let configuration = GSKDocumentGeneratorConfiguration.pdf(
    outputFilePath: outputPath
)
try GSKDocumentGenerator().generate(document, configuration: configuration)
val document = PDFDocument(
    pages = pages,
    title = "Confidential Document",
    password = "SecurePassword123", // User will need this to open PDF
)

val configuration = DocumentGenerator.Configuration(outputFile)
DocumentGenerator(context).generatePDFDocument(document, configuration)

Metadata and Keywords

Add metadata when downstream systems or document viewers should display a title, dates, or keywords:

let document = GSKPDFDocument(
    title: "Quarterly Financial Report",
    password: nil,
    keywords: "finance, quarterly, 2024, Q4, report",
    creationDate: Date(),
    lastUpdate: Date(),
    pages: pages
)
val document = PDFDocument(
    pages = pages,
    title = "Quarterly Financial Report",
    password = null,
    keywords = "finance, quarterly, 2024, Q4, report"
)

Multi-language Support

By default, PDF generation uses a standard font that supports English and Western European language characters. If you generate a searchable PDF from OCR in another language, specify a font that supports the characters for that language.

Finish the Flow

At this point, the custom integration path is complete: your app can capture and review a document image, process it, optionally run OCR, and generate the final PDF. For complete implementations, compare your code with the native custom demo applications.

Ready to get started?

Start with a free trial license to test the SDK, or contact us directly for a custom quote tailored to your needs.

Products

Industries

Case Studies

Integration

Company

© 2026 The Grizzly Labs. All rights reserved.