Skip to content

Swift API Reference

PDF Oxide provides idiomatic Swift bindings over the native C ABI. A CPdfOxide system-library module exposes the cbindgen header via a module map, and PdfOxide is the Swift wrapper. Handles are owned by classes (freed in deinit), returned C strings and buffers are copied into Swift String/[UInt8], and non-success error codes are thrown as PdfOxideError.

// Package.swift
dependencies: [
    .package(url: "https://github.com/yfedoseev/pdf_oxide", from: "0.3.69"),
],
targets: [
    .target(name: "YourTarget", dependencies: [
        .product(name: "PdfOxide", package: "pdf_oxide"),
    ]),
]
import PdfOxide

For the Rust API, see the Rust API Reference. For the Python API, see the Python API Reference. For type details, see Types & Enums.

All page indices are zero-based. Most methods are throws and throw PdfOxideError on a non-success C-ABI error code.


Document

The primary class for opening, extracting, rendering, and inspecting PDF files. Obtain instances via the static open* factory methods.

Opening

static func open(_ path: String) throws -> Document

Open a PDF from a file path.

static func openFromBytes(_ bytes: [UInt8]) throws -> Document

Open a PDF from in-memory bytes (e.g., downloaded from S3 or received over HTTP).

static func openWithPassword(_ path: String, password: String) throws -> Document

Open an encrypted PDF with a user or owner password.

static func openFromDocxBytes(_ bytes: [UInt8]) throws -> Document
static func openFromPptxBytes(_ bytes: [UInt8]) throws -> Document
static func openFromXlsxBytes(_ bytes: [UInt8]) throws -> Document

Convert an Office document (DOCX, PPTX, XLSX) from in-memory bytes into a Document.

func authenticate(_ password: String) throws -> Bool

Authenticate an already-open encrypted document. Returns true on success.

func close()

Free the native handle now (idempotent; also runs in deinit).

Document Info

func pageCount() throws -> Int
func version() throws -> PdfVersion
func isEncrypted() throws -> Bool
func hasStructureTree() throws -> Bool
func hasXfa() throws -> Bool
func page(_ index: Int) -> Page

General document metadata accessors. page(_:) returns a lightweight Page handle for the given index.

Text Extraction

func extractText(_ page: Int) throws -> String

Extract plain text from a single page.

func extractChars(_ pageIndex: Int) throws -> [Char]

Extract per-character positioning and font metadata.

func extractWords(_ pageIndex: Int) throws -> [Word]

Extract words with bounding boxes, font name/size, and bold flag.

func extractTextLines(_ pageIndex: Int) throws -> [TextLine]

Extract text grouped into lines with word counts and bounding boxes.

func extractTables(_ pageIndex: Int) throws -> [Table]

Detect and extract tables with rows, columns, headers, and cell text.

func extractStructuredJson(_ page: Int) throws -> String

Extract a structured JSON representation of a page’s content.

Auto Extraction & Classification

func extractTextAuto(_ pageIndex: Int) throws -> String

Auto-detect the best extraction path and return text for a page.

func extractAllText() throws -> String

Extract text from every page in the document.

func extractPageAuto(_ pageIndex: Int, optionsJson: String = "{}") throws -> String

Auto-extract a page using JSON-configured options.

func classifyPage(_ pageIndex: Int) throws -> String
func classifyDocument() throws -> String

Classify a single page or the whole document (e.g., scanned vs. digital).

Region Extraction

func extractTextInRect(_ pageIndex: Int, x: Float, y: Float, w: Float, h: Float) throws -> String
func extractWordsInRect(_ pageIndex: Int, x: Float, y: Float, w: Float, h: Float) throws -> [Word]
func extractLinesInRect(_ pageIndex: Int, x: Float, y: Float, w: Float, h: Float) throws -> [TextLine]
func extractTablesInRect(_ pageIndex: Int, x: Float, y: Float, w: Float, h: Float) throws -> [Table]
func extractImagesInRect(_ pageIndex: Int, x: Float, y: Float, w: Float, h: Float) throws -> [Image]

Extract content restricted to an (x, y, w, h) rectangle (PDF user-space points, origin bottom-left).

Conversion

func toPlainText(_ page: Int) throws -> String
func toMarkdown(_ page: Int) throws -> String
func toHtml(_ page: Int) throws -> String

Convert a single page to plain text, Markdown, or HTML.

func toPlainTextAll() throws -> String
func toMarkdownAll() throws -> String
func toHtmlAll() throws -> String

Convert all pages to plain text, Markdown, or HTML.

Office Export

func toDocx() throws -> [UInt8]
func toPptx() throws -> [UInt8]
func toXlsx() throws -> [UInt8]

Export the document to DOCX, PPTX, or XLSX bytes.

Images, Fonts & Paths

func embeddedImages(_ pageIndex: Int) throws -> [Image]

Extract embedded raster images (with raw bytes) from a page.

