Reference · Object · lib.rs

PdfDoc Object

An open PDF: what the apps show and look into. One per file; closed when the last reference goes.

class PdfDoc {
    static func open(bytes: Data, password: String?) throws -> PdfDoc
    func pageCount() -> UInt32
    func pageSizes() -> [PageSize]
    func render(page: UInt32, width: UInt32, annotations: Bool) throws -> RenderedPage
    func text(page: UInt32) throws -> String
    func words(page: UInt32) throws -> [TextWord]
    func find(pages: [UInt32], pattern: String, caseInsensitive: Bool) throws -> [TextHit]
    func looksScanned() -> Bool
    func blankPages() throws -> [UInt32]
    func contentBounds(page: UInt32) throws -> DisplayRect?
    func pagesWithoutText() throws -> [UInt32]
    func hasForm() throws -> Bool
    func formWidgets() throws -> [FormWidget]
    func fillForm(edits: [FormEdit]) throws -> Data
    func chapterStarts() throws -> [UInt32]
    func exportImage(page: UInt32, dpi: Double, png: Bool, quality: UInt8) throws -> Data
}

Methods

open Constructor

WrongPassword when the file is encrypted and password does not open it.

static func open(bytes: Data, password: String?) throws -> PdfDoc

Parameters

NameTypeSwift / C#
bytesVec<u8>bytes
passwordOption<String>password

Returns

PdfDoc

Errors

Throws PagewerkError:

  • Unreadable: “unreadable: {message}”
  • Refused: “refused: {message}”
  • WrongPassword: “wrong password”

page_count

No description yet.

func pageCount() -> UInt32

Parameters

None.

Returns

u32

Errors

Does not throw.

page_sizes

Each page as displayed, in points.

func pageSizes() -> [PageSize]

Parameters

None.

Returns

Vec<PageSize>

Errors

Does not throw.

render

The page width pixels wide; annotations: form answers, comments, stamps too.

func render(page: UInt32, width: UInt32, annotations: Bool) throws -> RenderedPage

Parameters

NameTypeSwift / C#
pageu32page
widthu32width
annotationsboolannotations

Returns

RenderedPage

Errors

Throws PagewerkError:

  • Unreadable: “unreadable: {message}”
  • Refused: “refused: {message}”
  • WrongPassword: “wrong password”

text

No description yet.

func text(page: UInt32) throws -> String

Parameters

NameTypeSwift / C#
pageu32page

Returns

String

Errors

Throws PagewerkError:

  • Unreadable: “unreadable: {message}”
  • Refused: “refused: {message}”
  • WrongPassword: “wrong password”

words

No description yet.

func words(page: UInt32) throws -> [TextWord]

Parameters

NameTypeSwift / C#
pageu32page

Returns

Vec<TextWord>

Errors

Throws PagewerkError:

  • Unreadable: “unreadable: {message}”
  • Refused: “refused: {message}”
  • WrongPassword: “wrong password”

find

Matches of a regular expression; escape_pattern turns plain words into one.

func find(pages: [UInt32], pattern: String, caseInsensitive: Bool) throws -> [TextHit]

Parameters

NameTypeSwift / C#
pagesVec<u32>pages
patternStringpattern
case_insensitiveboolcaseInsensitive

Returns

Vec<TextHit>

Errors

Throws PagewerkError:

  • Unreadable: “unreadable: {message}”
  • Refused: “refused: {message}”
  • WrongPassword: “wrong password”

looks_scanned

No text on the first pages: probably a scan.

func looksScanned() -> Bool

Parameters

None.

Returns

bool

Errors

Does not throw.

blank_pages

No description yet.

func blankPages() throws -> [UInt32]

Parameters

None.

Returns

Vec<u32>

Errors

Throws PagewerkError:

  • Unreadable: “unreadable: {message}”
  • Refused: “refused: {message}”
  • WrongPassword: “wrong password”

content_bounds

No description yet.

func contentBounds(page: UInt32) throws -> DisplayRect?

Parameters

NameTypeSwift / C#
pageu32page

Returns

Option<DisplayRect>

Errors

Throws PagewerkError:

  • Unreadable: “unreadable: {message}”
  • Refused: “refused: {message}”
  • WrongPassword: “wrong password”

pages_without_text

No description yet.

func pagesWithoutText() throws -> [UInt32]

Parameters

None.

Returns

Vec<u32>

Errors

Throws PagewerkError:

  • Unreadable: “unreadable: {message}”
  • Refused: “refused: {message}”
  • WrongPassword: “wrong password”

has_form

No description yet.

func hasForm() throws -> Bool

Parameters

None.

Returns

bool

Errors

Throws PagewerkError:

  • Unreadable: “unreadable: {message}”
  • Refused: “refused: {message}”
  • WrongPassword: “wrong password”

form_widgets

Every form widget, for the app to draw controls over the rendered page.

func formWidgets() throws -> [FormWidget]

Parameters

None.

Returns

Vec<FormWidget>

Errors

Throws PagewerkError:

  • Unreadable: “unreadable: {message}”
  • Refused: “refused: {message}”
  • WrongPassword: “wrong password”

fill_form

Fills widgets in this open document; returns the file as it now is.

func fillForm(edits: [FormEdit]) throws -> Data

Parameters

NameTypeSwift / C#
editsVec<FormEdit>edits

Returns

Vec<u8>

Errors

Throws PagewerkError:

  • Unreadable: “unreadable: {message}”
  • Refused: “refused: {message}”
  • WrongPassword: “wrong password”

chapter_starts

Pages where a chapter (top-level bookmark) starts.

func chapterStarts() throws -> [UInt32]

Parameters

None.

Returns

Vec<u32>

Errors

Throws PagewerkError:

  • Unreadable: “unreadable: {message}”
  • Refused: “refused: {message}”
  • WrongPassword: “wrong password”

export_image

One page as a JPG or PNG file (PDF in Bilder).

func exportImage(page: UInt32, dpi: Double, png: Bool, quality: UInt8) throws -> Data

Parameters

NameTypeSwift / C#
pageu32page
dpif64dpi
pngboolpng
qualityu8quality

Returns

Vec<u8>

Errors

Throws PagewerkError:

  • Unreadable: “unreadable: {message}”
  • Refused: “refused: {message}”
  • WrongPassword: “wrong password”

Used by

compare_documents, compare_report, pixel_changes, redact_find

Signatures are generated from the engine’s code. Swift is checked against the generated bindings; C# follows the bindings generator’s naming rules.