Skip to content

Swift-API-Referenz

PDF Oxide stellt idiomatische Swift-Bindings über die native C-ABI bereit. Ein CPdfOxide-Systembibliotheksmodul macht den cbindgen-Header über eine Module Map verfügbar, und PdfOxide ist der Swift-Wrapper. Handles gehören zu Klassen (in deinit freigegeben), zurückgegebene C-Strings und -Buffer werden in Swift-String/[UInt8] kopiert, und Fehlercodes außer „Erfolg" werden als PdfOxideError geworfen.

// 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

Zur Rust-API siehe die Rust-API-Referenz. Zur Python-API siehe die Python-API-Referenz. Für Details zu den Typen siehe Typen & Enums.

Alle Seitenindizes sind nullbasiert. Die meisten Methoden sind throws und werfen bei einem C-ABI-Fehlercode außer „Erfolg" ein PdfOxideError.


Document

Die zentrale Klasse zum Öffnen, Extrahieren, Rendern und Inspizieren von PDF-Dateien. Instanzen erhalten Sie über die statischen open*-Factory-Methoden.

Öffnen

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

Ein PDF aus einem Dateipfad öffnen.

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

Ein PDF aus Bytes im Arbeitsspeicher öffnen (z. B. von S3 heruntergeladen oder über HTTP empfangen).

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

Ein verschlüsseltes PDF mit einem Benutzer- oder Eigentümerpasswort öffnen.

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

Ein Office-Dokument (DOCX, PPTX, XLSX) aus Bytes im Arbeitsspeicher in ein Document umwandeln.

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

Ein bereits geöffnetes, verschlüsseltes Dokument authentifizieren. Gibt bei Erfolg true zurück.

func close()

Das native Handle sofort freigeben (idempotent; läuft auch in deinit).

Dokumentinformationen

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

Allgemeine Accessoren für Dokumentmetadaten. page(_:) gibt ein leichtgewichtiges Page-Handle für den angegebenen Index zurück.

Textextraktion

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

Reinen Text aus einer einzelnen Seite extrahieren.

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

Zeichenweise Positionierung und Font-Metadaten extrahieren.

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

Wörter mit Bounding-Boxen, Font-Name/-Größe und Fett-Flag extrahieren.

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

Text gruppiert in Zeilen mit Wortzahlen und Bounding-Boxen extrahieren.

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

Tabellen mit Zeilen, Spalten, Kopfzeilen und Zellentext erkennen und extrahieren.

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

Eine strukturierte JSON-Darstellung des Seiteninhalts extrahieren.

Auto-Extraktion & Klassifizierung

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

Den besten Extraktionspfad automatisch erkennen und den Text für eine Seite zurückgeben.

func extractAllText() throws -> String

Text aus jeder Seite des Dokuments extrahieren.

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

Eine Seite mit per JSON konfigurierten Optionen automatisch extrahieren.

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

Eine einzelne Seite oder das gesamte Dokument klassifizieren (z. B. gescannt vs. digital).

Bereichsextraktion

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]

Inhalt extrahieren, der auf ein (x, y, w, h)-Rechteck beschränkt ist (PDF-User-Space-Punkte, Ursprung unten links).

Konvertierung

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

Eine einzelne Seite in reinen Text, Markdown oder HTML konvertieren.

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

Alle Seiten in reinen Text, Markdown oder HTML konvertieren.

Office-Export

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

Das Dokument als DOCX-, PPTX- oder XLSX-Bytes exportieren.

Bilder, Fonts & Pfade

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

Eingebettete Rasterbilder (mit Rohbytes) aus einer Seite extrahieren.

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

Eingebettete Fonts einer Seite mit Typ, Encoding und Subset-Flags auflisten.

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

Vektorpfade (Linien, Kurven, Formen) aus einer Seite extrahieren.

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

Seiten-Fonts nach JSON serialisieren oder die Größe eines einzelnen Fonts auslesen.

Annotationen

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

Annotationen (Typ, Subtyp, Inhalt, Autor, Rechteck) aus einer Seite extrahieren.

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

Die Annotationen einer Seite nach JSON serialisieren.

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

Erweiterte Annotationsattribute auslesen (Farbe, Daten, Flags, URI, Symbol, Quad-Points).

Suche

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

Nach Text auf einer einzelnen Seite suchen.

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

Im gesamten Dokument nach Text suchen.

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

Eine Seite durchsuchen und die Treffer nach JSON serialisieren.

Seitengeometrie

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

Seitenabmessungen, Rotation und eine generische Elementliste der Seite auslesen.

Rendering

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

Eine Seite zu einem RenderedImage rendern (PNG, wenn format 0 ist, JPEG bei 1).

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