func embeddedFonts(_ pageIndex: Int) throws -> [Font]

List embedded fonts on a page with type, encoding, and subset flags.

func extractPaths(_ pageIndex: Int) throws -> [Path]

Extract vector paths (lines, curves, shapes) from a page.

func fontsToJson(_ pageIndex: Int) throws -> String
func fontSize(_ pageIndex: Int, fontIndex: Int) throws -> Float

Serialize page fonts to JSON, or read a single font’s size.

Annotations

func pageAnnotations(_ pageIndex: Int) throws -> [Annotation]

Extract annotations (type, subtype, content, author, rect) from a page.

func annotationsToJson(_ pageIndex: Int) throws -> String

Serialize a page’s annotations to JSON.

func annotationExtras(_ pageIndex: Int, index: Int) throws -> AnnotationExtras

Read extended annotation attributes (color, dates, flags, URI, icon, quad points).

func search(_ pageIndex: Int, _ term: String, _ caseSensitive: Bool) throws -> [SearchResult]

Search for text on a single page.

func searchAll(_ term: String, _ caseSensitive: Bool) throws -> [SearchResult]

Search for text across the whole document.

func searchResultsToJson(_ pageIndex: Int, _ term: String, caseSensitive: Bool) throws -> String

Search a page and serialize the matches to JSON.

Page Geometry

func pageWidth(_ pageIndex: Int) throws -> Float
func pageHeight(_ pageIndex: Int) throws -> Float
func pageRotation(_ pageIndex: Int) throws -> Int
func pageElements(_ pageIndex: Int) throws -> ElementList

Read page dimensions, rotation, and a generic element list for the page.

Rendering

func renderPage(_ pageIndex: Int, format: Int32 = 0) throws -> RenderedImage

Render a page to a RenderedImage (PNG when format is 0, JPEG when 1).

func renderPageZoom(_ pageIndex: Int, zoom: Float, format: Int32 = 0) throws -> RenderedImage

Render a page at a zoom factor.

func renderPageThumbnail(_ pageIndex: Int, size: Int, format: Int32 = 0) throws -> RenderedImage

Render a thumbnail that fits within size pixels.

func renderPageWithOptions(
    _ pageIndex: Int, dpi: Int32 = 150, format: Int32 = 0,
    bgR: Float = 1, bgG: Float = 1, bgB: Float = 1, bgA: Float = 1,
    transparentBackground: Bool = false, renderAnnotations: Bool = true, jpegQuality: Int32 = 90
) throws -> RenderedImage

Render with the full render-options surface (DPI, background color/alpha, annotations, JPEG quality).

func renderPageWithOptionsEx(
    _ pageIndex: Int, dpi: Int32 = 150, format: Int32 = 0,
    bgR: Float = 1, bgG: Float = 1, bgB: Float = 1, bgA: Float = 1,
    transparentBackground: Bool = false, renderAnnotations: Bool = true,
    jpegQuality: Int32 = 90, excludedLayers: [String] = []
) throws -> RenderedImage

Render with full options plus a list of OCG layer names to suppress.

func renderPageRegion(
    _ pageIndex: Int, cropX: Float, cropY: Float, cropWidth: Float, cropHeight: Float,
    format: Int32 = 0
) throws -> RenderedImage

Render a rectangular region of a page.

func renderPageFit(_ pageIndex: Int, width: Int32, height: Int32, format: Int32 = 0) throws -> RenderedImage

Render a page to fit inside width×height pixels, preserving aspect ratio.

func renderPageRaw(_ pageIndex: Int, dpi: Int32 = 150) throws -> (image: RenderedImage, width: Int, height: Int)

Render to a raw premultiplied RGBA8888 buffer plus the pixel dimensions.

func estimateRenderTime(_ pageIndex: Int) throws -> Int32

Estimate render cost for a page (implementation-defined units).

OCR

func ocrPageNeedsOcr(_ pageIndex: Int) throws -> Bool

Heuristically decide whether a page needs OCR (e.g., a scanned page).

func ocrExtractText(_ pageIndex: Int, engine: OcrEngine? = nil) throws -> String

Extract text via OCR. Pass a custom OcrEngine or nil for the default engine.

Forms

func formFields() throws -> [FormField]

List all form fields with name, value, type, and read-only/required flags.

func exportFormData(formatType: Int32) throws -> [UInt8]

Export form data as FDF/XFDF bytes.

func importFormData(_ dataPath: String) throws -> Int32
func importFormFromFile(_ filename: String) throws -> Bool

Import form data from a file path.

Document Structure

func outline() throws -> String
func pageLabels() throws -> String
func xmpMetadata() throws -> String
func sourceBytes() throws -> [UInt8]
func planSplitByBookmarks(optionsJson: String = "{}") throws -> String

Read the document outline, page labels, XMP metadata, the raw source bytes, or a JSON split plan based on bookmarks.

