Export (PDF, TIFF, JPEG, PNG) Pixelnetica™ Document Scanning SDK for Apple iOS

Once a page is cropped, enhanced, and (optionally) recognised, you write it to a file with PxImageWriter. The same API produces single images, multi-page PDFs, and searchable PDFs with an embedded invisible text layer.

Output formats

PxImageWriter_Type selects the format: PxImageWriter_Type_JPEG, PxImageWriter_Type_PNG, PxImageWriter_Type_PNG_EXT, PxImageWriter_Type_TIFF, and PxImageWriter_Type_PDF. PNG, TIFF, and PDF are licensed features.

Write a page

Create a writer for the format, open an output path, write the picture, and close. Engine calls can raise exceptions, so wrap them with PxCatchExceptions:

import DocScanningSDK

let writer = PxImageWriter.new(PxImageWriter_Type_PDF)
var writtenPath: String?
try PxCatchExceptions.do {
    writer.open(outputPath)
    writtenPath = writer.write(picture)   // write throws PxException for license-gated formats
}
writer.close()

Searchable PDF

To embed the OCR result as an invisible, selectable text layer behind the image, pass the page’s PxTextResult to write(_:with:) — the text layer is hidden by default:

let writer = PxImageWriter.new(PxImageWriter_Type_PDF)
var writtenPath: String?
try PxCatchExceptions.do {
    writer.open(outputPath)
    writtenPath = writer.write(picture, with: picture.scanResult)
}
writer.close()

Use setFonts(_:) to supply the fonts for the embedded text layer. See OCR & text recognition for producing the PxTextResult.

Multi-page PDFs

For a multi-page document, open the writer once, write each page, then close — every write call appends a page:

let writer = PxImageWriter.new(PxImageWriter_Type_PDF)
try PxCatchExceptions.do {
    writer.open(outputPath)
    for page in pages { _ = writer.write(page, with: page.scanResult) }
}
writer.close()

Compression

PDF (and TIFF) output is compressed per page. Call setCompressionLevel(_:) before writing, passing one of the PxImageWriter_CompressionLevel presets — or any custom rate >= 1. Higher means a smaller file at lower quality:

let writer = PxImageWriter.new(PxImageWriter_Type_PDF)
writer.setCompressionLevel(Float(PxImageWriter_CompressionLevel_Medium.rawValue))
PresetUse when
PxImageWriter_CompressionLevel_LosslessArchival quality — no quality loss, largest files.
PxImageWriter_CompressionLevel_LowDefault. Balanced size and quality for everyday documents.
PxImageWriter_CompressionLevel_MediumNoticeably smaller, for sharing or upload, with slight quality loss.
PxImageWriter_CompressionLevel_HighAggressive size reduction when storage or bandwidth is tight.
PxImageWriter_CompressionLevel_ExtremeSmallest files, most visible quality loss.

The level tunes the lossy compression of colour and greyscale pages only. Black-and-white pages are always stored losslessly, whatever the level — see Image enhancement. If you never call setCompressionLevel(_:), the writer uses Low.

More controls

  • Paper size & orientation: configure the PDF page geometry with the writer’s paper-configuration API (see PxPaper and the API reference).
  • Footer: add a footer with text (and an optional URL) via the writer’s footer configuration.

Tips

  • Always close() the writer — for PDFs this finalises the file.
  • Confirm the format’s feature is enabled on your license before exporting (PNG / TIFF / PDF are gated).

See also

Top