Eine Seite mit einem Zoomfaktor rendern.

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

Ein Thumbnail rendern, das innerhalb von size Pixeln passt.

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

Mit der vollständigen Render-Optionen-Oberfläche rendern (DPI, Hintergrundfarbe/-alpha, Annotationen, JPEG-Qualität).

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

Mit vollständigen Optionen plus einer Liste von OCG-Layer-Namen rendern, die unterdrückt werden sollen.

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

Einen rechteckigen Bereich einer Seite rendern.

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

Eine Seite so rendern, dass sie unter Beibehaltung des Seitenverhältnisses in width×height Pixel passt.

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

In einen rohen, premultiplizierten RGBA8888-Buffer plus die Pixelabmessungen rendern.

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

Den Renderaufwand für eine Seite schätzen (implementierungsspezifische Einheiten).

OCR

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

Heuristisch entscheiden, ob eine Seite OCR benötigt (z. B. eine gescannte Seite).

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

Text per OCR extrahieren. Übergeben Sie eine eigene OcrEngine oder nil für die Standard-Engine.

Formulare

func formFields() throws -> [FormField]

Alle Formularfelder mit Name, Wert, Typ und Schreibgeschützt-/Pflicht-Flags auflisten.

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

Formulardaten als FDF/XFDF-Bytes exportieren.

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

Formulardaten aus einem Dateipfad importieren.

Dokumentstruktur

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

Die Dokumentgliederung, Seitenbeschriftungen, XMP-Metadaten, die rohen Quellbytes oder einen JSON-Split-Plan auf Basis von Lesezeichen auslesen.

Inhaltsbereinigung

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

Kopf-/Fußzeilen/Artefakte auf einer einzelnen Seite löschen oder dokumentweit anhand eines Häufigkeitsschwellenwerts.

Validierung

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

Das Dokument gegen die Konformitätsstufen PDF/A, PDF/UA oder PDF/X validieren.

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

Das Dokument an Ort und Stelle in PDF/A konvertieren. Gibt bei Erfolg true zurück.

Signaturen

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

Das Dokument mit einem Zertifikat signieren und Grund und Ort einbetten.

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

Bestehende Signaturen inspizieren, alle Signaturen verifizieren (1=gültig, 0=ungültig, -1=unbekannt), auf einen Dokument-Zeitstempel prüfen und auf den Document Security Store zugreifen.

Barcodes

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

Ein generiertes BarcodeImage an der angegebenen Position und Größe auf eine Seite zeichnen.


Page

Ein leichtgewichtiges Seiten-Handle, das von Document.page(_:) zurückgegeben wird. Alle Accessoren delegieren an das übergeordnete Dokument.

let index: Int

Der nullbasierte Seitenindex.

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

Die Seite als reinen Text, Markdown oder HTML extrahieren.


Pdf

Eine Klasse zum Erstellen von PDFs aus Quellformaten und zum Speichern.

Factory-Methoden

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

Ein PDF aus Markdown, HTML oder reinem Text erstellen.

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

Ein einseitiges PDF aus einer Bilddatei oder Bildbytes erstellen.

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

Ein PDF aus HTML + CSS mit einem optionalen eingebetteten Font erstellen.

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

Ein PDF aus HTML + CSS mit mehreren benannten Fonts erstellen.

Methoden

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

In einer Datei speichern, die PDF-Bytes abrufen, Seiten zählen oder das Handle freigeben.


DocumentEditor

Ein veränderbarer Editor zum Modifizieren bestehender PDFs: Seiten, Rotation, Geometrie, Redaktion, Flattening, Formulare, Zusammenführung und Speichern.

Öffnen & Lebenszyklus

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()

Einen Editor aus einem Pfad oder aus Bytes öffnen und das Handle nach Gebrauch freigeben.

Info & Metadaten

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

Dokumentinformationen auslesen und Producer und Erstellungsdatum lesen/setzen.

Seitenoperationen

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

Seiten löschen, verschieben und drehen.

Seitengeometrie

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

Ränder beschneiden und CropBox- und MediaBox-Geometrie lesen/setzen.

Löschen & Redaktion

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

Rechteckige Löschbereiche in die Warteschlange stellen und leeren.

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

Ausstehende Redaktionen anwenden und seitenweise Redaktionsmarkierungen verwalten.

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

Redaktionsbereiche in die Warteschlange stellen, sie zählen, destruktiv anwenden (gibt die Anzahl entfernter Glyphen zurück) oder nur Metadaten/JavaScript/eingebettete Dateien bereinigen.

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