Content Cleanup

func eraseHeader(_ pageIndex: Int) throws -> Int32
func eraseFooter(_ pageIndex: Int) throws -> Int32
func eraseArtifacts(_ pageIndex: Int) throws -> Int32
func removeHeaders(threshold: Float) throws -> Int32
func removeFooters(threshold: Float) throws -> Int32
func removeArtifacts(threshold: Float) throws -> Int32

Erase headers/footers/artifacts on a single page, or document-wide using a frequency threshold.

Validation

func validatePdfA(_ level: Int32) throws -> PdfAResults
func validatePdfUa(_ level: Int32) throws -> UaResults
func validatePdfX(_ level: Int32) throws -> PdfXResults

Validate the document against PDF/A, PDF/UA, or PDF/X conformance levels.

func convertToPdfA(_ level: Int32) throws -> Bool

Convert the document to PDF/A in place. Returns true on success.

Signatures

func sign(_ certificate: Certificate, reason: String, location: String) throws -> Int32

Sign the document with a certificate, embedding reason and location.

func signatureCount() throws -> Int
func signature(_ index: Int) throws -> SignatureInfo?
func verifyAllSignatures() throws -> Int32
func hasTimestamp() throws -> Bool
func dss() throws -> Dss?

Inspect existing signatures, verify all signatures (1=valid, 0=invalid, -1=unknown), check for a document timestamp, and access the Document Security Store.

Barcodes

func addBarcodeToPage(_ page: Int, _ barcode: BarcodeImage, x: Float, y: Float, width: Float, height: Float) throws

Draw a generated BarcodeImage onto a page at the given position and size.


Page

A lightweight per-page handle returned by Document.page(_:). All accessors dispatch to the parent document.

let index: Int

The zero-based page index.

func text() throws -> String
func markdown() throws -> String
func html() throws -> String
func plainText() throws -> String

Extract the page as plain text, Markdown, or HTML.


Pdf

A class for creating PDFs from source formats and saving them.

Factory Methods

static func fromMarkdown(_ md: String) throws -> Pdf
static func fromHtml(_ html: String) throws -> Pdf
static func fromText(_ text: String) throws -> Pdf

Create a PDF from Markdown, HTML, or plain text.

static func fromImage(_ path: String) throws -> Pdf
static func fromImageBytes(_ bytes: [UInt8]) throws -> Pdf

Create a single-page PDF from an image file or image bytes.

static func fromHtmlCss(html: String, css: String, fontBytes: [UInt8] = []) throws -> Pdf

Create a PDF from HTML + CSS with an optional embedded font.

static func fromHtmlCssWithFonts(html: String, css: String, fonts: [(String, [UInt8])]) throws -> Pdf

Create a PDF from HTML + CSS with multiple named fonts.

Methods

func save(_ path: String) throws
func toBytes() throws -> [UInt8]
func pageCount() throws -> Int
func close()

Save to a file, get the PDF bytes, count pages, or free the handle.


DocumentEditor

A mutable editor for modifying existing PDFs: pages, rotation, geometry, redaction, flattening, forms, merge, and saving.

Opening & Lifecycle

static func openEditor(_ path: String) throws -> DocumentEditor
static func open(_ path: String) throws -> DocumentEditor
static func openFromBytes(_ bytes: [UInt8]) throws -> DocumentEditor
func close()
func free()

Open an editor from a path or bytes, and free the handle when done.

Info & Metadata

func pageCount() throws -> Int
func version() throws -> PdfVersion
func isModified() throws -> Bool
func getSourcePath() throws -> String
func getProducer() throws -> String
func setProducer(_ value: String) throws
func getCreationDate() throws -> String
func setCreationDate(_ date: String) throws

Read document info and get/set the producer and creation date.

Page Operations

func deletePage(_ page: Int) throws
func movePage(_ from: Int, _ to: Int) throws
func rotatePageBy(_ page: Int, _ degrees: Int) throws
func rotateAllPages(_ degrees: Int) throws
func setPageRotation(_ page: Int, _ degrees: Int) throws
func getPageRotation(_ page: Int) throws -> Int

Delete, move, and rotate pages.

Page Geometry

func cropMargins(left: Float, right: Float, top: Float, bottom: Float) throws
func getPageCropBox(_ page: Int) throws -> Bbox
func setPageCropBox(_ page: Int, x: Double, y: Double, width: Double, height: Double) throws
func getPageMediaBox(_ page: Int) throws -> Bbox
func setPageMediaBox(_ page: Int, x: Double, y: Double, width: Double, height: Double) throws

Crop margins and get/set CropBox and MediaBox geometry.

Erase & Redaction

func eraseRegion(_ page: Int, x: Float, y: Float, width: Float, height: Float) throws
func eraseRegions(_ page: Int, _ rects: [(Double, Double, Double, Double)]) throws
func clearEraseRegions(_ page: Int) throws

