Swift API リファレンス
PDF Oxide は、ネイティブな C ABI の上に構築された慣用的な Swift バインディングを提供します。CPdfOxide システムライブラリモジュールがモジュールマップ経由で cbindgen 製ヘッダーを公開し、PdfOxide がその Swift ラッパーになります。ハンドルはクラスが所有し(deinit で解放されます)、返却された C 文字列やバッファは Swift の String / [UInt8] へコピーされ、非成功のエラーコードは 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
Rust API については Rust API リファレンス を参照してください。Python API については Python API リファレンス を参照してください。型の詳細については 型と列挙型 を参照してください。
すべてのページインデックスは 0 始まりです。ほとんどのメソッドは throws であり、非成功の C-ABI エラーコードが返されると PdfOxideError をスローします。
Document
PDF ファイルを開き、抽出・レンダリング・検査するための中心的なクラスです。インスタンスは静的な open* ファクトリメソッドから取得します。
開く
static func open(_ path: String) throws -> Document
ファイルパスから PDF を開きます。
static func openFromBytes(_ bytes: [UInt8]) throws -> Document
メモリ上のバイト列(例: S3 からダウンロードしたり HTTP で受信したもの)から PDF を開きます。
static func openWithPassword(_ path: String, password: String) throws -> Document
ユーザーパスワードまたはオーナーパスワードで暗号化された PDF を開きます。
static func openFromDocxBytes(_ bytes: [UInt8]) throws -> Document
static func openFromPptxBytes(_ bytes: [UInt8]) throws -> Document
static func openFromXlsxBytes(_ bytes: [UInt8]) throws -> Document
Office ドキュメント(DOCX、PPTX、XLSX)をメモリ上のバイト列から Document へ変換します。
func authenticate(_ password: String) throws -> Bool
すでに開いている暗号化済みドキュメントを認証します。成功時に true を返します。
func close()
ネイティブハンドルを直ちに解放します(冪等で、deinit でも実行されます)。
ドキュメント情報
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
汎用的なドキュメントメタデータのアクセサです。page(_:) は指定インデックスに対応する軽量な Page ハンドルを返します。
テキスト抽出
func extractText(_ page: Int) throws -> String
1 ページ分のプレーンテキストを抽出します。
func extractChars(_ pageIndex: Int) throws -> [Char]
1 文字ごとの位置情報とフォントメタデータを抽出します。
func extractWords(_ pageIndex: Int) throws -> [Word]
バウンディングボックス、フォント名・サイズ、太字フラグ付きで単語を抽出します。
func extractTextLines(_ pageIndex: Int) throws -> [TextLine]
単語数とバウンディングボックスを伴う行単位にまとめたテキストを抽出します。
func extractTables(_ pageIndex: Int) throws -> [Table]
行・列・ヘッダー・セルテキストを伴うテーブルを検出して抽出します。
func extractStructuredJson(_ page: Int) throws -> String
ページコンテンツの構造化 JSON 表現を抽出します。
自動抽出と分類
func extractTextAuto(_ pageIndex: Int) throws -> String
最適な抽出パスを自動判定し、ページのテキストを返します。
func extractAllText() throws -> String
ドキュメント内のすべてのページからテキストを抽出します。
func extractPageAuto(_ pageIndex: Int, optionsJson: String = "{}") throws -> String
JSON で指定したオプションを使ってページを自動抽出します。
func classifyPage(_ pageIndex: Int) throws -> String
func classifyDocument() throws -> String
単一ページまたはドキュメント全体を分類します(例: スキャン文書かデジタル文書か)。
領域抽出
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]
(x, y, w, h) の矩形(PDF ユーザー空間のポイント単位、原点は左下)に限定してコンテンツを抽出します。
変換
func toPlainText(_ page: Int) throws -> String
func toMarkdown(_ page: Int) throws -> String
func toHtml(_ page: Int) throws -> String
1 ページをプレーンテキスト、Markdown、または HTML に変換します。
func toPlainTextAll() throws -> String
func toMarkdownAll() throws -> String
func toHtmlAll() throws -> String
全ページをプレーンテキスト、Markdown、または HTML に変換します。
Office へのエクスポート
func toDocx() throws -> [UInt8]
func toPptx() throws -> [UInt8]
func toXlsx() throws -> [UInt8]
ドキュメントを DOCX、PPTX、または XLSX のバイト列にエクスポートします。
画像・フォント・パス
func embeddedImages(_ pageIndex: Int) throws -> [Image]
ページから埋め込みラスター画像を(生のバイト列とともに)抽出します。
func embeddedFonts(_ pageIndex: Int) throws -> [Font]
ページ上の埋め込みフォントを、種別・エンコーディング・サブセットフラグ付きで列挙します。
func extractPaths(_ pageIndex: Int) throws -> [Path]
ページからベクターパス(線・曲線・図形)を抽出します。
func fontsToJson(_ pageIndex: Int) throws -> String
func fontSize(_ pageIndex: Int, fontIndex: Int) throws -> Float
ページのフォントを JSON にシリアライズするか、単一フォントのサイズを読み取ります。
注釈
func pageAnnotations(_ pageIndex: Int) throws -> [Annotation]
ページから注釈(種別、サブタイプ、内容、作成者、矩形)を抽出します。
func annotationsToJson(_ pageIndex: Int) throws -> String
ページの注釈を JSON にシリアライズします。
func annotationExtras(_ pageIndex: Int, index: Int) throws -> AnnotationExtras
注釈の拡張属性(色、日付、フラグ、URI、アイコン、クアッドポイント)を読み取ります。
検索
func search(_ pageIndex: Int, _ term: String, _ caseSensitive: Bool) throws -> [SearchResult]
単一ページ内でテキストを検索します。
func searchAll(_ term: String, _ caseSensitive: Bool) throws -> [SearchResult]
ドキュメント全体でテキストを検索します。
func searchResultsToJson(_ pageIndex: Int, _ term: String, caseSensitive: Bool) throws -> String
ページを検索し、一致結果を JSON にシリアライズします。
ページのジオメトリ
func pageWidth(_ pageIndex: Int) throws -> Float
func pageHeight(_ pageIndex: Int) throws -> Float
func pageRotation(_ pageIndex: Int) throws -> Int
func pageElements(_ pageIndex: Int) throws -> ElementList
ページの寸法、回転、およびそのページの汎用要素リストを読み取ります。
レンダリング
func renderPage(_ pageIndex: Int, format: Int32 = 0) throws -> RenderedImage
ページを RenderedImage にレンダリングします(format が 0 の場合は PNG、1 の場合は JPEG)。
func renderPageZoom(_ pageIndex: Int, zoom: Float, format: Int32 = 0) throws -> RenderedImage
ページを指定したズーム倍率でレンダリングします。
func renderPageThumbnail(_ pageIndex: Int, size: Int, format: Int32 = 0) throws -> RenderedImage
size ピクセル内に収まるサムネイルをレンダリングします。
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
レンダリングオプションのフルセット(DPI、背景色・アルファ、注釈、JPEG 品質)を指定してレンダリングします。
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
フルオプションに加えて、非表示にする OCG レイヤー名のリストを指定してレンダリングします。
func renderPageRegion(
_ pageIndex: Int, cropX: Float, cropY: Float, cropWidth: Float, cropHeight: Float,
format: Int32 = 0
) throws -> RenderedImage
ページの矩形領域をレンダリングします。
func renderPageFit(_ pageIndex: Int, width: Int32, height: Int32, format: Int32 = 0) throws -> RenderedImage
アスペクト比を維持しつつ、width×height ピクセル内に収まるようにページをレンダリングします。
func renderPageRaw(_ pageIndex: Int, dpi: Int32 = 150) throws -> (image: RenderedImage, width: Int, height: Int)
生のプリマルチプライド RGBA8888 バッファとピクセル寸法にレンダリングします。
func estimateRenderTime(_ pageIndex: Int) throws -> Int32
ページのレンダリングコストを見積もります(単位は実装依存)。
OCR
func ocrPageNeedsOcr(_ pageIndex: Int) throws -> Bool
ページに OCR が必要かどうか(例: スキャンページかどうか)をヒューリスティックに判定します。
func ocrExtractText(_ pageIndex: Int, engine: OcrEngine? = nil) throws -> String
OCR でテキストを抽出します。カスタムの OcrEngine を渡すか、デフォルトエンジンを使う場合は nil を渡します。
フォーム
func formFields() throws -> [FormField]
すべてのフォームフィールドを、名前・値・種別・読み取り専用/必須フラグ付きで列挙します。
func exportFormData(formatType: Int32) throws -> [UInt8]
フォームデータを FDF/XFDF のバイト列としてエクスポートします。
func importFormData(_ dataPath: String) throws -> Int32
func importFormFromFile(_ filename: String) throws -> Bool
ファイルパスからフォームデータをインポートします。
ドキュメント構造
func outline() throws -> String
func pageLabels() throws -> String
func xmpMetadata() throws -> String
func sourceBytes() throws -> [UInt8]
func planSplitByBookmarks(optionsJson: String = "{}") throws -> String
ドキュメントのアウトライン、ページラベル、XMP メタデータ、生のソースバイト列、またはブックマークに基づく JSON 分割プランを読み取ります。
コンテンツのクリーンアップ
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
単一ページのヘッダー/フッター/アーティファクトを消去するか、出現頻度のしきい値を使ってドキュメント全体から消去します。
検証
func validatePdfA(_ level: Int32) throws -> PdfAResults
func validatePdfUa(_ level: Int32) throws -> UaResults
func validatePdfX(_ level: Int32) throws -> PdfXResults
ドキュメントを PDF/A、PDF/UA、または PDF/X の適合レベルに対して検証します。
func convertToPdfA(_ level: Int32) throws -> Bool
ドキュメントをその場で PDF/A に変換します。成功時に true を返します。
署名
func sign(_ certificate: Certificate, reason: String, location: String) throws -> Int32
証明書でドキュメントに署名し、理由と場所を埋め込みます。
func signatureCount() throws -> Int
func signature(_ index: Int) throws -> SignatureInfo?
func verifyAllSignatures() throws -> Int32
func hasTimestamp() throws -> Bool
func dss() throws -> Dss?
既存の署名を検査し、すべての署名を検証し(1=有効、0=無効、-1=不明)、ドキュメントタイムスタンプの有無を確認し、Document Security Store にアクセスします。
バーコード
func addBarcodeToPage(_ page: Int, _ barcode: BarcodeImage, x: Float, y: Float, width: Float, height: Float) throws
生成済みの BarcodeImage を、指定した位置とサイズでページ上に描画します。
Page
Document.page(_:) から返される、ページ単位の軽量ハンドルです。すべてのアクセサは親ドキュメントへディスパッチされます。
let index: Int
0 始まりのページインデックスです。
func text() throws -> String
func markdown() throws -> String
func html() throws -> String
func plainText() throws -> String
ページをプレーンテキスト、Markdown、または HTML として抽出します。
ソース形式から PDF を作成し、保存するためのクラスです。
ファクトリメソッド
static func fromMarkdown(_ md: String) throws -> Pdf
static func fromHtml(_ html: String) throws -> Pdf
static func fromText(_ text: String) throws -> Pdf
Markdown、HTML、またはプレーンテキストから PDF を作成します。
static func fromImage(_ path: String) throws -> Pdf
static func fromImageBytes(_ bytes: [UInt8]) throws -> Pdf
画像ファイルまたは画像バイト列から 1 ページの PDF を作成します。
static func fromHtmlCss(html: String, css: String, fontBytes: [UInt8] = []) throws -> Pdf
HTML + CSS から、任意の埋め込みフォントを伴って PDF を作成します。
static func fromHtmlCssWithFonts(html: String, css: String, fonts: [(String, [UInt8])]) throws -> Pdf
HTML + CSS から、複数の名前付きフォントを伴って PDF を作成します。
メソッド
func save(_ path: String) throws
func toBytes() throws -> [UInt8]
func pageCount() throws -> Int
func close()
ファイルへの保存、PDF バイト列の取得、ページ数のカウント、またはハンドルの解放を行います。
DocumentEditor
既存 PDF を変更するためのミュータブルなエディタです。ページ、回転、ジオメトリ、墨消し、フラット化、フォーム、結合、保存に対応します。
開く・ライフサイクル
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()
パスまたはバイト列からエディタを開き、完了したらハンドルを解放します。
情報とメタデータ
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
ドキュメント情報を読み取り、プロデューサーと作成日時を取得・設定します。
ページ操作
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
ページの削除、移動、回転を行います。
ページのジオメトリ
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
余白をトリミングし、CropBox と MediaBox のジオメトリを取得・設定します。
消去と墨消し
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
矩形の消去領域をキューに追加・クリアします。
func applyAllRedactions() throws
func applyPageRedactions(_ page: Int) throws
func isPageMarkedForRedaction(_ page: Int) throws -> Bool
func unmarkPageForRedaction(_ page: Int) throws
保留中の墨消しを適用し、ページ単位の墨消しマークを管理します。
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
墨消し領域をキューに追加し、その数を数え、破壊的に適用し(除去されたグリフ数を返します)、またはメタデータ/JavaScript/埋め込みファイルのみをスクラブします。
フラット化
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
フォームと注釈をフラット化し、フラット化の警告を読み取り、ページ単位のフラット化マークを管理します。
フォーム
func setFormFieldValue(_ name: String, _ value: String) throws
func importFdfBytes(_ data: [UInt8]) throws -> Int32
func importXfdfBytes(_ data: [UInt8]) throws -> Int32
フォームフィールドの値を設定するか、FDF/XFDF データをバイト列からインポートします。
バーコード
func addBarcodeToPage(_ page: Int, _ barcode: BarcodeImage, x: Float, y: Float, width: Float, height: Float) throws
生成済みのバーコードをページ上に描画します。
ドキュメント操作
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]
別の PDF を結合し、PDF/A に変換し、ファイルを添付し、またはページのサブセットをバイト列として抽出します。
保存
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]
ファイルまたはバイト列に保存します。任意で圧縮/GC/線形化、または AES パスワード暗号化を指定できます。
DocumentBuilder
タグ付きの複数ページ PDF をゼロから作成するための流れるようなビルダーです。ほとんどのメソッドはチェーン用に self を返します。
static func create() throws -> DocumentBuilder
新しいドキュメントビルダーを作成します。
メタデータと構造
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
ドキュメントメタデータ、open-action スクリプト、PDF/UA タグ付け、言語、ロールマップを設定し、埋め込みフォントを登録します。
ページ
func a4Page() throws -> PageBuilder
func letterPage() throws -> PageBuilder
func page(_ width: Float, _ height: Float) throws -> PageBuilder
A4、Letter、または任意サイズのページを開始し、PageBuilder を返します。
出力
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()
バイト列へビルドする、ファイルへ保存する、または AES 暗号化付きで保存します。
PageBuilder
1 ページ分の内容を構築する流れるようなビルダーで、DocumentBuilder.a4Page() / .letterPage() / .page(_:_:) から返されます。ほとんどのメソッドは self を返します。
テキストとレイアウト
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
アクティブなフォントと位置を設定してから、テキスト、見出し、段落、スペース、罫線、段組みフロー、脚注を書き込んだり、同サイズのページを開始したりします。
インラインラン
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
スタイル付きのインラインテキストランと改行を追加します。
リンクとスクリプト
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/ページ/名前付き/JavaScript のリンク注釈を追加し、ページ単位またはフィールド単位のスクリプトを付与します。
マークアップ注釈
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
ハイライト/下線/取り消し線/波線のマークアップ、付箋、透かし、スタンプ、フリーテキスト注釈を追加します。
フォームフィールド
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 のテキストフィールド、チェックボックス、プッシュボタン、署名フィールド、コンボボックス、ラジオグループを追加します。
バーコードと画像
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 次元バーコード、QR コード、画像(任意で代替テキストやアーティファクトタグ付き)を描画します。
ベクターグラフィックス
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
矩形、線、ストローク付き/破線の図形、および矩形に制約されたテキストを描画します。
テーブル
func table(nColumns: Int, widths: [Float], aligns: [Int32], nRows: Int, cellStrings: [String], hasHeader: Bool) throws -> PageBuilder
静的なテーブルをバッファリングします。cellStrings は行優先(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
ストリーミング行、任意の rowspan、バッチ処理、自動フィットモードを使って、大きなテーブルを段階的に構築します。
仕上げ
func done() throws
func close()
ページを仕上げ、親ビルダーへ制御を返します。
EmbeddedFont
DocumentBuilder に登録されたフォントです。
static func fromFile(_ path: String) throws -> EmbeddedFont
static func fromBytes(_ bytes: [UInt8], name: String? = nil) throws -> EmbeddedFont
func close()
TrueType/OpenType フォントをファイルまたはバイト列から読み込みます。
BarcodeImage
1 次元/2 次元バーコードを生成・検査します。
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
QR コード、または指定形式のバーコードを生成します。
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()
デコードされたペイロード、形式、信頼度を読み取るか、バーコードを PNG バイト列または SVG 文字列にレンダリングします。
RenderedImage
Document.renderPage* メソッドから返される、レンダリング済みのページ画像です。
let width: Int
let height: Int
let data: [UInt8]
func save(_ path: String) throws
func close()
ピクセル寸法、エンコード済みの画像バイト列、および画像をファイルに保存するヘルパーを提供します。
Renderer
スタンドアロンなレンダラー設定ハンドルです。
static func create(dpi: Int32 = 150, format: Int32 = 0, quality: Int32 = 90, antiAlias: Bool = true) throws -> Renderer
func close()
DPI、形式(0=PNG、1=JPEG)、JPEG 品質、アンチエイリアス設定を備えた再利用可能なレンダラーを作成します。
OcrEngine
検出/認識モデルを基盤とする OCR エンジンです。
static func create(detModelPath: String, recModelPath: String, dictPath: String) throws -> OcrEngine
func close()
検出モデル、認識モデル、辞書のパスからエンジンを作成します。これを Document.ocrExtractText(_:engine:) に渡します。
Certificate
署名用の証明書と鍵です。
static func loadFromBytes(_ bytes: [UInt8], password: String) throws -> Certificate
static func loadFromPem(certPem: String, keyPem: String) throws -> Certificate
PKCS#12 バイト列(パスワード付き)または PEM 文字列から証明書を読み込みます。
func subject() throws -> String
func issuer() throws -> String
func serial() throws -> String
func validity() throws -> CertificateValidity
func isValid() throws -> Bool
func close()
サブジェクト、発行者、シリアル、有効期間、および現在の有効性を読み取ります。
SignatureInfo
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()
署名者メタデータ、証明書、PAdES レベル、タイムスタンプを読み取り、署名を検証します(任意で分離型のメッセージダイジェスト検査を伴います)。
Timestamp
RFC 3161 タイムスタンプトークンです。
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()
タイムスタンプトークンを解析してそのフィールドを読み取るか、検証します。
TsaClient
タイムスタンプ局(TSA)クライアントです(tsa-client フィーチャーで有効になります)。
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()
TSA エンドポイントを構成し、データまたは事前計算済みハッシュに対してタイムスタンプを要求します。
Dss
Document.dss() から返される Document Security Store です。
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()
長期検証(LTV)のために保存された証明書、CRL、OCSP レスポンスの数を数えて読み取ります。
PdfAResults / UaResults / PdfXResults
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()
適合性/アクセシビリティ、エラーと警告のリスト、および PDF/UA の統計情報を検査します。
ElementList
Document.pageElements(_:) から返される、ページ単位の汎用要素リストです。
func count() throws -> Int
func element(_ index: Int) throws -> Element
func all() throws -> [Element]
func toJson() throws -> String
func close()
ページ要素(種別、テキスト、矩形)を反復処理するか、JSON にシリアライズします。
トップレベル関数
生のバイト列やグローバル状態に対して動作するフリー関数です。
func signBytes(_ pdf: [UInt8], certificate: Certificate, reason: String? = nil, location: String? = nil) throws -> [UInt8]
生の PDF バイト列に署名し、署名済み 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]
PAdES ベースラインレベル(0=B-B、1=B-T、2=B-LT)で署名し、任意で TSA URL と失効情報を指定します。
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]
signBytesPades の構造体オプション版です。
func merge(_ paths: [String]) throws -> [UInt8]
paths の PDF を(順番どおりに)1 つのメモリ上 PDF へ結合します。
func addTimestamp(_ pdfData: [UInt8], sigIndex: Int32, tsaUrl: String) throws -> [UInt8]
署名に RFC 3161 タイムスタンプを追加し、再保存した PDF バイト列を返します。
func setLogLevel(_ level: Int32)
func getLogLevel() -> Int32
グローバルなライブラリログレベルを設定または読み取ります(0=Off … 5=Trace)。
PdfOxide(グローバル設定)
PdfOxide 列挙型は、プロセス全体の暗号ポリシー、モデルのプリフェッチ、パーサー設定を名前空間として束ねます。
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
暗号プロバイダー、CBOM/インベントリ、ポリシー、FIPS モードを検査・設定します。
static func modelManifest() -> String
static func prefetchAvailable() -> Int32
static func prefetchModels(languagesCsv: String) throws -> String
OCR モデルのマニフェストを読み取り、カンマ区切りの言語リストに対してモデルをプリフェッチします。
static func setMaxOpsPerStream(_ limit: Int64) -> Int64
static func setPreserveUnmappedGlyphs(_ preserve: Int32) -> Int32
パーサーの上限値とグリフマッピングの挙動を調整します。
値型
抽出メソッドから返されるプレーンな構造体です。
PdfOxideError
struct PdfOxideError: Error, CustomStringConvertible {
let code: Int32
let op: String
}
非成功の C-ABI エラーコードが返された際にスローされます。
PdfVersion
struct PdfVersion { let major: Int; let minor: Int }
PDF バージョン(例: 1.7)です。
Bbox
struct Bbox { let x: Double; let y: Double; let width: Double; let height: Double }
PDF ユーザー空間単位の軸並行バウンディングボックスです。
Char
struct Char { let character: UInt32; let bbox: Bbox; let fontName: String; let fontSize: Double }
抽出された 1 文字(Unicode スカラー値)です。
Word
struct Word { let text: String; let bbox: Bbox; let fontName: String; let fontSize: Double; let bold: Bool }
抽出された 1 単語です。
TextLine
struct TextLine { let text: String; let bbox: Bbox; let wordCount: Int }
抽出されたテキストの 1 行です。
Table
struct Table {
let rowCount: Int
let colCount: Int
let hasHeader: Bool
func cell(_ row: Int, _ col: Int) -> String
}
抽出された 1 つのテーブルです。セルは cell(_:_:) で必要に応じて読み取ります。
Font
struct Font { let name: String; let type: String; let encoding: String; let embedded: Bool; let subset: Bool }
埋め込みフォントの記述子です。
Image
struct Image {
let width: Int
let height: Int
let bitsPerComponent: Int
let format: String
let colorspace: String
let data: [UInt8]
}
生のバイト列を伴う、抽出されたラスター画像です。
Annotation
struct Annotation { let type: String; let subtype: String; let content: String; let author: String; let rect: Bbox; let borderWidth: Double }
注釈の中核属性です。
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]
}
annotationExtras(_:index:) から得られる注釈の拡張属性です。
Path
struct Path { let bbox: Bbox; let strokeWidth: Double; let hasStroke: Bool; let hasFill: Bool; let operationCount: Int }
ベクターパスのジオメトリ概要です。
SearchResult
struct SearchResult { let text: String; let page: Int; let bbox: Bbox }
テキスト検索の一致結果です。
FormField
struct FormField { let name: String; let value: String; let type: String; let readonly: Bool; let required: Bool }
フォームフィールドの記述子です。
QuadPoint
struct QuadPoint { let x1, y1, x2, y2, x3, y3, x4, y4: Double }
マークアップ注釈の四角形です。
Element
struct Element { let type: String; let text: String; let rect: Bbox }
ElementList から得られる汎用ページ要素です。
CertificateValidity
struct CertificateValidity { let notBefore: Int64; let notAfter: Int64 }
証明書の有効期間(Unix タイムスタンプ)です。
UaStats
struct UaStats { let structElements: Int; let images: Int; let tables: Int; let forms: Int; let annotations: Int; let pages: Int }
UaResults.stats() から得られる PDF/UA の構造統計です。
完全な例
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")
他の言語のバインディング
PDF Oxide はあらゆる主要なエコシステム向けにネイティブバインディングを提供しています: Rust, Python, Node.js, WASM, C#, Golang, Java, PHP, Ruby, C++, Kotlin, Dart, R, Julia, Zig, Scala, Clojure, Objective-C, Elixir。
次のステップ
- 型と列挙型 — すべての共有型と列挙型
- Page API リファレンス — バインディング間で一貫したページ単位の反復処理
- Swift 入門 — チュートリアル