Formulare und Annotationen flatten, Flatten-Warnungen auslesen und seitenweise Flatten-Markierungen verwalten.

Formulare

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

Einen Formularfeldwert setzen oder FDF/XFDF-Daten aus Bytes importieren.

Barcodes

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

Einen generierten Barcode auf eine Seite zeichnen.

Dokumentoperationen

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]

Ein anderes PDF zusammenführen, in PDF/A konvertieren, eine Datei anhängen oder eine Teilmenge von Seiten als Bytes extrahieren.

Speichern

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]

In eine Datei oder in Bytes speichern, mit optionaler Komprimierung/GC/Linearisierung oder AES-Passwortverschlüsselung.


DocumentBuilder

Ein Fluent-Builder zum Erstellen getaggter, mehrseitiger PDFs von Grund auf. Die meisten Methoden geben für Chaining self zurück.

static func create() throws -> DocumentBuilder

Einen neuen Document-Builder erstellen.

Metadaten & Struktur

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

Dokumentmetadaten, ein Open-Action-Skript, PDF/UA-Tagging, Sprache, Role-Map setzen und eingebettete Fonts registrieren.

Seiten

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

Eine A4-, Letter- oder benutzerdefiniert dimensionierte Seite beginnen und einen PageBuilder zurückgeben.

Ausgabe

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()

In Bytes bauen, in einer Datei speichern oder mit AES-Verschlüsselung speichern.


PageBuilder

Ein Fluent-Builder für den Inhalt einer Seite, zurückgegeben von DocumentBuilder.a4Page() / .letterPage() / .page(_:_:). Die meisten Methoden geben self zurück.

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

Den aktiven Font und die Position setzen, dann Text, Überschriften, Absätze, Abstände, Linien, mehrspaltigen Fluss, Fußnoten schreiben oder eine gleich große Seite beginnen.

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

Formatierte Inline-Text-Runs und Zeilenumbrüche anhängen.

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

URL-/Seiten-/benannte/JavaScript-Link-Annotationen hinzufügen und seiten- oder feldbezogene Skripte anhängen.

Markup-Annotationen

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

Highlight-/Unterstreichungs-/Durchstreichungs-/Wellenlinien-Markup, Haftnotizen, Wasserzeichen, Stempel und Freitext-Annotationen hinzufügen.

Formularfelder

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

AcroForm-Textfelder, Checkboxen, Push-Buttons, Signaturfelder, Combo-Boxen und Radio-Gruppen hinzufügen.

Barcodes & Bilder

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

1-D-Barcodes, QR-Codes und Bilder zeichnen (mit optionalem Alt-Text oder Artefakt-Tagging).

Vektorgrafik

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

Rechtecke, Linien, gestrichene/gestrichelte Formen und auf ein Rechteck beschränkten Text zeichnen.

Tabellen

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