Queue and clear rectangular erase regions.

func applyAllRedactions() throws
func applyPageRedactions(_ page: Int) throws
func isPageMarkedForRedaction(_ page: Int) throws -> Bool
func unmarkPageForRedaction(_ page: Int) throws

Apply pending redactions and manage per-page redaction marks.

func redactionAdd(_ page: Int, x1: Double, y1: Double, x2: Double, y2: Double, r: Double, g: Double, b: Double) throws
func redactionCount(_ page: Int) throws -> Int
func redactionApply(scrubMetadata: Bool, r: Double, g: Double, b: Double) throws -> Int
func redactionScrubMetadata() throws -> Int

Queue redaction regions, count them, destructively apply them (returns glyphs removed), or scrub metadata/JavaScript/embedded files only.

Flattening

func flattenForms() throws
func flattenFormsOnPage(_ page: Int) throws
func flattenAnnotations(_ page: Int) throws
func flattenAllAnnotations() throws
func flattenWarningsCount() throws -> Int
func flattenWarning(_ index: Int) throws -> String
func isPageMarkedForFlatten(_ page: Int) throws -> Bool
func unmarkPageForFlatten(_ page: Int) throws

Flatten forms and annotations, read flatten warnings, and manage per-page flatten marks.

Forms

func setFormFieldValue(_ name: String, _ value: String) throws
func importFdfBytes(_ data: [UInt8]) throws -> Int32
func importXfdfBytes(_ data: [UInt8]) throws -> Int32

Set a form field value, or import FDF/XFDF data from bytes.

Barcodes

func addBarcodeToPage(_ page: Int, _ barcode: BarcodeImage, x: Float, y: Float, width: Float, height: Float) throws

Draw a generated barcode onto a page.

Document Operations

func mergeFrom(_ sourcePath: String) throws
func mergeFromBytes(_ bytes: [UInt8]) throws
func convertToPdfA(_ level: Int) throws
func embedFile(_ name: String, _ data: [UInt8]) throws
func extractPagesToBytes(_ pages: [Int]) throws -> [UInt8]

Merge another PDF, convert to PDF/A, attach a file, or extract a subset of pages to bytes.

Saving

func save(_ path: String) throws
func saveToBytes() throws -> [UInt8]
func saveToBytesWithOptions(compress: Bool, garbageCollect: Bool, linearize: Bool) throws -> [UInt8]
func saveEncrypted(_ path: String, userPassword: String, ownerPassword: String) throws
func saveEncryptedToBytes(userPassword: String, ownerPassword: String) throws -> [UInt8]

Save to a file or bytes, with optional compression/GC/linearization or AES password encryption.


DocumentBuilder

A fluent builder for creating tagged, multi-page PDFs from scratch. Most methods return self for chaining.

static func create() throws -> DocumentBuilder

Create a new document builder.

Metadata & Structure

func setTitle(_ title: String) throws -> DocumentBuilder
func setAuthor(_ author: String) throws -> DocumentBuilder
func setSubject(_ subject: String) throws -> DocumentBuilder
func setKeywords(_ keywords: String) throws -> DocumentBuilder
func setCreator(_ creator: String) throws -> DocumentBuilder
func onOpen(_ script: String) throws -> DocumentBuilder
func taggedPdfUa1() throws -> DocumentBuilder
func language(_ lang: String) throws -> DocumentBuilder
func roleMap(custom: String, standard: String) throws -> DocumentBuilder
func registerEmbeddedFont(_ name: String, _ font: EmbeddedFont) throws -> DocumentBuilder

Set document metadata, an open-action script, PDF/UA tagging, language, role map, and register embedded fonts.

Pages

func a4Page() throws -> PageBuilder
func letterPage() throws -> PageBuilder
func page(_ width: Float, _ height: Float) throws -> PageBuilder

Start an A4, Letter, or custom-sized page, returning a PageBuilder.

Output

func build() throws -> [UInt8]
func save(_ path: String) throws
func saveEncrypted(_ path: String, userPassword: String, ownerPassword: String) throws
func toBytesEncrypted(userPassword: String, ownerPassword: String) throws -> [UInt8]
func close()

Build to bytes, save to a file, or save with AES encryption.


PageBuilder

A fluent builder for the contents of one page, returned by DocumentBuilder.a4Page() / .letterPage() / .page(_:_:). Most methods return self.

Text & Layout

func font(_ name: String, _ size: Float) throws -> PageBuilder
func at(_ x: Float, _ y: Float) throws -> PageBuilder
func text(_ text: String) throws -> PageBuilder
func heading(_ level: Int, _ text: String) throws -> PageBuilder
func paragraph(_ text: String) throws -> PageBuilder
func space(_ points: Float) throws -> PageBuilder
func horizontalRule() throws -> PageBuilder
func columns(_ columnCount: UInt32, _ gapPt: Float, _ text: String) throws -> PageBuilder
func footnote(_ refMark: String, _ noteText: String) throws -> PageBuilder
func newPageSameSize() throws -> PageBuilder

