The PDF generation module provides comprehensive functionality for creating professional PDF documents from your processed images. You can generate searchable PDFs with OCR text, add metadata, configure security options, and control page sizing.
Create a simple PDF from scanned images:
import GSSDK
// Create PDF pages from images
let page1 = GSKPDFPage(
filePath: "/path/to/image1.jpg",
inchesSize: GSKPDFSize(width: 8.27, height: 11.69) // A4 size
)
let page2 = GSKPDFPage(
filePath: "/path/to/image2.jpg",
inchesSize: GSKPDFSize(width: 8.27, height: 0) // Fit height
)
// Create PDF document
let document = GSKPDFDocument(
title: "My Document",
password: nil,
keywords: nil,
pages: [page1, page2]
)
// Generate PDF file
let configuration = GSKDocumentGeneratorConfiguration(
outputFilePath: "/path/to/output.pdf"
)
try GSKDocumentGenerator().generate(document, configuration: configuration)
import com.geniusscansdk.pdf.*
// Create PDF pages from images
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) // Fit height
)
// Create PDF document
val document = PDFDocument(
pages = listOf(page1, page2),
title = "My Document",
)
// Generate PDF file
val configuration = DocumentGenerator.Configuration(outputFile)
DocumentGenerator(context).generatePDFDocument(document, configuration)
Create searchable PDFs by including OCR text layout:
// First, perform OCR on the image
let ocrConfiguration = GSKOCRConfiguration.configuration(languageTags: ["en-US"])
let ocrResult = try await GSKOCR.recognizeText(
forImageAtPath: imagePath,
ocrConfiguration: ocrConfiguration,
onProgress: nil
)
// Create page with text layout
let page = GSKPDFPage(
filePath: imagePath,
inchesSize: GSKPDFSize(width: 8.27, height: 11.69),
textLayout: ocrResult.textLayout // Makes PDF searchable
)
// Create and generate PDF
let document = GSKPDFDocument(
title: "Searchable Document",
password: nil,
keywords: ["invoice", "2024"],
pages: [page]
)
let configuration = GSKDocumentGeneratorConfiguration(outputFilePath: outputPath)
try GSKDocumentGenerator().generate(document, configuration: configuration)
// First, perform OCR on the image
val ocrResult = ocrProcessor.processImage(imageFile)
// Create page with text layout
val page = PDFPage(
imageFile,
PDFSize(width = 8.27, height = 11.69),
ocrResult.textLayout // Makes PDF searchable
)
// Create and generate PDF
val document = PDFDocument(
pages = listOf(page),
title = "Searchable Document",
)
val configuration = DocumentGenerator.Configuration(outputFile)
DocumentGenerator(context).generatePDFDocument(document, configuration)
Add password protection to your PDFs:
// Create password-protected PDF
let document = GSKPDFDocument(
title: "Confidential Document",
password: "SecurePassword123", // User will need this to open PDF
keywords: nil,
pages: pages
)
// Generate as usual
let configuration = GSKDocumentGeneratorConfiguration(
outputFilePath: outputPath
)
try GSKDocumentGenerator().generate(document, configuration: configuration)
// Create password-protected PDF
val document = PDFDocument(
pages = pages,
title = "Confidential Document",
password = "SecurePassword123", // User will need this to open PDF
)
// Generate as usual
val configuration = DocumentGenerator.Configuration(outputFile)
DocumentGenerator(context).generatePDFDocument(document, configuration)
Add metadata to make PDFs more discoverable:
let document = GSKPDFDocument(
title: "Q4 2024 Financial Report",
password: nil,
keywords: ["finance", "quarterly", "2024", "Q4", "report"],
pages: pages
)
val document = PDFDocument(
pages = pages,
title = "Q4 2024 Financial Report",
password = null,
keywords = listOf("finance", "quarterly", "2024", "Q4", "report")
)
By default, PDF generation uses a standard font that supports English and Western European language characters. If you perform text recognition for another language, you need to specify a font that supports that language’s characters when generating the PDF document.
You have now learned how to:
This completes the custom integration workflow. For more examples and complete implementations, explore our demo applications or consult the API documentation.
© 2025 The Grizzly Labs. All rights reserved.