Eine statische Tabelle puffern; cellStrings ist zeilenweise angeordnet (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

Große Tabellen inkrementell mit gestreamten Zeilen, optionalen Rowspans, Batching und Auto-Fit-Modi aufbauen.

Abschluss

func done() throws
func close()

Die Seite abschließen und die Kontrolle an den übergeordneten Builder zurückgeben.


EmbeddedFont

Ein bei einem DocumentBuilder registrierter Font.

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

Einen TrueType-/OpenType-Font aus einer Datei oder aus Bytes laden.


BarcodeImage

1-D-/2-D-Barcodes generieren und inspizieren.

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

Einen QR-Code oder einen Barcode eines bestimmten Formats generieren.

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()

Die dekodierte Payload, das Format und die Konfidenz auslesen oder den Barcode als PNG-Bytes oder SVG-String rendern.


RenderedImage

Ein gerendertes Seitenbild, das von den Document.renderPage*-Methoden zurückgegeben wird.

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

Pixelabmessungen, kodierte Bildbytes und ein Helfer zum Speichern des Bildes in einer Datei.


Renderer

Ein eigenständiges Renderer-Konfigurations-Handle.

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

Einen wiederverwendbaren Renderer mit DPI, Format (0=PNG, 1=JPEG), JPEG-Qualität und Anti-Aliasing-Einstellungen erstellen.


OcrEngine

Eine OCR-Engine, die von Erkennungs-/Klassifizierungsmodellen gestützt wird.

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

Eine Engine aus Detektionsmodell-, Erkennungsmodell- und Wörterbuchpfaden erstellen. Übergeben Sie sie an Document.ocrExtractText(_:engine:).


Certificate

Ein Signaturzertifikat und -schlüssel.

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

Ein Zertifikat aus PKCS#12-Bytes (mit Passwort) oder aus PEM-Strings laden.

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

Subject, Issuer, Seriennummer, Gültigkeitszeitraum und die aktuelle Gültigkeit auslesen.


SignatureInfo

Details einer bestehenden Signatur, zurückgegeben von 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()

Unterzeichner-Metadaten, Zertifikat, PAdES-Level und Zeitstempel auslesen; die Signatur verifizieren (mit einer optionalen Detached-Message-Digest-Prüfung).


Timestamp

Ein RFC-3161-Zeitstempel-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()

Ein Zeitstempel-Token parsen und seine Felder auslesen oder es verifizieren.


TsaClient

Ein Client für eine Zeitstempelstelle (Time-Stamping Authority, hinter dem 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()

Einen TSA-Endpunkt konfigurieren und Zeitstempel über Daten oder einen vorberechneten Hash anfordern.


Dss

Der Document Security Store, zurückgegeben von 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()

Die für die Langzeitvalidierung gespeicherten Zertifikate, CRLs und OCSP-Antworten zählen und auslesen.


PdfAResults / UaResults / PdfXResults

Validierungsergebnis-Handles, zurückgegeben von 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()

Konformität/Barrierefreiheit, Fehler- und Warnlisten sowie PDF/UA-Statistiken inspizieren.


ElementList

Eine generische seitenweise Elementliste, zurückgegeben von Document.pageElements(_:).

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

Über Seitenelemente iterieren (Typ, Text, Rechteck) oder sie nach JSON serialisieren.


Funktionen auf oberster Ebene

Freie Funktionen, die auf rohen Bytes oder globalem Zustand operieren.

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

Rohe PDF-Bytes signieren und das signierte PDF zurückgeben.

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]

Auf einem PAdES-Baseline-Level signieren (0=B-B, 1=B-T, 2=B-LT) mit optionaler TSA-URL und Sperrmaterial.

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-Variante von signBytesPades.

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

Die PDFs unter paths (in Reihenfolge) zu einem einzigen PDF im Arbeitsspeicher zusammenführen.

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

Einen RFC-3161-Zeitstempel zu einer Signatur hinzufügen und die neu gespeicherten PDF-Bytes zurückgeben.

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

Das globale Log-Level der Bibliothek setzen oder auslesen (0=Aus … 5=Trace).


PdfOxide (Globale Konfiguration)

Das PdfOxide-Enum bündelt prozessweite kryptografische Richtlinien, Modell-Prefetch und Parser-Konfiguration unter einem Namespace.

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

Den kryptografischen Provider, CBOM/Inventar, die Richtlinie und den FIPS-Modus inspizieren und konfigurieren.

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

Das OCR-Modell-Manifest auslesen und Modelle für eine kommagetrennte Sprachliste vorab abrufen.

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

Parser-Limits und das Glyph-Mapping-Verhalten anpassen.


Wertetypen

Einfache Structs, die von Extraktionsmethoden zurückgegeben werden.

PdfOxideError

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

Wird bei jedem C-ABI-Fehlercode außer „Erfolg" geworfen.

PdfVersion

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

PDF-Version (z. B. 1.7).

Bbox

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

Eine achsenparallele Bounding-Box in PDF-User-Space-Einheiten.

Char

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

Ein einzelnes extrahiertes Zeichen (Unicode-Skalarwert).

Word

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

Ein einzelnes extrahiertes Wort.

TextLine

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

Eine einzelne extrahierte Textzeile.

Table

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

Eine einzelne extrahierte Tabelle; Zellen werden bei Bedarf über cell(_:_:) ausgelesen.

Font

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

Ein Deskriptor für einen eingebetteten Font.

Image

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

Ein extrahiertes Rasterbild mit seinen Rohbytes.

Annotation

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

Die Kernattribute einer Annotation.

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]
}

Erweiterte Annotationsattribute aus annotationExtras(_:index:).

Path

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

Eine geometrische Zusammenfassung eines Vektorpfads.

SearchResult

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

Ein Treffer der Textsuche.

FormField

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

Ein Formularfeld-Deskriptor.

QuadPoint

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

Ein Viereck einer Markup-Annotation.

Element

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

Ein generisches Seitenelement aus einer ElementList.

CertificateValidity

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

Der Gültigkeitszeitraum eines Zertifikats (Unix-Zeitstempel).

UaStats

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

PDF/UA-Strukturstatistiken aus UaResults.stats().


Vollständiges Beispiel

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 bietet native Bindings für jedes wichtige Ökosystem: Rust, Python, Node.js, WASM, C#, Golang, Java, PHP, Ruby, C++, Kotlin, Dart, R, Julia, Zig, Scala, Clojure, Objective-C und Elixir.

Nächste Schritte