Set the active font and position, then write text, headings, paragraphs, spacing, rules, multi-column flow, footnotes, or start a same-size page.

Inline Runs

func inline(_ text: String) throws -> PageBuilder
func inlineBold(_ text: String) throws -> PageBuilder
func inlineItalic(_ text: String) throws -> PageBuilder
func inlineColor(_ r: Float, _ g: Float, _ b: Float, _ text: String) throws -> PageBuilder
func newline() throws -> PageBuilder

Append styled inline text runs and line breaks.

func linkUrl(_ url: String) throws -> PageBuilder
func linkPage(_ page: Int) throws -> PageBuilder
func linkNamed(_ destination: String) throws -> PageBuilder
func linkJavascript(_ script: String) throws -> PageBuilder
func onOpen(_ script: String) throws -> PageBuilder
func onClose(_ script: String) throws -> PageBuilder
func fieldKeystroke(_ script: String) throws -> PageBuilder
func fieldFormat(_ script: String) throws -> PageBuilder
func fieldValidate(_ script: String) throws -> PageBuilder
func fieldCalculate(_ script: String) throws -> PageBuilder

Add URL/page/named/JavaScript link annotations and attach page or field-level scripts.

Markup Annotations

func highlight(_ r: Float, _ g: Float, _ b: Float) throws -> PageBuilder
func underline(_ r: Float, _ g: Float, _ b: Float) throws -> PageBuilder
func strikeout(_ r: Float, _ g: Float, _ b: Float) throws -> PageBuilder
func squiggly(_ r: Float, _ g: Float, _ b: Float) throws -> PageBuilder
func stickyNote(_ text: String) throws -> PageBuilder
func stickyNoteAt(_ x: Float, _ y: Float, _ text: String) throws -> PageBuilder
func watermark(_ text: String) throws -> PageBuilder
func watermarkConfidential() throws -> PageBuilder
func watermarkDraft() throws -> PageBuilder
func stamp(_ typeName: String) throws -> PageBuilder
func freetext(_ x: Float, _ y: Float, _ w: Float, _ h: Float, _ text: String) throws -> PageBuilder

Add highlight/underline/strikeout/squiggly markup, sticky notes, watermarks, stamps, and free-text annotations.

Form Fields

func textField(_ name: String, _ x: Float, _ y: Float, _ w: Float, _ h: Float, defaultValue: String? = nil) throws -> PageBuilder
func checkbox(_ name: String, _ x: Float, _ y: Float, _ w: Float, _ h: Float, checked: Bool) throws -> PageBuilder
func pushButton(_ name: String, _ x: Float, _ y: Float, _ w: Float, _ h: Float, _ caption: String) throws -> PageBuilder
func signatureField(_ name: String, _ x: Float, _ y: Float, _ w: Float, _ h: Float) throws -> PageBuilder
func comboBox(_ name: String, _ x: Float, _ y: Float, _ w: Float, _ h: Float, options: [String], selected: String? = nil) throws -> PageBuilder
func radioGroup(_ name: String, values: [String], xs: [Float], ys: [Float], ws: [Float], hs: [Float], selected: String? = nil) throws -> PageBuilder

Add AcroForm text fields, checkboxes, push buttons, signature fields, combo boxes, and radio groups.

Barcodes & Images

func barcode1d(_ barcodeType: Int32, _ data: String, _ x: Float, _ y: Float, _ w: Float, _ h: Float) throws -> PageBuilder
func barcodeQr(_ data: String, _ x: Float, _ y: Float, _ size: Float) throws -> PageBuilder
func image(_ bytes: [UInt8], _ x: Float, _ y: Float, _ w: Float, _ h: Float) throws -> PageBuilder
func imageWithAlt(_ bytes: [UInt8], _ x: Float, _ y: Float, _ w: Float, _ h: Float, altText: String) throws -> PageBuilder
func imageArtifact(_ bytes: [UInt8], _ x: Float, _ y: Float, _ w: Float, _ h: Float) throws -> PageBuilder

Draw 1-D barcodes, QR codes, and images (with optional alt text or artifact tagging).

Vector Graphics

func rect(_ x: Float, _ y: Float, _ w: Float, _ h: Float) throws -> PageBuilder
func filledRect(_ x: Float, _ y: Float, _ w: Float, _ h: Float, _ r: Float, _ g: Float, _ b: Float) throws -> PageBuilder
func line(_ x1: Float, _ y1: Float, _ x2: Float, _ y2: Float) throws -> PageBuilder
func strokeRect(_ x: Float, _ y: Float, _ w: Float, _ h: Float, width: Float, _ r: Float, _ g: Float, _ b: Float) throws -> PageBuilder
func strokeLine(_ x1: Float, _ y1: Float, _ x2: Float, _ y2: Float, width: Float, _ r: Float, _ g: Float, _ b: Float) throws -> PageBuilder
func strokeRectDashed(_ x: Float, _ y: Float, _ w: Float, _ h: Float, width: Float, _ r: Float, _ g: Float, _ b: Float, dashArray: [Float], phase: Float) throws -> PageBuilder
func strokeLineDashed(_ x1: Float, _ y1: Float, _ x2: Float, _ y2: Float, width: Float, _ r: Float, _ g: Float, _ b: Float, dashArray: [Float], phase: Float) throws -> PageBuilder
func textInRect(_ x: Float, _ y: Float, _ w: Float, _ h: Float, _ text: String, align: Int32) throws -> PageBuilder

Draw rectangles, lines, stroked/dashed shapes, and text constrained to a rectangle.

Tables

func table(nColumns: Int, widths: [Float], aligns: [Int32], nRows: Int, cellStrings: [String], hasHeader: Bool) throws -> PageBuilder

Buffer a static table; cellStrings is row-major (row * nColumns + col).

func streamingTableBegin(nColumns: Int, headers: [String], widths: [Float], aligns: [Int32], repeatHeader: Bool) throws -> PageBuilder
func streamingTableBeginV2(nColumns: Int, headers: [String], widths: [Float], aligns: [Int32], repeatHeader: Bool, mode: Int32, sampleRows: Int, minColWidthPt: Float, maxColWidthPt: Float, maxRowspan: Int) throws -> PageBuilder
func streamingTableSetBatchSize(_ batchSize: Int) throws -> PageBuilder
func streamingTablePendingRowCount() throws -> Int
func streamingTableBatchCount() throws -> Int
func streamingTableFlush() throws -> PageBuilder
func streamingTablePushRow(_ cells: [String]) throws -> PageBuilder
func streamingTablePushRowV2(_ cells: [String], rowspans: [Int]?) throws -> PageBuilder
func streamingTableFinish() throws -> PageBuilder

Build large tables incrementally with streaming rows, optional rowspans, batching, and auto-fit modes.

Finishing

func done() throws
func close()

Finish the page and return control to the parent builder.


EmbeddedFont

A font registered with a DocumentBuilder.

static func fromFile(_ path: String) throws -> EmbeddedFont
static func fromBytes(_ bytes: [UInt8], name: String? = nil) throws -> EmbeddedFont
func close()

Load a TrueType/OpenType font from a file or bytes.


BarcodeImage

Generate and inspect 1-D/2-D barcodes.

static func generateQrCode(_ data: String, errorCorrection: Int32 = 1, sizePx: Int32 = 256) throws -> BarcodeImage
static func generateBarcode(_ data: String, format: Int32, sizePx: Int32 = 256) throws -> BarcodeImage

Generate a QR code or a barcode of a given format.

func data() throws -> String
func format() throws -> Int32
func confidence() throws -> Float
func imagePng(sizePx: Int32 = 256) throws -> [UInt8]
func svg(sizePx: Int32 = 256) throws -> String
func close()

Read the decoded payload, format, and confidence, or render the barcode to PNG bytes or an SVG string.


RenderedImage

A rendered page image returned by the Document.renderPage* methods.

let width: Int
let height: Int
let data: [UInt8]
func save(_ path: String) throws
func close()

Pixel dimensions, encoded image bytes, and a helper to save the image to a file.


Renderer

A standalone renderer configuration handle.

static func create(dpi: Int32 = 150, format: Int32 = 0, quality: Int32 = 90, antiAlias: Bool = true) throws -> Renderer
func close()

Create a reusable renderer with DPI, format (0=PNG, 1=JPEG), JPEG quality, and anti-aliasing settings.


OcrEngine

An OCR engine backed by detection/recognition models.

static func create(detModelPath: String, recModelPath: String, dictPath: String) throws -> OcrEngine
func close()

Create an engine from detection model, recognition model, and dictionary paths. Pass it to Document.ocrExtractText(_:engine:).


Certificate

A signing certificate and key.

static func loadFromBytes(_ bytes: [UInt8], password: String) throws -> Certificate
static func loadFromPem(certPem: String, keyPem: String) throws -> Certificate

Load a certificate from PKCS#12 bytes (with password) or from PEM strings.

func subject() throws -> String
func issuer() throws -> String
func serial() throws -> String
func validity() throws -> CertificateValidity
func isValid() throws -> Bool
func close()

Read the subject, issuer, serial, validity window, and current validity.


SignatureInfo

Details of an existing signature, returned by Document.signature(_:).

func signerName() throws -> String
func signingReason() throws -> String
func signingLocation() throws -> String
func signingTime() throws -> Int64
func certificate() throws -> Certificate?
func padesLevel() throws -> Int32
func hasTimestamp() throws -> Bool
func timestamp() throws -> Timestamp?
func addTimestamp(_ ts: Timestamp) throws -> Bool
func verify() throws -> Int32
func verifyDetached(_ pdf: [UInt8]) throws -> Int32
func close()

Read signer metadata, certificate, PAdES level, and timestamp; verify the signature (with an optional detached message-digest check).


Timestamp

An RFC 3161 timestamp token.

static func parse(_ bytes: [UInt8]) throws -> Timestamp
func token() throws -> [UInt8]
func messageImprint() throws -> [UInt8]
func time() throws -> Int64
func serial() throws -> String
func tsaName() throws -> String
func policyOid() throws -> String
func hashAlgorithm() throws -> Int32
func verify() throws -> Bool
func close()

Parse a timestamp token and read its fields, or verify it.


TsaClient

A Time-Stamping Authority client (behind the tsa-client feature).

static func create(url: String, username: String? = nil, password: String? = nil,
                   timeout: Int32 = 30, hashAlgo: Int32 = 0, useNonce: Bool = true, certReq: Bool = true) throws -> TsaClient
func requestTimestamp(_ data: [UInt8]) throws -> Timestamp
func requestTimestampHash(_ hash: [UInt8], hashAlgo: Int32) throws -> Timestamp
func close()

Configure a TSA endpoint and request timestamps over data or a precomputed hash.


Dss

The Document Security Store, returned by Document.dss().

func certCount() throws -> Int
func crlCount() throws -> Int
func ocspCount() throws -> Int
func vriCount() throws -> Int
func cert(_ index: Int) throws -> [UInt8]
func crl(_ index: Int) throws -> [UInt8]
func ocsp(_ index: Int) throws -> [UInt8]
func close()

Count and read the certificates, CRLs, and OCSP responses stored for long-term validation.


PdfAResults / UaResults / PdfXResults

Validation result handles returned by Document.validatePdfA/Ua/X(_:).

// PdfAResults
func isCompliant() throws -> Bool
func errors() throws -> [String]
func warningCount() throws -> Int
func close()

// UaResults
func isAccessible() throws -> Bool
func errors() throws -> [String]
func warnings() throws -> [String]
func stats() throws -> UaStats
func close()

// PdfXResults
func isCompliant() throws -> Bool
func errors() throws -> [String]
func close()

Inspect compliance/accessibility, error and warning lists, and PDF/UA statistics.


ElementList

A generic per-page element list, returned by Document.pageElements(_:).

func count() throws -> Int
func element(_ index: Int) throws -> Element
func all() throws -> [Element]
func toJson() throws -> String
func close()

Iterate page elements (type, text, rect) or serialize them to JSON.


Top-Level Functions

Free functions that operate on raw bytes or global state.

func signBytes(_ pdf: [UInt8], certificate: Certificate, reason: String? = nil, location: String? = nil) throws -> [UInt8]

Sign raw PDF bytes and return the signed PDF.

func signBytesPades(_ pdf: [UInt8], certificate: Certificate, level: Int32,
                    tsaUrl: String? = nil, reason: String? = nil, location: String? = nil,
                    certs: [[UInt8]] = [], crls: [[UInt8]] = [], ocsps: [[UInt8]] = []) throws -> [UInt8]

Sign at a PAdES baseline level (0=B-B, 1=B-T, 2=B-LT) with optional TSA URL and revocation material.

func signBytesPadesOpts(_ pdf: [UInt8], certificate: Certificate, level: Int32,
                        tsaUrl: String? = nil, reason: String? = nil, location: String? = nil,
                        certs: [[UInt8]] = [], crls: [[UInt8]] = [], ocsps: [[UInt8]] = []) throws -> [UInt8]

Struct-options variant of signBytesPades.

func merge(_ paths: [String]) throws -> [UInt8]

Merge the PDFs at paths (in order) into a single in-memory PDF.

func addTimestamp(_ pdfData: [UInt8], sigIndex: Int32, tsaUrl: String) throws -> [UInt8]

Add an RFC 3161 timestamp to a signature and return the re-saved PDF bytes.

func setLogLevel(_ level: Int32)
func getLogLevel() -> Int32

Set or read the global library log level (0=Off … 5=Trace).


PdfOxide (Global Configuration)

The PdfOxide enum namespaces process-wide cryptographic policy, model prefetch, and parser configuration.

static func cryptoActiveProvider() -> String
static func cryptoCbom() -> String
static func cryptoFipsAvailable() -> Int32
static func cryptoInventory() -> String
static func cryptoPolicy() -> String
static func cryptoSetPolicy(_ spec: String) -> Int32
static func cryptoUseFips() -> Int32

Inspect and configure the cryptographic provider, CBOM/inventory, policy, and FIPS mode.

static func modelManifest() -> String
static func prefetchAvailable() -> Int32
static func prefetchModels(languagesCsv: String) throws -> String

Read the OCR model manifest and prefetch models for a comma-separated language list.

static func setMaxOpsPerStream(_ limit: Int64) -> Int64
static func setPreserveUnmappedGlyphs(_ preserve: Int32) -> Int32

Tune parser limits and glyph-mapping behavior.


Value Types

Plain structs returned by extraction methods.

PdfOxideError

struct PdfOxideError: Error, CustomStringConvertible {
    let code: Int32
    let op: String
}

Thrown on any non-success C-ABI error code.

PdfVersion

struct PdfVersion { let major: Int; let minor: Int }

PDF version (e.g. 1.7).

Bbox

struct Bbox { let x: Double; let y: Double; let width: Double; let height: Double }

An axis-aligned bounding box in PDF user-space units.

Char

struct Char { let character: UInt32; let bbox: Bbox; let fontName: String; let fontSize: Double }

A single extracted character (Unicode scalar value).

Word

struct Word { let text: String; let bbox: Bbox; let fontName: String; let fontSize: Double; let bold: Bool }

A single extracted word.

TextLine

struct TextLine { let text: String; let bbox: Bbox; let wordCount: Int }

A single extracted line of text.

Table

struct Table {
    let rowCount: Int
    let colCount: Int
    let hasHeader: Bool
    func cell(_ row: Int, _ col: Int) -> String
}

A single extracted table; cells are read on demand via cell(_:_:).

Font

struct Font { let name: String; let type: String; let encoding: String; let embedded: Bool; let subset: Bool }

An embedded font descriptor.

Image

struct Image {
    let width: Int
    let height: Int
    let bitsPerComponent: Int
    let format: String
    let colorspace: String
    let data: [UInt8]
}

An extracted raster image with its raw bytes.

Annotation

struct Annotation { let type: String; let subtype: String; let content: String; let author: String; let rect: Bbox; let borderWidth: Double }

An annotation’s core attributes.

AnnotationExtras

struct AnnotationExtras {
    let color: UInt32
    let creationDate: Int64
    let modificationDate: Int64
    let hidden: Bool
    let markedDeleted: Bool
    let printable: Bool
    let readOnly: Bool
    let uri: String
    let iconName: String
    let quadPoints: [QuadPoint]
}

Extended annotation attributes from annotationExtras(_:index:).

Path

struct Path { let bbox: Bbox; let strokeWidth: Double; let hasStroke: Bool; let hasFill: Bool; let operationCount: Int }

A vector path’s geometry summary.

SearchResult

struct SearchResult { let text: String; let page: Int; let bbox: Bbox }

A text search match.

FormField

struct FormField { let name: String; let value: String; let type: String; let readonly: Bool; let required: Bool }

A form field descriptor.

QuadPoint

struct QuadPoint { let x1, y1, x2, y2, x3, y3, x4, y4: Double }

A markup-annotation quadrilateral.

Element

struct Element { let type: String; let text: String; let rect: Bbox }

A generic page element from an ElementList.

CertificateValidity

struct CertificateValidity { let notBefore: Int64; let notAfter: Int64 }

A certificate’s validity window (Unix timestamps).

UaStats

struct UaStats { let structElements: Int; let images: Int; let tables: Int; let forms: Int; let annotations: Int; let pages: Int }

PDF/UA structure statistics from UaResults.stats().


Complete Example

import PdfOxide

// --- Extraction ---
let doc = try Document.open("input.pdf")
print("Pages: \(try doc.pageCount())")

for i in 0..<(try doc.pageCount()) {
    let text = try doc.extractText(i)
    print("Page \(i + 1): \(text.count) characters")
}

// Word-level geometry
let words = try doc.extractWords(0)
for w in words.prefix(5) {
    print("'\(w.text)' at \(w.bbox) font=\(w.fontName) size=\(w.fontSize)")
}

// Render the first page to PNG
let image = try doc.renderPage(0, format: 0)
try image.save("page0.png")

// --- Creation (fluent) ---
let builder = try DocumentBuilder.create()
try builder.setTitle("Report")
let page = try builder.letterPage()
try page.at(72, 720).font("Helvetica", 18).heading(1, "Report")
try page.paragraph("Generated by PDF Oxide.")
try page.done()
try builder.save("report.pdf")

// --- Editing ---
let editor = try DocumentEditor.open("document.pdf")
try editor.rotateAllPages(90)
try editor.setFormFieldValue("name", "John Doe")
try editor.mergeFrom("appendix.pdf")
try editor.save("output.pdf")

// --- Signatures ---
let cert = try Certificate.loadFromBytes(p12Bytes, password: "secret")
let signed = try signBytesPades(pdfBytes, certificate: cert, level: 1,
                                tsaUrl: "https://freetsa.org/tsr")

Other Language Bindings

PDF Oxide ships native bindings for every major ecosystem: Rust, Python, Node.js, WASM, C#, Golang, Java, PHP, Ruby, C++, Kotlin, Dart, R, Julia, Zig, Scala, Clojure, Objective-C, and Elixir.

Next Steps