Sign in

    This version of the module is deprecated: Use moonbitlang/pdflite instead

    pdflite

    Download zip
    Author
    Version
    0.1.2
    License
    Apache-2.0
    Last updated
    5 months ago
    Downloads
    8K

    #bobzhang/pdflite

    PdfBytes

    type PdfBytes = Bytes

    PDF byte strings and byte streams.

    This is an alias for MoonBit Bytes because PDF strings and streams are byte sequences, not Unicode text. Use String only after an explicit PDF text decoding step.

    PdfError

    pub(all) suberror PdfError {
    InvalidByte(Int)
    InvalidCursorPosition(Int)
    InvalidReadLength(Int)
    InvalidBit(Int)
    InvalidBitCount(Int)
    MatrixNotInvertable
    DictionaryExpected
    DictionaryKeyNotFound(PdfName)
    NumberExpected
    RectangleExpected
    BadRectangle
    MatrixMalformed
    InvalidHexEscape
    InvalidASCII85Data
    FilterNotSupported(PdfName)
    FilterExpected
    CCITTDecodeParmsExpected
    CCITTNotSupported(String)
    InvalidCCITTData
    PredictorExpected
    PredictorNotSupported(Int)
    InvalidLZWData
    InvalidFlateData
    ParseObjectExpected
    ParseArrayMalformed
    ParseSingleObjectExpected
    ParseIndirectObjectExpected
    ParseEndObjectExpected
    ParseStreamExpected
    ParseEndStreamExpected
    StreamLengthExpected
    StreamDataExpected
    ParsedObjectExpected
    PageTreeExpected
    PageRotationExpected(Int)
    ContentOperatorExpected
    ContentOperandExpected
    FunctionExpected
    FunctionNotSupported(Int)
    BadFunctionEvaluation(String)
    StartXRefExpected
    XRefExpected
    XRefEntryExpected
    TrailerExpected
    RootExpected
    BadRevision
    InvalidObjectNumber(Int)
    BadDate
    InvalidUnicodeCodepoint(Int)
    InvalidUTF16BE
    InvalidUTF8
    InvalidPDFDocEncoding(Int)
    CryptoKeyExpected
    InvalidCryptoDataLength(Int)
    EncryptionExpected
    EncryptionMethodExpected
    EncryptionDictionaryEntryExpected(PdfName)
    EncryptionDictionaryEntryTooShort(PdfName)
    EncryptionIDExpected
    EncryptionAuthenticationUnsupported(PdfCryptType)
    EncryptionObjectCryptUnsupported(PdfCryptType)
    EncryptionSavedStateExpected
    EncryptionRecryptUnsupported(PdfCryptType)
    EncryptionRecryptFailed
    EncryptionPermissionsCorrupt
    EncryptionPermissionsMismatch(Int, Int)
    RandomBytesUnavailable
    EncodingExpected
    EncodingDifferencesMalformed
    EncodingWriteUnsupported
    FontSubtypeExpected
    FontFlagsExpected
    StandardFontExpected
    BaseFontExpected
    FontFirstCharExpected
    FontLastCharExpected
    FontWidthsExpected
    FontWidthExpected
    FontCharProcsExpected
    FontTypeExpected
    FontWriteUnsupported
    AfmExpected
    ColourSpaceExpected
    BadText
    CIDSystemInfoExpected
    CIDRegistryExpected
    CIDOrderingExpected
    CIDSupplementExpected
    CIDBaseFontExpected
    CIDFontDescriptorExpected
    CIDWidthsExpected
    CIDWidths2Expected
    DescendantFontExpected
    CMapEncodingExpected
    PageLabelStyleExpected(String)
    EndOfInput
    } derive(Eq, ToJson,
    Debug
    )

    Error variants raised by pdflite parsing, writing, filtering, text, and encryption APIs.

    The variants intentionally stay specific enough for tests and callers to distinguish malformed input classes, while most public APIs expose them through the ordinary raise PdfError flow.

    BitStream

    pub struct BitStream {
    input : ByteCursor
    current_byte : Int
    bit_mask : Int
    bits_read : Int
    } derive(Eq, ToJson,
    Debug
    )

    A big-endian bit reader over a ByteCursor.

    The stream reads the most-significant bit of each byte first, matching the bit order used by PDF filters such as CCITT and Flate Huffman tables. align discards any unread bits in the current byte and resumes at the next byte boundary.

    BitStream::align

    fn BitStream::align(self : BitStream) -> Unit

    Discards unread bits in the current byte and moves to the next byte boundary.

    BitStream::bits_read

    fn BitStream::bits_read(self : BitStream) -> Int

    Returns the number of bits consumed from this stream.

    The count includes bits skipped by align.

    BitStream::get_bit

    fn BitStream::get_bit(self : BitStream) -> Bool raise PdfError

    Reads one bit and returns it as a boolean.

    The return value is true for bit 1 and false for bit 0. Raises PdfError::EndOfInput if there is no byte available for the next bit.

    BitStream::get_bit_int

    fn BitStream::get_bit_int(self : BitStream) -> Int raise PdfError

    Reads one bit and returns it as integer 0 or 1.

    Raises PdfError::EndOfInput if there is no byte available for the next bit.

    BitStream::get_value_int

    fn BitStream::get_value_int(self : BitStream, width : Int) -> Int raise PdfError

    Reads up to 31 bits as a big-endian signed Int payload.

    This function only assembles the bit pattern; it does not sign-extend the result. Raises PdfError::InvalidBitCount for widths outside 0..=31 and PdfError::EndOfInput if the stream ends early.

    BitStream::get_value_int64

    fn BitStream::get_value_int64(self : BitStream, width : Int) -> Int64 raise PdfError

    Reads up to 32 bits as a big-endian Int64 payload.

    This is useful for PDF filter fields whose packed value may not fit the positive range of Int. Raises PdfError::InvalidBitCount for widths outside 0..=32 and PdfError::EndOfInput if the stream ends early.

    BitStream::position

    fn BitStream::position(self : BitStream) -> BitStreamPosition

    Returns a restorable snapshot of the current bit position.

    BitStream::seek

    fn BitStream::seek(self : BitStream, position : BitStreamPosition) -> Unit

    Restores this bit stream to a previously captured position.

    Raises PdfError::InvalidCursorPosition if the saved byte position is not valid for the underlying cursor.

    BitStreamPosition

    pub struct BitStreamPosition {
    input_position : Int
    current_byte : Int
    bit_mask : Int
    bits_read : Int
    } derive(Eq, ToJson,
    Debug
    )

    A restorable snapshot of a BitStream position.

    The snapshot captures both the underlying byte cursor position and the partially consumed current byte, so seeking back to it is safe even in the middle of a byte.

    BitWriter

    pub struct BitWriter {
    current_byte : Int
    bit_index : Int
    bytes : Array[Byte]
    } derive(Eq, ToJson,
    Debug
    )

    A big-endian bit writer that accumulates PDF bytes.

    Bits are packed most-significant first in each output byte. The final byte is zero-padded when align or to_bytes flushes a partially filled byte.

    BitWriter::align

    fn BitWriter::align(self : BitWriter) -> Unit

    Flushes any partial output byte, padding its unread low bits with zero.

    BitWriter::append_aligned

    fn BitWriter::append_aligned(self : BitWriter, other : BitWriter) -> BitWriter

    Appends another writer's bits after aligning this writer to a byte boundary.

    The returned writer is a copy; neither input writer is mutated.

    BitWriter::bit_length

    fn BitWriter::bit_length(self : BitWriter) -> Int

    Returns the number of bits currently written, including an unflushed partial byte.

    BitWriter::put_bit

    fn BitWriter::put_bit(self : BitWriter, bit : Int) -> Unit raise PdfError

    Writes one bit, accepting only integer values 0 and 1.

    Raises PdfError::InvalidBit for any other value.

    BitWriter::put_value_int

    fn BitWriter::put_value_int(self : BitWriter, width : Int, value : Int) -> Unit raise PdfError

    Writes the low width bits of an Int in big-endian bit order.

    Raises PdfError::InvalidBitCount for widths outside 0..=31.

    BitWriter::put_value_int64

    fn BitWriter::put_value_int64(self : BitWriter, width : Int, value : Int64) -> Unit raise PdfError

    Writes the low width bits of an Int64 in big-endian bit order.

    Raises PdfError::InvalidBitCount for widths outside 0..=32.

    BitWriter::to_bytes

    fn BitWriter::to_bytes(self : BitWriter) -> Bytes

    Returns the accumulated bytes, flushing a partial final byte if needed.

    ByteCursor

    pub struct ByteCursor {
    data : BytesView
    position : Int
    offset : Int
    source : String
    } derive(Eq, ToJson,
    Debug
    )

    A mutable read cursor over a PDF byte view.

    ByteCursor keeps a source label for diagnostics and supports an optional logical offset. After set_offset, public positions are relative to that offset while absolute positions still refer to the underlying byte view.

    ByteCursor::absolute_position

    fn ByteCursor::absolute_position(self : ByteCursor) -> Int

    Returns the current absolute position in the underlying byte view.

    ByteCursor::drop_pdf_whitespace

    fn ByteCursor::drop_pdf_whitespace(self : ByteCursor) -> Unit

    Advance the cursor past PDF white space.

    The first non-whitespace byte, delimiter, or end of input is left unread.

    ByteCursor::ignore_until

    fn ByteCursor::ignore_until(self : ByteCursor, stop : (Int) -> Bool, eof_is_delimiter? : Bool) -> Unit raise PdfError

    Advances until stop matches the next byte.

    The delimiter byte is left unread. EOF handling follows read_until_view.

    ByteCursor::input_byte

    fn ByteCursor::input_byte(self : ByteCursor) -> Int

    Reads one byte as an integer and advances the cursor.

    Returns pdf_no_more when reading past the end. This method always advances by one position, matching the historical parser cursor behavior.

    ByteCursor::input_pdf_error

    fn ByteCursor::input_pdf_error(self : ByteCursor, message : String) -> String

    Formats an input error message with the source label and current logical position.

    ByteCursor::length

    fn ByteCursor::length(self : ByteCursor) -> Int

    Returns the total length of the underlying byte view.

    ByteCursor::lex_pdf_bool

    fn ByteCursor::lex_pdf_bool(self : ByteCursor) -> PdfLexeme

    Lex true or false at the current cursor position.

    The cursor first reads one regular token. Non-boolean tokens produce LexNone.

    ByteCursor::lex_pdf_comment

    fn ByteCursor::lex_pdf_comment(self : ByteCursor) -> PdfLexeme

    Lex and skip a PDF comment.

    A comment starts with % and runs up to but not including the next newline. The comment text is intentionally not retained; this returns an empty LexComment payload. Non-comment input returns LexNone.

    ByteCursor::lex_pdf_delimiter

    fn ByteCursor::lex_pdf_delimiter(self : ByteCursor) -> PdfLexeme

    Lex one PDF delimiter token.

    Recognizes [, ], <<, and >>. A single < or > is left unread and returns LexNone.

    ByteCursor::lex_pdf_hex_string

    fn ByteCursor::lex_pdf_hex_string(self : ByteCursor) -> PdfLexeme raise PdfError

    Lex a PDF hexadecimal string.

    The opening < must not be a dictionary delimiter <<. White space inside the hex string is ignored, odd trailing nibbles are padded in the PDF way, and invalid hex digits raise InvalidHexEscape.

    ByteCursor::lex_pdf_keyword

    fn ByteCursor::lex_pdf_keyword(self : ByteCursor) -> PdfLexeme raise PdfError

    Lex PDF structural keywords.

    Recognized keywords include obj, endobj, R, null, and endstream. If a token begins with endobj followed by extra bytes, only endobj is consumed so the suffix can be lexed by later calls.

    ByteCursor::lex_pdf_literal_string

    fn ByteCursor::lex_pdf_literal_string(self : ByteCursor) -> PdfLexeme raise PdfError

    Lex a PDF literal string.

    Literal strings are enclosed in parentheses, may contain balanced nested parentheses, and support the PDF backslash escapes for control characters, octal bytes, escaped parentheses, and line continuation. Unterminated strings raise EndOfInput.

    ByteCursor::lex_pdf_name

    fn ByteCursor::lex_pdf_name(self : ByteCursor) -> PdfLexeme raise PdfError

    Lex a PDF name object.

    Names start with / and keep the slash in the stored bytes. #xx hex escapes are decoded into raw bytes. Invalid escapes raise InvalidHexEscape; non-name input returns LexNone without consuming it.

    ByteCursor::lex_pdf_number

    fn ByteCursor::lex_pdf_number(self : ByteCursor) -> PdfLexeme

    Lex a PDF integer or real number.

    Integers are limited to MoonBit Int range; oversized integer-looking tokens fall back to real-number parsing. A leading doubled minus is accepted compatibly by dropping one minus sign.

    ByteCursor::lex_pdf_token

    fn ByteCursor::lex_pdf_token(self : ByteCursor) -> PdfLexeme raise PdfError

    Lex one token from the current cursor position.

    This dispatcher skips white space, recognizes comments, primitives, delimiters, names, literal and hex strings, and selected keywords. It returns StopLexing at end of input and at markers that terminate object scanning, such as startxref or inline image data boundaries.

    ByteCursor::lex_pdf_tokens

    fn ByteCursor::lex_pdf_tokens(self : ByteCursor) -> Array[PdfLexeme] raise PdfError

    Lex tokens until a stop marker or unmatched input is reached.

    StopLexing and LexNone terminate scanning and are not included in the returned token array.

    ByteCursor::nudge

    fn ByteCursor::nudge(self : ByteCursor) -> Unit

    Advances the cursor by one byte, ignoring the value read.

    ByteCursor::peek

    fn ByteCursor::peek(self : ByteCursor) -> Byte?

    Returns the next byte without consuming it, or None at end of input.

    ByteCursor::peek_byte

    fn ByteCursor::peek_byte(self : ByteCursor) -> Int

    Returns the next byte as an integer without consuming it.

    Returns pdf_no_more at end of input.

    ByteCursor::peek_bytes

    fn ByteCursor::peek_bytes(self : ByteCursor, length : Int) -> Bytes raise PdfError

    Copies the next length bytes without advancing.

    Raises the same errors as peek_view.

    ByteCursor::peek_view

    fn ByteCursor::peek_view(self : ByteCursor, length : Int) -> BytesView raise PdfError

    Returns a read-only view of the next length bytes without advancing.

    Raises PdfError::InvalidReadLength for negative lengths and PdfError::EndOfInput if the requested range extends past the input.

    ByteCursor::position

    fn ByteCursor::position(self : ByteCursor) -> Int

    Returns the current logical position, relative to the configured offset.

    ByteCursor::read_byte

    fn ByteCursor::read_byte(self : ByteCursor) -> Byte?

    Reads one byte and advances the cursor, returning None at end of input.

    ByteCursor::read_byte_back

    fn ByteCursor::read_byte_back(self : ByteCursor) -> Byte?

    Reads the previous byte and moves the cursor backward.

    Returns None when the cursor is at the logical start or when the resulting position is outside the underlying view.

    ByteCursor::read_bytes

    fn ByteCursor::read_bytes(self : ByteCursor, length : Int) -> Bytes raise PdfError

    Reads length bytes into owned PDF bytes and advances past them.

    Raises the same errors as read_view.

    ByteCursor::read_bytes_at

    fn ByteCursor::read_bytes_at(self : ByteCursor, position : Int, length : Int) -> Bytes raise PdfError

    Seeks to position, reads length bytes into owned PDF bytes, and advances past them.

    ByteCursor::read_jpeg_data

    fn ByteCursor::read_jpeg_data(self : ByteCursor) -> Bytes raise PdfError

    Reads JPEG data from the current cursor position through the EOI marker.

    The returned bytes include the terminal 0xFF 0xD9 marker. Raises PdfError::EndOfInput if the marker is not found before EOF.

    ByteCursor::read_line

    fn ByteCursor::read_line(self : ByteCursor) -> Bytes raise PdfError

    Reads one line into owned PDF bytes.

    Raises PdfError::EndOfInput if called at EOF.

    ByteCursor::read_line_view

    fn ByteCursor::read_line_view(self : ByteCursor) -> BytesView raise PdfError

    Reads one line as a view, including the line-ending bytes when present.

    Both LF and CRLF are recognized. Raises PdfError::EndOfInput if called at EOF.

    ByteCursor::read_line_views

    fn ByteCursor::read_line_views(self : ByteCursor) -> Array[BytesView]

    Reads all remaining lines as borrowed views.

    Each line view includes the line-ending bytes when they were present in the input.

    ByteCursor::read_lines

    fn ByteCursor::read_lines(self : ByteCursor) -> Array[Bytes]

    Reads all remaining lines as owned PDF bytes.

    ByteCursor::read_pdf_header

    fn ByteCursor::read_pdf_header(self : ByteCursor) -> PdfVersion raise PdfError

    Read the PDF header from the current cursor buffer.

    The reader probes the first 1024 bytes for %PDF-x.y. When found, the cursor offset is set to the header position and the cursor advances past the header. If no header is found, pdf_default_version is returned.

    ByteCursor::read_pdf_regular_token_view

    fn ByteCursor::read_pdf_regular_token_view(self : ByteCursor) -> BytesView

    Skip PDF white space and read a regular token as a borrowed byte view.

    ByteCursor::read_remaining_bytes

    fn ByteCursor::read_remaining_bytes(self : ByteCursor) -> Bytes

    Reads all remaining bytes into owned PDF bytes and advances to EOF.

    ByteCursor::read_until_pdf_whitespace_or_delimiter

    fn ByteCursor::read_until_pdf_whitespace_or_delimiter(self : ByteCursor) -> BytesView

    Read a borrowed view up to PDF white space or a delimiter.

    The terminating byte is left unread so higher-level lexers can dispatch on delimiters after reading a regular token.

    ByteCursor::read_until_view

    fn ByteCursor::read_until_view(self : ByteCursor, stop : (Int) -> Bool, eof_is_delimiter? : Bool) -> BytesView raise PdfError

    Reads until stop matches the next byte and returns the bytes before it.

    The delimiter byte is not consumed. If EOF is reached and eof_is_delimiter is true, the remaining bytes are returned; otherwise PdfError::EndOfInput is raised.

    ByteCursor::read_view

    fn ByteCursor::read_view(self : ByteCursor, length : Int) -> BytesView raise PdfError

    Reads length bytes as a view and advances past them.

    Raises PdfError::InvalidReadLength for negative lengths and PdfError::EndOfInput if the requested range extends past the input.

    ByteCursor::read_view_at

    fn ByteCursor::read_view_at(self : ByteCursor, position : Int, length : Int) -> BytesView raise PdfError

    Seeks to position, then reads length bytes as a view.

    The returned view borrows the cursor input; use read_bytes_at when owned bytes are required.

    ByteCursor::remaining_length

    fn ByteCursor::remaining_length(self : ByteCursor) -> Int

    Returns the number of unread bytes remaining from the absolute cursor position.

    ByteCursor::remaining_view

    fn ByteCursor::remaining_view(self : ByteCursor) -> BytesView

    Returns a view of all bytes from the current position to the end of input.

    ByteCursor::rewind

    fn ByteCursor::rewind(self : ByteCursor) -> Unit raise PdfError

    Moves the cursor one byte backward.

    Raises PdfError::InvalidCursorPosition if the cursor is already at the logical start position.

    ByteCursor::seek

    fn ByteCursor::seek(self : ByteCursor, position : Int) -> Unit raise PdfError

    Moves the cursor to a logical position.

    The supplied position is interpreted relative to the configured offset. Seeking past the end is allowed so callers can probe EOF behavior; negative absolute positions raise PdfError::InvalidCursorPosition.

    ByteCursor::set_offset

    fn ByteCursor::set_offset(self : ByteCursor, offset : Int) -> Unit raise PdfError

    Sets the logical position offset used by position and seek.

    The offset can only be set once and must be non-negative. This is used when parsing substreams whose local position should start at zero while retaining absolute positions for diagnostics.

    ByteCursor::source

    fn ByteCursor::source(self : ByteCursor) -> String

    Returns the diagnostic source label associated with this cursor.

    ByteCursor::to_bytes

    fn ByteCursor::to_bytes(self : ByteCursor) -> Bytes

    Copies the underlying byte view into owned PDF bytes.

    ByteCursor::view

    fn ByteCursor::view(self : ByteCursor) -> BytesView

    Returns the underlying read-only byte view without copying.

    ByteOutput

    pub struct ByteOutput {
    data : Array[Byte]
    position : Int
    written_length : Int
    } derive(Eq, ToJson,
    Debug
    )

    A growable byte sink with seekable overwrite support.

    ByteOutput tracks the current write position separately from the highest position written, so callers may seek backward to patch bytes and then obtain only the initialized prefix with to_bytes.

    ByteOutput::length

    fn ByteOutput::length(self : ByteOutput) -> Int

    Returns the highest written byte position.

    This is the length of the byte sequence returned by to_bytes.

    ByteOutput::position

    fn ByteOutput::position(self : ByteOutput) -> Int

    Returns the current write position.

    ByteOutput::seek

    fn ByteOutput::seek(self : ByteOutput, position : Int) -> Unit raise PdfError

    Moves the write position.

    Seeking beyond the current length is allowed; unwritten gaps are filled with zero when data is later written. Negative positions raise PdfError::InvalidCursorPosition.

    ByteOutput::to_bytes

    fn ByteOutput::to_bytes(self : ByteOutput) -> Bytes

    Returns the written prefix as owned PDF bytes.

    Bytes beyond length that were only preallocated are not included.

    ByteOutput::write_ascii

    fn ByteOutput::write_ascii(self : ByteOutput, text : String) -> Unit raise PdfError

    Encodes an ASCII string and writes the resulting bytes.

    The underlying @ascii.encode function is used intentionally; callers should pass bytes directly for non-ASCII PDF payloads.

    ByteOutput::write_byte

    fn ByteOutput::write_byte(self : ByteOutput, value : Int) -> Unit raise PdfError

    Writes one byte at the current position and advances by one.

    Raises PdfError::InvalidByte if value is outside the byte range 0..=255.

    ByteOutput::write_byte_at

    fn ByteOutput::write_byte_at(self : ByteOutput, position : Int, value : Int) -> Unit raise PdfError

    Seeks to position, writes one byte, and advances by one.

    Raises the same errors as seek and write_byte.

    ByteOutput::write_repeated_byte

    fn ByteOutput::write_repeated_byte(self : ByteOutput, length : Int, value? : Int) -> Unit raise PdfError

    Writes length copies of value and advances past them.

    The default value is zero. Raises PdfError::InvalidReadLength for invalid lengths and PdfError::InvalidByte for values outside 0..=255.

    ByteOutput::write_view

    fn ByteOutput::write_view(self : ByteOutput, bytes : BytesView) -> Unit raise PdfError

    Writes a byte view at the current position and advances past it.

    Raises PdfError::InvalidReadLength if the computed end position overflows.

    ByteOutput::write_view_at

    fn ByteOutput::write_view_at(self : ByteOutput, position : Int, bytes : BytesView) -> Unit raise PdfError

    Seeks to position, writes a byte view, and advances past it.

    Raises the same errors as seek and write_view.

    ByteOutput::write_view_slice

    fn ByteOutput::write_view_slice(self : ByteOutput, bytes : BytesView, offset : Int, length : Int) -> Unit raise PdfError

    Writes a slice of a byte view at the current position.

    Raises PdfError::InvalidCursorPosition for a negative offset, PdfError::InvalidReadLength for a negative or overflowing length, and PdfError::EndOfInput if the requested slice exceeds the input view.

    ObjectStreamReference

    pub(all) struct ObjectStreamReference {
    object_stream_number : Int
    index : Int
    } derive(Eq, ToJson,
    Debug
    )

    Location of an object stored inside a PDF object stream.

    object_stream_number is the containing object stream number, and index is the zero-based entry index inside that stream.

    PaperSize

    pub(all) struct PaperSize {
    unit : PdfUnit
    width : Double
    height : Double
    } derive(Eq, ToJson,
    Debug
    )

    A paper size expressed in a declared unit.

    Width and height are stored as given; conversion to PDF points happens at page-construction boundaries.

    PaperSize::height

    fn PaperSize::height(self : PaperSize) -> Double

    Returns the paper height in this size's unit.

    PaperSize::landscape

    fn PaperSize::landscape(self : PaperSize) -> PaperSize

    Returns the same paper dimensions with width and height swapped.

    PaperSize::unit

    fn PaperSize::unit(self : PaperSize) -> PdfUnit

    Returns the unit used by this paper size.

    PaperSize::width

    fn PaperSize::width(self : PaperSize) -> Double

    Returns the paper width in this size's unit.

    PdfAesV3RandomField

    pub(all) enum PdfAesV3RandomField {
    PdfAesV3FileKey
    PdfAesV3UserValidationSalt
    PdfAesV3UserKeySalt
    PdfAesV3OwnerValidationSalt
    PdfAesV3OwnerKeySalt
    PdfAesV3PermissionsPadding
    } derive(Eq, ToJson,
    Debug
    )

    Random material requested while constructing PDF 2.0 AESV3 encryption data.

    Provider callbacks receive this field tag and a byte length, allowing tests and reproducible builds to supply deterministic file keys, salts, and permissions padding.

    PdfAfmData

    pub(all) struct PdfAfmData {
    headers : Array[(Bytes, Bytes)]
    char_metrics : Array[(Int, Int)]
    kerns : Array[(Int, Int, Int)]
    char_name_widths : Array[(Bytes, Int)]
    } derive(Eq, ToJson,
    Debug
    )

    Parsed Adobe Font Metrics data used by standard-font helpers.

    Headers preserve raw key/value bytes. Character metrics store character codes and widths, kerns store pair adjustments, and char_name_widths preserves name-based widths for encodings that refer to glyph names.

    PdfAnnotation

    pub(all) struct PdfAnnotation {
    subtype : PdfAnnotationSubtype
    contents : Bytes?
    subject : Bytes?
    rectangle : PdfRectangle
    border : PdfAnnotationBorder
    colour : PdfAnnotationColour?
    rest : PdfObject
    } derive(Eq, ToJson,
    Debug
    )

    Parsed PDF annotation dictionary.

    contents and subject are raw PDF string bytes. rectangle is required when reading from a PDF. rest preserves dictionary entries not modeled by the typed fields so they can be written back.

    PdfAnnotationBorder

    pub(all) struct PdfAnnotationBorder {
    width : Double
    vertical_radius : Double
    horizontal_radius : Double
    style : PdfAnnotationStyle
    dash_array : Array[Int]
    } derive(Eq, ToJson,
    Debug
    )

    Parsed annotation border information.

    vertical_radius and horizontal_radius come from the legacy /Border array form. style and dash_array represent /BS dictionary entries when present.

    PdfAnnotationColour

    pub(all) struct PdfAnnotationColour {
    red : Int
    green : Int
    blue : Int
    } derive(Eq, ToJson,
    Debug
    )

    RGB annotation colour from the /C entry.

    Components are stored as integer channel values after parsing PDF numbers.

    PdfAnnotationStyle

    pub(all) enum PdfAnnotationStyle {
    AnnotationNoStyle
    AnnotationSolid
    AnnotationDashed
    AnnotationBeveled
    AnnotationInset
    AnnotationUnderlineStyle
    } derive(Eq, ToJson,
    Debug
    )

    Border style used by an annotation border dictionary.

    PdfAnnotationSubtype

    pub(all) enum PdfAnnotationSubtype {
    AnnotationText
    AnnotationLink
    AnnotationFreeText
    AnnotationLine
    AnnotationSquare
    AnnotationCircle
    AnnotationPolygon
    AnnotationPolyLine
    AnnotationHighlight
    AnnotationUnderline
    AnnotationSquiggly
    AnnotationStrikeOut
    AnnotationStamp
    AnnotationCaret
    AnnotationInk
    AnnotationPopup(PdfAnnotation)
    AnnotationFileAttachment
    AnnotationSound
    AnnotationMovie
    AnnotationWidget
    AnnotationScreen
    AnnotationPrinterMark
    AnnotationTrapNet
    AnnotationWatermark
    AnnotationThreeDee
    AnnotationUnknown(PdfName)
    } derive(Eq, ToJson,
    Debug
    )

    Supported annotation subtype.

    Popup annotations embed their resolved parent annotation when available. Unknown subtype names are preserved as AnnotationUnknown.

    PdfBookmark

    pub(all) struct PdfBookmark {
    level : Int
    text : Bytes
    target : PdfDestination
    is_open : Bool
    colour : PdfBookmarkColour
    flags : Int
    } derive(Eq, ToJson,
    Debug
    )

    One bookmark in the flattened outline representation.

    Bookmarks are ordered in preorder. level is zero-based nesting depth, text is the raw PDF title string bytes, and target is the parsed destination or preserved action.

    PdfBookmarkColour

    pub(all) struct PdfBookmarkColour {
    red : Double
    green : Double
    blue : Double
    } derive(Eq, ToJson,
    Debug
    )

    Bookmark display colour from the PDF outline /C entry.

    PDF stores these as RGB real numbers, normally in the range 0.0 to 1.0.

    PdfBookmarkNode

    type PdfBookmarkNode derive(Eq, ToJson,
    Debug
    )

    PdfCIDKeyedFont

    pub(all) struct PdfCIDKeyedFont {
    basefont : PdfName
    composite : PdfCompositeCIDFont
    encoding : PdfCMapEncoding
    } derive(Eq, ToJson,
    Debug
    )

    Parsed Type 0 font with descendant CIDFont and CMap encoding.

    PdfCIDKeyedFont::debug_name

    fn PdfCIDKeyedFont::debug_name(self : PdfCIDKeyedFont) -> String

    Return a compact debug label containing the Type 0 base font name.

    PdfCIDKeyedFont::is_identity_h

    fn PdfCIDKeyedFont::is_identity_h(self : PdfCIDKeyedFont) -> Bool

    Test whether this Type 0 font uses /Identity-H.

    PdfCIDKeyedFont::is_identity_v

    fn PdfCIDKeyedFont::is_identity_v(self : PdfCIDKeyedFont) -> Bool

    Test whether this Type 0 font uses /Identity-V.

    PdfCIDKeyedFont::uses_two_byte_codes

    fn PdfCIDKeyedFont::uses_two_byte_codes(self : PdfCIDKeyedFont) -> Bool

    Return true when this Type 0 font uses fixed two-byte character codes.

    PdfCIDSystemInfo

    pub(all) struct PdfCIDSystemInfo {
    registry : Bytes
    ordering : Bytes
    supplement : Int
    } derive(Eq, ToJson,
    Debug
    )

    CID-system identity from a CIDFont or CMap dictionary.

    registry and ordering are stored as PDF bytes because PDF strings are byte sequences, not MoonBit String values.

    PdfCIDVerticalWidth

    pub(all) struct PdfCIDVerticalWidth {
    width : Double
    vx : Double
    vy : Double
    } derive(Eq, ToJson,
    Debug
    )

    Vertical metrics for a CID in a composite font.

    The fields correspond to the PDF /W2 tuple: vertical width and horizontal displacement vector components.

    PdfCMapCodeSpace

    pub(all) struct PdfCMapCodeSpace {
    length : Int
    first : Int
    last : Int
    } derive(Eq, ToJson,
    Debug
    )

    One parsed CMap code-space range.

    length is the character-code byte length, and first/last are the inclusive packed-byte bounds accepted by that range.

    PdfCMapEncoding

    pub(all) enum PdfCMapEncoding {
    PdfPredefinedCMap(PdfName)
    PdfCMap(Int)
    PdfExternalCMap(Int, PdfParsedCMap)
    } derive(Eq, ToJson,
    Debug
    )

    CMap source used by a Type 0 font.

    A CMap may be predefined by name, referenced as an external stream object, or parsed from that external stream together with its mapping tables.

    PdfCMapEncoding::is_identity_h

    fn PdfCMapEncoding::is_identity_h(self : PdfCMapEncoding) -> Bool

    Test whether this CMap encoding is the predefined /Identity-H map.

    PdfCMapEncoding::is_identity_v

    fn PdfCMapEncoding::is_identity_v(self : PdfCMapEncoding) -> Bool

    Test whether this CMap encoding is the predefined /Identity-V map.

    PdfCMapEncoding::uses_two_byte_codes

    fn PdfCMapEncoding::uses_two_byte_codes(self : PdfCMapEncoding) -> Bool

    Return true when this CMap consumes text as fixed two-byte character codes.

    Identity CMaps and common UCS2/UTF16 predefined maps are treated as two-byte. Parsed external CMaps are two-byte only when all code spaces have length 2, or when they inherit an identity base with no explicit spaces.

    PdfCalculatorFunction

    pub(all) struct PdfCalculatorFunction {
    operations : Array[PdfCalculatorOp]
    } derive(Eq, ToJson,
    Debug
    )

    PDF function type 4, represented as parsed calculator operations.

    Evaluation starts with the function inputs on the stack and returns the numeric values left on the stack after all operations have run.

    PdfCalculatorOp

    pub(all) enum PdfCalculatorOp {
    PdfCalculatorInt(Int)
    PdfCalculatorFloat(Double)
    PdfCalculatorAbs
    PdfCalculatorAdd
    PdfCalculatorAnd
    PdfCalculatorAtan
    PdfCalculatorBitshift
    PdfCalculatorBool(Bool)
    PdfCalculatorCeiling
    PdfCalculatorCos
    PdfCalculatorCopy
    PdfCalculatorCvi
    PdfCalculatorCvr
    PdfCalculatorSub
    PdfCalculatorMul
    PdfCalculatorDiv
    PdfCalculatorDup
    PdfCalculatorExch
    PdfCalculatorExp
    PdfCalculatorFloor
    PdfCalculatorIdiv
    PdfCalculatorIf(Array[PdfCalculatorOp])
    PdfCalculatorIfElse(Array[PdfCalculatorOp], Array[PdfCalculatorOp])
    PdfCalculatorIndex
    PdfCalculatorLn
    PdfCalculatorLog
    PdfCalculatorEq
    PdfCalculatorGe
    PdfCalculatorGt
    PdfCalculatorLe
    PdfCalculatorLt
    PdfCalculatorMod
    PdfCalculatorNe
    PdfCalculatorNeg
    PdfCalculatorNot
    PdfCalculatorOr
    PdfCalculatorPop
    PdfCalculatorRoll
    PdfCalculatorRound
    PdfCalculatorSin
    PdfCalculatorSqrt
    PdfCalculatorTruncate
    PdfCalculatorXor
    } derive(Eq, ToJson,
    Debug
    )

    Operation in a PDF type 4 PostScript calculator function.

    Literals push values onto the calculator stack. PdfCalculatorIf and PdfCalculatorIfElse store nested procedure bodies; the remaining variants correspond to PDF calculator-language operators.

    PdfCalculatorOp::debug_name

    fn PdfCalculatorOp::debug_name(self : PdfCalculatorOp) -> String

    Return the calculator-language spelling for one operation.

    Procedure operations are formatted recursively in the same brace-delimited form accepted by the type 4 parser.

    PdfClassicXRefEntry

    type PdfClassicXRefEntry derive(Eq, ToJson,
    Debug
    )

    PdfColourSpace

    pub(all) enum PdfColourSpace {
    PdfDeviceGray
    PdfDeviceRGB
    PdfDeviceCMYK
    PdfCalGray(PdfTristimulusPoint, PdfTristimulusPoint, Double)
    PdfCalRGB(PdfTristimulusPoint, PdfTristimulusPoint, Array[Double], Array[Double])
    PdfLab(PdfTristimulusPoint, PdfTristimulusPoint, Array[Double])
    PdfICCBased(Int, PdfColourSpace, Array[Double], PdfObject?, PdfObject)
    PdfIndexed(PdfColourSpace, Array[(Int, Array[Int])])
    PdfPattern
    PdfPatternWithBaseColourSpace(PdfColourSpace)
    PdfSeparation(PdfName, PdfColourSpace, PdfObject)
    PdfDeviceN(Array[PdfName], PdfColourSpace, PdfObject, PdfObject)
    } derive(Eq, ToJson,
    Debug
    )

    Parsed representation of the PDF colour spaces supported by this package.

    Device spaces represent the PDF built-ins. Calibrated and ICC-based spaces preserve their calibration data, indexed spaces hold an expanded lookup table, and separation or DeviceN spaces retain their tint transform objects for round-tripping.

    PdfColourSpace::debug_name

    fn PdfColourSpace::debug_name(self : PdfColourSpace) -> String

    Return a diagnostic name for a colour space.

    Built-in spaces use their PDF names. Composite spaces include the diagnostic name of their alternate or base space, making the result useful for logs, snapshots, and error messages rather than for serialization.

    PdfColourSpace::name

    Return the PDF colourant name carried by a separation space.

    Only PdfSeparation has a single associated colourant name in this API. Other colour spaces, including PdfDeviceN, return None.

    PdfCompositeCIDFont

    pub(all) struct PdfCompositeCIDFont {
    cid_system_info : PdfCIDSystemInfo
    cid_basefont : PdfName
    cid_fontdescriptor : PdfFontDescriptor
    cid_widths : Array[(Int, Double)]
    cid_widths2 : Array[(Int, PdfCIDVerticalWidth)]
    cid_default_width : Double
    cid_default_width2 : Array[Double]
    } derive(Eq, ToJson,
    Debug
    )

    Parsed descendant CIDFont data for a Type 0 composite font.

    Width arrays are normalized into explicit CID-to-width entries while preserving the PDF default horizontal and vertical widths.

    PdfContentInlineTextFilter

    type PdfContentInlineTextFilter derive(Eq,
    Debug
    )

    PdfContentLexeme

    type PdfContentLexeme derive(Eq, ToJson,
    Debug
    )

    PdfContentOp

    pub(all) enum PdfContentOp {
    Op_w(Double)
    Op_J(Int)
    Op_j(Int)
    Op_M(Double)
    Op_d(Array[Double], Double)
    Op_ri(PdfName)
    Op_i(Double)
    Op_q
    Op_Q
    Op_cm(TransformMatrix)
    Op_m(Double, Double)
    Op_l(Double, Double)
    Op_c(Double, Double, Double, Double, Double, Double)
    Op_v(Double, Double, Double, Double)
    Op_y(Double, Double, Double, Double)
    Op_h
    Op_re(Double, Double, Double, Double)
    Op_S
    Op_s
    Op_f
    Op_F
    Op_fstar
    Op_B
    Op_Bstar
    Op_b
    Op_bstar
    Op_n
    Op_W
    Op_Wstar
    Op_BT
    Op_ET
    Op_Tc(Double)
    Op_Tw(Double)
    Op_Tz(Double)
    Op_TL(Double)
    Op_Tf(PdfName, Double)
    Op_Tr(Int)
    Op_Ts(Double)
    Op_Td(Double, Double)
    Op_TD(Double, Double)
    Op_Tm(TransformMatrix)
    Op_Tstar
    Op_Tj(Bytes)
    Op_TJ(PdfObject)
    Op_quote(Bytes)
    Op_double_quote(Double, Double, Bytes)
    Op_d0(Double, Double)
    Op_d1(Double, Double, Double, Double, Double, Double)
    Op_G(Double)
    Op_g(Double)
    Op_RG(Double, Double, Double)
    Op_rg(Double, Double, Double)
    Op_K(Double, Double, Double, Double)
    Op_k(Double, Double, Double, Double)
    Op_gs(PdfName)
    Op_CS(PdfName)
    Op_cs(PdfName)
    Op_SC(Array[Double])
    Op_sc(Array[Double])
    Op_SCN(Array[Double])
    Op_scn(Array[Double])
    Op_SCNName(PdfName, Array[Double])
    Op_scnName(PdfName, Array[Double])
    Op_sh(PdfName)
    Op_Do(PdfName)
    Op_InlineImage(PdfObject, PdfObject?, Bytes)
    Op_MP(PdfName)
    Op_DP(PdfName, PdfObject)
    Op_BMC(PdfName)
    Op_BDC(PdfName, PdfObject)
    Op_EMC
    Op_BX
    Op_EX
    Op_Unknown(Bytes)
    } derive(Eq, ToJson,
    Debug
    )

    Flat representation of PDF content stream operators.

    Text strings and unknown operators are stored as raw PDF bytes. Inline images carry their image dictionary, optional decode parameters, and image data; the parser decodes supported inline-image filters when it can do so safely.

    PdfCryptType

    pub(all) enum PdfCryptType {
    PdfCryptARC4(Int, Int)
    PdfCryptAESV2
    PdfCryptAESV3(Bool)
    } derive(Eq, ToJson,
    Debug
    )

    Object encryption algorithm used by the PDF security handlers.

    ARC4 carries key length in bits and security-handler revision. AESV3 carries whether the ISO/PDF 2.0 hash variant is in use.

    PdfDate

    pub(all) struct PdfDate {
    year : Int
    month : Int
    day : Int
    hour : Int
    minute : Int
    second : Int
    hour_offset : Int
    minute_offset : Int
    } derive(Eq, ToJson,
    Debug
    )

    A PDF date with local time-zone offset components.

    The fields mirror PDF's D:YYYYMMDDHHmmSSOHH'mm' representation. Month and day default to 1 when omitted during parsing; time fields default to zero.

    PdfDecryptionResult

    pub(all) struct PdfDecryptionResult {
    document : PdfDocument
    denied_permissions : Array[PdfPermission]
    } derive(Eq, ToJson,
    Debug
    )

    Result of successfully decrypting a document.

    document is a decrypted copy with encryption removed from the trailer and saved encryption state attached. denied_permissions is decoded from the original /P permission mask.

    PdfDestination

    pub(all) enum PdfDestination {
    DestAction(PdfObject)
    DestNull
    DestNamed(PdfName)
    DestString(Bytes)
    DestXYZ(PdfTargetPage, Double?, Double?, Double?)
    DestFit(PdfTargetPage)
    DestFitH(PdfTargetPage, Double?)
    DestFitV(PdfTargetPage, Double?)
    DestFitR(PdfTargetPage, Double, Double, Double, Double)
    DestFitB(PdfTargetPage)
    DestFitBH(PdfTargetPage, Double?)
    DestFitBV(PdfTargetPage, Double?)
    } derive(Eq, ToJson,
    Debug
    )

    A normalized PDF destination.

    The variants cover action dictionaries, named/string destinations, null destinations, and all standard page-view destination array forms.

    PdfDocument

    pub struct PdfDocument {
    major : Int
    minor : Int
    root : Int
    objects : PdfObjects
    trailer_dict : PdfObject
    was_linearized : Bool
    saved_encryption : PdfSavedEncryption?
    first_xref : Int
    revision_read : Int
    } derive(Eq, ToJson,
    Debug
    )

    In-memory representation of one PDF document.

    A document stores the PDF version, catalog root number, object table, trailer dictionary, linearization flag, saved encryption metadata, first xref offset, and the revision count read from the input.

    PdfDocument::add_annotation

    fn PdfDocument::add_annotation(self : PdfDocument, page : PdfPage, annotation : PdfAnnotation) -> PdfPage raise PdfError

    Return a page value with an annotation prepended to /Annots.

    The annotation is written as a direct dictionary. Existing annotation arrays are preserved after the new entry; a non-array /Annots value raises.

    PdfDocument::add_bookmarks

    fn PdfDocument::add_bookmarks(self : PdfDocument, bookmarks : ArrayView[PdfBookmark]) -> PdfDocument raise PdfError

    Return a copy of the document with its outline tree replaced.

    The input must be in preorder using zero-based level values. Empty input removes existing bookmarks. New outline objects are allocated after the current maximum object number.

    PdfDocument::add_object

    fn PdfDocument::add_object(self : PdfDocument, object : PdfObject, generation? : Int) -> Int

    Add a parsed object using the next available object number.

    Returns the allocated object number and records an object-altered event.

    PdfDocument::add_object_given_number

    fn PdfDocument::add_object_given_number(self : PdfDocument, number : Int, object : PdfObject, generation? : Int) -> Unit

    Add or replace a parsed object at an explicit object number.

    This records an object-altered event and updates the maximum object number if needed.

    PdfDocument::add_pagetree

    fn PdfDocument::add_pagetree(self : PdfDocument, pages : ArrayView[PdfPage]) -> Int raise PdfError

    Add a balanced page tree for pages and return its root object number.

    Page content objects that are not already indirect are inserted into the document. The document is mutated in place.

    PdfDocument::add_prefix

    fn PdfDocument::add_prefix(self : PdfDocument, prefix : String) -> Unit raise PdfError

    Prefix all page resource names and corresponding content references.

    If split content streams cannot be parsed independently, content streams are merged first. This mutates the document in place and is useful before combining pages from multiple documents.

    PdfDocument::add_root

    fn PdfDocument::add_root(self : PdfDocument, page_root_number : Int, extras : ArrayView[(PdfName, PdfObject)]) -> Int raise PdfError

    Add or replace the catalog root pointing at a page-tree root.

    Existing catalog entries are preserved except /Type and /Pages; extras can add or replace other catalog entries. The document trailer /Root is updated and the document is mutated in place.

    PdfDocument::aesv2_decrypt_parsed_objects

    fn PdfDocument::aesv2_decrypt_parsed_objects(self : PdfDocument, file_key : BytesView, key_length_bits : Int, no_encrypt_metadata? : Bool, skip_object_number? : Int) -> PdfDocument raise PdfError

    AESV2-decrypt all parsed objects in a copied document.

    Parsed streams may retain deferred crypt metadata so stream bytes can be decrypted lazily. skip_object_number leaves the encryption dictionary untouched.

    PdfDocument::aesv2_encrypt_parsed_objects_with_iv_provider

    fn PdfDocument::aesv2_encrypt_parsed_objects_with_iv_provider(self : PdfDocument, file_key : BytesView, key_length_bits : Int, iv_provider : (Int, Int, Int) -> Bytes raise PdfError, no_encrypt_metadata? : Bool, skip_object_number? : Int) -> PdfDocument raise PdfError

    AESV2-encrypt all parsed objects in a copied document.

    The IV provider receives object number, generation, and per-object IV index. skip_object_number leaves the encryption dictionary unencrypted.

    PdfDocument::aesv3_decrypt_parsed_objects

    fn PdfDocument::aesv3_decrypt_parsed_objects(self : PdfDocument, file_key : BytesView, no_encrypt_metadata? : Bool, skip_object_number? : Int) -> PdfDocument raise PdfError

    AESV3-decrypt all parsed objects in a copied document.

    Parsed streams may retain deferred crypt metadata so stream bytes can be decrypted lazily. skip_object_number leaves the encryption dictionary untouched.

    PdfDocument::aesv3_encrypt_parsed_objects_with_iv_provider

    fn PdfDocument::aesv3_encrypt_parsed_objects_with_iv_provider(self : PdfDocument, file_key : BytesView, iv_provider : (Int, Int, Int) -> Bytes raise PdfError, no_encrypt_metadata? : Bool, skip_object_number? : Int) -> PdfDocument raise PdfError

    AESV3-encrypt all parsed objects in a copied document.

    The IV provider receives object number, generation, and per-object IV index. skip_object_number leaves the encryption dictionary unencrypted.

    PdfDocument::annotations_of_page

    fn PdfDocument::annotations_of_page(self : PdfDocument, page : PdfPage) -> Array[PdfAnnotation] raise PdfError

    Read annotations from a page's /Annots array.

    Missing or malformed /Annots entries are treated as no annotations. When a popup annotation and its parent both appear in the page array, the parent is skipped and represented through AnnotationPopup.

    PdfDocument::arc4_crypt_parsed_objects

    fn PdfDocument::arc4_crypt_parsed_objects(self : PdfDocument, file_key : BytesView, key_length_bits : Int, no_encrypt_metadata? : Bool, skip_object_number? : Int) -> PdfDocument raise PdfError

    Apply ARC4 crypt to all parsed objects in a copied document.

    skip_object_number is used to leave the encryption dictionary itself unencrypted. Deferred and object-stream placeholders are left untouched.

    PdfDocument::bpc

    fn PdfDocument::bpc(self : PdfDocument, image : PdfObject) -> PdfObject?

    Compatibility alias for PdfDocument::image_bits_per_component.

    PdfDocument::build_name_tree

    fn PdfDocument::build_name_tree(self : PdfDocument, entries : ArrayView[(Bytes, PdfObject)]) -> PdfObject

    Build a PDF name tree from byte-string keys and object values.

    Entries are sorted by byte order. Empty input produces a leaf tree with an empty /Names array; larger inputs are split into child nodes with /Limits entries, allocating child objects in self as needed.

    PdfDocument::build_number_tree

    fn PdfDocument::build_number_tree(self : PdfDocument, entries : ArrayView[(Int, PdfObject)]) -> PdfObject

    Build a PDF number tree from integer keys and object values.

    Entries are sorted numerically. Empty input produces a leaf tree with an empty /Nums array; larger inputs are split into child nodes with /Limits entries, allocating child objects in self as needed.

    PdfDocument::catalog

    fn PdfDocument::catalog(self : PdfDocument) -> PdfObject raise PdfError

    Return the resolved document catalog object.

    A /Root entry in the trailer dictionary is preferred over the stored root number. The selected reference is resolved through direct; if it resolves to PdfNull, this raises RootExpected.

    PdfDocument::change_id

    fn PdfDocument::change_id(self : PdfDocument, path : String, get_time : () -> Double) -> Unit raise PdfError

    Replaces this document's trailer /ID entry.

    Raises PdfError::DictionaryExpected if the trailer is not a dictionary.

    PdfDocument::change_pages

    fn PdfDocument::change_pages(self : PdfDocument, pages : ArrayView[PdfPage], change_references? : Bool, matrices? : ArrayView[(Int, TransformMatrix)], changes? : ArrayView[(Int, Int)]) -> PdfDocument raise PdfError

    Replace the document page tree with pages.

    When change_references is true, page-object references in destinations, actions, annotations, and bookmarks are rewritten from the old page set to the new one. matrices can transform destination coordinates for pages whose geometry changed, and changes can map old page serials to new serials when page counts differ.

    PdfDocument::colour_space_components

    fn PdfDocument::colour_space_components(self : PdfDocument, resources : PdfObject, object : PdfObject) -> Int raise PdfError

    Return the number of components required by a colour-space object.

    Resource names are resolved through the supplied resources dictionary. Pattern spaces without a base colour space are rejected because their paint operators do not consume ordinary colour components.

    PdfDocument::colspace

    fn PdfDocument::colspace(self : PdfDocument, image : PdfObject, resources : PdfObject) -> PdfColourSpace raise PdfError

    Compatibility alias for PdfDocument::image_colour_space.

    PdfDocument::combine_pdf_resources

    fn PdfDocument::combine_pdf_resources(self : PdfDocument, first : PdfObject, second : PdfObject) -> PdfObject

    Merge two page resource dictionaries.

    Known resource categories such as /Font, /XObject, and /ColorSpace are concatenated; unknown top-level entries from both dictionaries are preserved. Later duplicate resource names are not renamed here.

    PdfDocument::contents_of_name_tree

    fn PdfDocument::contents_of_name_tree(self : PdfDocument, tree : PdfObject) -> Array[(PdfObject, PdfObject)]

    Return the immediate key-value pairs contained in a name or number tree.

    The tree may store entries directly in /Names or /Nums, or indirectly in child nodes under /Kids. Entries are returned as raw PdfObject pairs, so callers that need typed name or number keys should use read_name_tree or read_number_tree.

    PdfDocument::copy

    fn PdfDocument::copy(self : PdfDocument) -> PdfDocument

    Deep-copy the document object table and trailer.

    Parsed object containers and stream data are copied so mutations to the copy do not alter the original document's object graph.

    PdfDocument::decrypt_single_stream

    fn PdfDocument::decrypt_single_stream(self : PdfDocument, object_number : Int, generation : Int, stream : PdfObject, user_password? : BytesView?, owner_password? : BytesView?, no_encrypt_metadata? : Bool) -> PdfObject? raise PdfError

    Decrypt one encrypted stream object with available passwords.

    Unencrypted documents return stream unchanged. Encrypted documents return None when no supplied password authenticates. The caller supplies the stream object's number and generation because object keys depend on them.

    PdfDocument::decrypt_with_owner_password

    fn PdfDocument::decrypt_with_owner_password(self : PdfDocument, password : BytesView, no_encrypt_metadata? : Bool) -> PdfDecryptionResult? raise PdfError

    Decrypt with an owner password only.

    Unencrypted documents return a copied document and empty denied permissions. Encrypted documents return None when the owner password does not authenticate.

    PdfDocument::decrypt_with_passwords

    fn PdfDocument::decrypt_with_passwords(self : PdfDocument, user_password? : BytesView?, owner_password? : BytesView?, no_encrypt_metadata? : Bool) -> PdfDecryptionResult? raise PdfError

    Decrypt this document using optional user and owner passwords.

    If the document is not encrypted, a copied document and empty permissions list are returned. If it is encrypted and no password works, the result is None; malformed encryption data still raises PdfError.

    PdfDocument::decrypt_with_user_password

    fn PdfDocument::decrypt_with_user_password(self : PdfDocument, password : BytesView, no_encrypt_metadata? : Bool) -> PdfDecryptionResult? raise PdfError

    Decrypt with a user password only.

    Unencrypted documents return a copied document and empty denied permissions. Encrypted documents return None when the user password does not authenticate.

    PdfDocument::direct

    fn PdfDocument::direct(self : PdfDocument, object : PdfObject) -> PdfObject

    Resolve an object through the document object table.

    Direct objects are returned unchanged. Indirect references are followed recursively through parsed entries in self.objects; missing, unparsed, or excessively deep references resolve to PdfNull rather than raising.

    PdfDocument::encrypt_128bit

    fn PdfDocument::encrypt_128bit(self : PdfDocument, user_password : BytesView, owner_password : BytesView, denied_permissions : ArrayView[PdfPermission], file_id? : BytesView) -> PdfDocument raise PdfError

    Encrypt a copy of the document with the revision-3 128-bit ARC4 handler.

    denied_permissions is converted to the PDF /P mask. file_id can be supplied for deterministic output; when omitted, a generated file ID is added as needed.

    PdfDocument::encrypt_128bit_aesv2

    fn PdfDocument::encrypt_128bit_aesv2(self : PdfDocument, user_password : BytesView, owner_password : BytesView, denied_permissions : ArrayView[PdfPermission], encrypt_metadata? : Bool, file_id? : BytesView) -> PdfDocument raise PdfError

    Encrypt a copy of the document with revision-4 AESV2 using native randomness.

    Fresh random IVs are generated for encrypted strings and streams. When file_id is empty, a random 16-byte first trailer ID is generated before deriving the encryption key.

    PdfDocument::encrypt_128bit_aesv2_with_iv_provider

    fn PdfDocument::encrypt_128bit_aesv2_with_iv_provider(self : PdfDocument, user_password : BytesView, owner_password : BytesView, denied_permissions : ArrayView[PdfPermission], iv_provider : (Int, Int, Int) -> Bytes raise PdfError, encrypt_metadata? : Bool, file_id? : BytesView) -> PdfDocument raise PdfError

    Encrypt a copy of the document with revision-4 AESV2.

    iv_provider supplies per-object 16-byte CBC IVs by object number, generation, and IV index. This makes tests reproducible while allowing production callers to provide secure random IVs.

    PdfDocument::encrypt_128bit_r4

    fn PdfDocument::encrypt_128bit_r4(self : PdfDocument, user_password : BytesView, owner_password : BytesView, denied_permissions : ArrayView[PdfPermission], encrypt_metadata? : Bool, file_id? : BytesView) -> PdfDocument raise PdfError

    Encrypt a copy of the document with revision-4 128-bit ARC4.

    This writes a crypt-filter dictionary using /V2. encrypt_metadata=false follows the revision-4 no-metadata key derivation and stream policy.

    PdfDocument::encrypt_256bit_aesv3

    fn PdfDocument::encrypt_256bit_aesv3(self : PdfDocument, user_password : BytesView, owner_password : BytesView, denied_permissions : ArrayView[PdfPermission], iso? : Bool, encrypt_metadata? : Bool, file_id? : BytesView) -> PdfDocument raise PdfError

    Encrypt a copy of the document with AESV3/AES-256 using native randomness.

    Native random bytes supply the file key, salts, permissions padding, and per-object IVs. Set iso=true for the ISO/PDF 2.0 AESV3 hash variant.

    PdfDocument::encrypt_256bit_aesv3_iso

    fn PdfDocument::encrypt_256bit_aesv3_iso(self : PdfDocument, user_password : BytesView, owner_password : BytesView, denied_permissions : ArrayView[PdfPermission], encrypt_metadata? : Bool, file_id? : BytesView) -> PdfDocument raise PdfError

    Encrypt a copy of the document with the ISO AESV3/AES-256 variant.

    This is the native-random convenience wrapper for encrypt_256bit_aesv3 with iso=true.

    PdfDocument::encrypt_256bit_aesv3_iso_with_providers

    fn PdfDocument::encrypt_256bit_aesv3_iso_with_providers(self : PdfDocument, user_password : BytesView, owner_password : BytesView, denied_permissions : ArrayView[PdfPermission], random_provider : (PdfAesV3RandomField, Int) -> Bytes raise PdfError, iv_provider : (Int, Int, Int) -> Bytes raise PdfError, encrypt_metadata? : Bool, file_id? : BytesView) -> PdfDocument raise PdfError

    Encrypt a copy of the document with the ISO AESV3/AES-256 variant.

    This is a convenience wrapper around encrypt_256bit_aesv3_with_providers with iso=true.

    PdfDocument::encrypt_256bit_aesv3_with_providers

    fn PdfDocument::encrypt_256bit_aesv3_with_providers(self : PdfDocument, user_password : BytesView, owner_password : BytesView, denied_permissions : ArrayView[PdfPermission], random_provider : (PdfAesV3RandomField, Int) -> Bytes raise PdfError, iv_provider : (Int, Int, Int) -> Bytes raise PdfError, iso? : Bool, encrypt_metadata? : Bool, file_id? : BytesView) -> PdfDocument raise PdfError

    Encrypt a copy of the document with AESV3/AES-256 security.

    random_provider supplies the file key, salts, and permissions padding; iv_provider supplies CBC IVs for encrypted strings and streams. iso=true selects the ISO/PDF 2.0 hash variant.

    PdfDocument::encrypt_40bit

    fn PdfDocument::encrypt_40bit(self : PdfDocument, user_password : BytesView, owner_password : BytesView, denied_permissions : ArrayView[PdfPermission], file_id? : BytesView) -> PdfDocument raise PdfError

    Encrypt a copy of the document with the revision-2 40-bit ARC4 handler.

    denied_permissions is converted to the PDF /P mask. file_id can be supplied for deterministic output; when omitted, the document gets a CamlPDF-style generated file ID.

    PdfDocument::encryption_values

    fn PdfDocument::encryption_values(self : PdfDocument) -> PdfEncryptionValues raise PdfError

    Parse the document trailer's /Encrypt dictionary.

    The returned value contains the normalized security-handler parameters needed for authentication and object crypt. Missing encryption dictionaries, unsupported handlers, malformed /O or /U entries, and missing trailer /ID values raise PdfError.

    PdfDocument::endpage

    fn PdfDocument::endpage(self : PdfDocument) -> Int raise PdfError

    Return the number of pages by walking the page tree.

    PdfDocument::endpage_fast

    fn PdfDocument::endpage_fast(self : PdfDocument) -> Int raise PdfError

    Return the root page-tree /Count value without validating child pages.

    Missing or malformed counts return 0.

    PdfDocument::event_log

    fn PdfDocument::event_log(self : PdfDocument) -> Array[(Int, PdfObjectEvent)]

    Return a copy of the document object mutation log.

    PdfDocument::first_xref

    fn PdfDocument::first_xref(self : PdfDocument) -> Int

    Return the byte offset of the first xref section read from the input.

    PdfDocument::get_image_24bpp

    fn PdfDocument::get_image_24bpp(self : PdfDocument, resources : PdfObject, image : PdfObject) -> PdfImage raise PdfError

    Extract an image as either encoded image bytes or 24bpp RGB data.

    DCT/JPEG, JPX/JPEG2000, and JBIG2 streams are returned still encoded. Other supported image streams are decoded, have supported /Decode arrays applied, and are converted to PdfRawImage(width, height, PdfBPP24, data) where data is RGBRGB byte order.

    PdfDocument::get_number

    fn PdfDocument::get_number(self : PdfDocument, object : PdfObject) -> Double raise PdfError

    Read a PDF numeric object as a Double.

    The object is resolved first. PDF real numbers are returned directly and PDF integers are widened to Double; any other object raises NumberExpected.

    PdfDocument::image_bits_per_component

    fn PdfDocument::image_bits_per_component(self : PdfDocument, image : PdfObject) -> PdfObject?

    Return an image's /BitsPerComponent or abbreviated /BPC entry.

    Image masks default to 1 when no explicit value is present. The raw object is returned to preserve the PDF representation.

    PdfDocument::image_colour_space

    fn PdfDocument::image_colour_space(self : PdfDocument, image : PdfObject, resources : PdfObject) -> PdfColourSpace raise PdfError

    Read an image XObject colour space.

    /ImageMask true images are treated as PdfDeviceGray. Otherwise this reads /ColorSpace or /CS, resolving named spaces through resources.

    PdfDocument::indirect_number

    fn PdfDocument::indirect_number(self : PdfDocument, key : PdfName, object : PdfObject) -> Int?

    Return the indirect object number stored under a dictionary key.

    The containing object is resolved before lookup, but the entry itself is inspected before dereferencing. This returns Some(number) only when the immediate entry value is PdfIndirect(number).

    PdfDocument::is_cidkeyed_font

    fn PdfDocument::is_cidkeyed_font(self : PdfDocument, font : PdfObject) -> Bool

    Return true if a font dictionary is a Type 0 CID-keyed font.

    PdfDocument::is_encrypted

    fn PdfDocument::is_encrypted(self : PdfDocument) -> Bool

    Return true when the trailer contains an /Encrypt entry.

    PdfDocument::is_simple_font

    fn PdfDocument::is_simple_font(self : PdfDocument, font : PdfObject) -> Bool

    Return true if a font dictionary has a simple-font subtype.

    PdfDocument::is_standard14_font

    fn PdfDocument::is_standard14_font(self : PdfDocument, font : PdfObject) -> Bool

    Return true if a font dictionary is an unembedded standard 14 font.

    A matching Type1 or TrueType /BaseFont without explicit /Widths is treated as a standard-font dictionary.

    PdfDocument::iter_objects

    fn PdfDocument::iter_objects(self : PdfDocument, callback : (Int, PdfObject) -> Unit raise) -> Unit raise

    Iterate over parsed objects in object-number order.

    The callback receives (number, object). Errors raised by the callback propagate to the caller.

    PdfDocument::iter_objects_in_order

    fn PdfDocument::iter_objects_in_order(self : PdfDocument, callback : (Int, PdfObject) -> Unit raise) -> Unit raise

    Iterate over parsed objects in object-number order.

    This is the explicit-order variant used by iter_objects.

    PdfDocument::iter_objects_with_generation

    fn PdfDocument::iter_objects_with_generation(self : PdfDocument, callback : (Int, Int, PdfObject) -> Unit raise) -> Unit raise

    Iterate over parsed objects with their generation numbers.

    The callback receives (number, generation, object) in object-number order, and any callback error is propagated.

    PdfDocument::iter_stream

    fn PdfDocument::iter_stream(self : PdfDocument, callback : (PdfObject) -> Unit raise) -> Unit raise

    Iterate over parsed stream objects in object-number order.

    The callback receives the stream as a PdfObject so callers can use the same object-level helpers as for values read from arrays or dictionaries.

    PdfDocument::lookup_chain

    fn PdfDocument::lookup_chain(self : PdfDocument, start : PdfObject, keys : ArrayView[PdfName]) -> PdfObject?

    Follow a sequence of dictionary keys and array pseudo-keys.

    Lookup starts from start; every successful step resolves indirect objects. An empty key sequence returns Some(start). If any step cannot be resolved, the result is None.

    PdfDocument::lookup_direct

    fn PdfDocument::lookup_direct(self : PdfDocument, key : PdfName, object : PdfObject) -> PdfObject?

    Look up key in a dictionary or stream dictionary and resolve the value.

    The containing object is first passed through direct. If the object is not dictionary-like, the key is absent, or the resolved value is PdfNull, this returns None.

    PdfDocument::lookup_direct_or_array

    fn PdfDocument::lookup_direct_or_array(self : PdfDocument, name : PdfName, object : PdfObject) -> PdfObject?

    Look up a dictionary entry, or address an array by a pseudo-key.

    Names that begin with /[ followed by decimal digits are treated as array indexes when object is a PdfArray; other names are resolved with lookup_direct. The returned value is resolved through direct.

    PdfDocument::lookup_direct_or_else

    fn PdfDocument::lookup_direct_or_else(self : PdfDocument, first_key : PdfName, second_key : PdfName, object : PdfObject) -> PdfObject?

    Look up either of two alternative dictionary keys.

    first_key is preferred. second_key is checked only when the first lookup is absent or resolves to PdfNull.

    PdfDocument::lookup_object_or_null

    fn PdfDocument::lookup_object_or_null(self : PdfDocument, number : Int) -> PdfObject

    Return a parsed object by number, or PdfNull if it is absent or deferred.

    PdfDocument::lookup_required

    fn PdfDocument::lookup_required(self : PdfDocument, key : PdfName, object : PdfObject, error : PdfError) -> PdfObject raise PdfError

    Look up a required dictionary entry and resolve the value.

    This is the raising counterpart to lookup_direct: it raises the caller supplied error when the containing object is not dictionary-like, when the key is absent, or when the resolved value is PdfNull.

    PdfDocument::map_objects_in_place

    fn PdfDocument::map_objects_in_place(self : PdfDocument, transform : (PdfObject) -> PdfObject) -> Unit

    Transform every parsed document object in place.

    Deferred entries remain deferred and are not passed to transform.

    PdfDocument::merge_content_streams

    fn PdfDocument::merge_content_streams(self : PdfDocument) -> Unit raise PdfError

    Merge multi-stream page contents into single decoded streams.

    Only page-like objects with /Resources are considered. The document is mutated in place and stream filters are decoded before concatenation.

    PdfDocument::merge_name_trees_no_clash

    fn PdfDocument::merge_name_trees_no_clash(self : PdfDocument, trees : ArrayView[PdfObject]) -> PdfObject

    Merge several name trees when the caller guarantees there are no clashes.

    Entries are read from every input tree and rebuilt into a single sorted name tree. This function does not report duplicate keys; callers that require conflict handling should check the inputs before calling it.

    PdfDocument::merge_number_trees_no_clash

    fn PdfDocument::merge_number_trees_no_clash(self : PdfDocument, trees : ArrayView[PdfObject]) -> PdfObject

    Merge several number trees when the caller guarantees there are no clashes.

    Entries are read from every input tree and rebuilt into a single sorted number tree. Duplicate-key handling follows the read/build helpers and is not reported as an error.

    PdfDocument::name_tree_lookup

    fn PdfDocument::name_tree_lookup(self : PdfDocument, key : BytesView, tree : PdfObject) -> PdfObject?

    Look up a byte-string key in a PDF name tree.

    The BytesView key is copied into an owned PdfString because PDF objects own their byte storage. Prefer this method when the key is already available as PDF-encoded bytes.

    PdfDocument::name_tree_lookup_object

    fn PdfDocument::name_tree_lookup_object(self : PdfDocument, key : PdfObject, tree : PdfObject) -> PdfObject?

    Look up a raw key object in a PDF name tree or number tree.

    /Limits entries are used to skip child nodes when they are comparable with key. The lookup accepts both direct leaf arrays and nested /Kids nodes, returning None for malformed nodes or missing keys.

    PdfDocument::number_tree_lookup

    fn PdfDocument::number_tree_lookup(self : PdfDocument, key : Int, tree : PdfObject) -> PdfObject?

    Look up an integer key in a PDF number tree.

    PdfDocument::object_count

    fn PdfDocument::object_count(self : PdfDocument) -> Int

    Return the number of entries in the document object table.

    PdfDocument::object_numbers

    fn PdfDocument::object_numbers(self : PdfDocument) -> Array[Int]

    Return document object numbers in ascending order.

    PdfDocument::page_number_of_target

    fn PdfDocument::page_number_of_target(self : PdfDocument, destination : PdfDestination) -> Int raise PdfError

    Resolve a destination target to a 1-based page number.

    PdfDocument::page_object_number

    fn PdfDocument::page_object_number(self : PdfDocument, page_number : Int) -> Int? raise PdfError

    Return the object number for a 1-based page number.

    Out-of-range page numbers return None.

    PdfDocument::page_reference_numbers

    fn PdfDocument::page_reference_numbers(self : PdfDocument) -> Array[Int] raise PdfError

    Return page object numbers in page-tree order.

    PdfDocument::pages_of_pagetree

    fn PdfDocument::pages_of_pagetree(self : PdfDocument) -> Array[PdfPage] raise PdfError

    Read the document page tree into PdfPage records.

    Inherited resources, media boxes, crop boxes, and rotation are resolved while walking the tree. Malformed page-tree structure raises PdfError.

    PdfDocument::pages_of_pagetree_quick

    fn PdfDocument::pages_of_pagetree_quick(self : PdfDocument) -> Int raise PdfError

    Count pages by walking the page tree without materializing PdfPage records.

    PdfDocument::parse_cmap

    fn PdfDocument::parse_cmap(self : PdfDocument, cmap : PdfObject) -> PdfParsedCMap raise PdfError

    Decode and parse a CMap stream object in this document.

    The stream is decoded through its first filter, stream-dictionary metadata is merged with parsed metadata, and indirect /UseCMap bases are composed with cycle protection. Malformed or non-stream inputs raise PdfError.

    PdfDocument::parse_content_bytes_with_resources

    fn PdfDocument::parse_content_bytes_with_resources(self : PdfDocument, resources : PdfObject, data : Bytes) -> Array[PdfContentOp] raise PdfError

    Parse content bytes with page resources.

    This is the owned-byte wrapper for parse_content_view_with_resources.

    PdfDocument::parse_content_ops

    fn PdfDocument::parse_content_ops(self : PdfDocument, streams : ArrayView[PdfObject]) -> Array[PdfContentOp] raise PdfError

    Decode and parse a list of content stream objects from this document.

    Each input must resolve to a stream object. Stream filters are decoded before parsing, then the decoded streams are concatenated with whitespace. Use parse_content_ops_with_resources when inline-image length inference needs page resources.

    PdfDocument::parse_content_ops_with_resources

    fn PdfDocument::parse_content_ops_with_resources(self : PdfDocument, resources : PdfObject, streams : ArrayView[PdfObject]) -> Array[PdfContentOp] raise PdfError

    Decode and parse content stream objects with page resources.

    The resource dictionary is used for inline-image color-space component lookup when an unfiltered inline image has no reliable declared length.

    PdfDocument::parse_content_view_with_resources

    fn PdfDocument::parse_content_view_with_resources(self : PdfDocument, resources : PdfObject, data : BytesView) -> Array[PdfContentOp] raise PdfError

    Parse a content byte view with page resources.

    The input view is read directly; returned operators own any byte data they need to keep, such as text strings and inline-image data.

    PdfDocument::parse_function

    fn PdfDocument::parse_function(self : PdfDocument, function_object : PdfObject) -> PdfFunction raise PdfError

    Parse a PDF function object from this document.

    Supports PDF function types 0, 2, 3, and 4. Sampled and calculator functions are read from decoded stream data; interpolation and stitching functions are read from dictionaries. Raises for malformed dictionaries, invalid arities, stream decoding failures, or unsupported function types.

    PdfDocument::parse_matrix

    fn PdfDocument::parse_matrix(self : PdfDocument, key : PdfName, object : PdfObject) -> TransformMatrix raise PdfError

    Read a transformation matrix from a dictionary entry.

    If key is absent, the identity matrix is returned. Present values must be arrays of six numbers in PDF matrix order [a b c d e f]; malformed arrays raise MatrixMalformed, and non-numeric entries raise NumberExpected.

    PdfDocument::parse_rectangle

    fn PdfDocument::parse_rectangle(self : PdfDocument, object : PdfObject) -> PdfRectangle raise PdfError

    Parse and normalize a PDF rectangle array.

    The input must resolve to an array of four numeric objects. Coordinates are normalized so the result always has lower bounds in min_x/min_y and upper bounds in max_x/max_y. Non-array inputs raise RectangleExpected; malformed numeric entries raise BadRectangle.

    PdfDocument::parsed_object_entries

    fn PdfDocument::parsed_object_entries(self : PdfDocument) -> Array[(Int, Int, PdfObject)]

    Return parsed document objects as sorted (number, generation, object) triples.

    PdfDocument::pdf_decode_stream

    fn PdfDocument::pdf_decode_stream(self : PdfDocument, object : PdfObject) -> PdfObject raise PdfError

    Decode all supported filter stages from a stream object in this document.

    Indirect filter and decode-parameter objects are resolved through the document. Unsupported filters raise FilterNotSupported.

    PdfDocument::pdf_decode_stream_until_unknown

    fn PdfDocument::pdf_decode_stream_until_unknown(self : PdfDocument, object : PdfObject) -> PdfObject raise PdfError

    Decode supported filter stages until the first unsupported filter.

    The unsupported filter and remaining filters stay in the stream dictionary; malformed supported filters still raise.

    PdfDocument::pdf_decode_streams_until_unknown

    fn PdfDocument::pdf_decode_streams_until_unknown(self : PdfDocument) -> Unit raise PdfError

    Decode supported filter stages on every parsed stream in the document.

    Streams already marked as decrypted stay in that state. Objects are updated in place and logged as altered when their stream data changes.

    PdfDocument::pdf_object_of_function

    fn PdfDocument::pdf_object_of_function(self : PdfDocument, function : PdfFunction) -> PdfObject

    Build a PDF object for a parsed function.

    Interpolation functions are written as dictionaries. Stitching functions add child function objects to this document and reference them from the returned dictionary. Sampled and calculator variants currently write only the common function dictionary fields and do not recreate their stream data.

    PdfDocument::pdf_of_pages

    fn PdfDocument::pdf_of_pages(self : PdfDocument, page_numbers : ArrayView[Int], retain_numbering? : Bool, process_struct_tree? : Bool) -> PdfDocument raise PdfError

    Extract selected pages into a new document.

    page_numbers are 1-based. Bookmarks, destinations, annotations, and page labels are repaired for the retained pages where possible. retain_numbering preserves original page-label numbering; process_struct_tree trims tagged structure references to deleted pages.

    PdfDocument::permissions

    fn PdfDocument::permissions(self : PdfDocument) -> Array[PdfPermission] raise PdfError

    Decode the denied permissions from the document encryption dictionary.

    Unencrypted documents return an empty array. Encrypted documents parse /Encrypt and may raise if the encryption dictionary is malformed.

    PdfDocument::postpend_operators

    fn PdfDocument::postpend_operators(self : PdfDocument, page : PdfPage, ops : ArrayView[PdfContentOp], fast? : Bool) -> PdfPage raise PdfError

    Append content operators to a page.

    Normal mode parses existing content and wraps it with graphics-state protection before appending ops. fast mode appends a protected new stream without parsing existing content.

    PdfDocument::prepend_operators

    fn PdfDocument::prepend_operators(self : PdfDocument, page : PdfPage, ops : ArrayView[PdfContentOp], fast? : Bool) -> PdfPage raise PdfError

    Prepend content operators to a page.

    In normal mode existing content is parsed and merged into a single stream after ops. In fast mode a new stream is inserted before existing content without parsing the old streams.

    PdfDocument::process_xobjects

    fn PdfDocument::process_xobjects(self : PdfDocument, page : PdfPage, process : (PdfDocument, PdfObject, ArrayView[PdfObject]) -> Array[PdfObject] raise PdfError) -> Unit raise PdfError

    Process Form XObjects referenced by a page resource dictionary.

    For each indirect /XObject with subtype /Form, process receives the document, page resources, and the form stream. It must return exactly one processed stream, which replaces the original form stream data.

    PdfDocument::read_annotation

    fn PdfDocument::read_annotation(self : PdfDocument, annotation : PdfObject) -> PdfAnnotation raise PdfError

    Read one annotation dictionary from this document.

    The annotation object may be direct or indirect. /Rect is required. Popup parents are resolved recursively up to a bounded depth to avoid cycles.

    PdfDocument::read_bookmarks

    fn PdfDocument::read_bookmarks(self : PdfDocument, preserve_actions? : Bool) -> Array[PdfBookmark] raise PdfError

    Read the document outline tree as flattened bookmarks.

    When preserve_actions is false, actions with destinations are resolved to destinations where possible. When it is true, action dictionaries and named destinations are preserved more shallowly for round-tripping.

    PdfDocument::read_cid_system_info

    fn PdfDocument::read_cid_system_info(self : PdfDocument, dictionary : PdfObject) -> PdfCIDSystemInfo raise PdfError

    Read a CID-system-info dictionary.

    Registry and ordering are returned as byte strings, matching PDF string semantics. Missing or malformed required fields raise PdfError.

    PdfDocument::read_cidkeyed_font

    fn PdfDocument::read_cidkeyed_font(self : PdfDocument, font : PdfObject) -> PdfCIDKeyedFont raise PdfError

    Parse a Type 0 font dictionary into a CID-keyed font.

    This reads the descendant CIDFont, width data, descriptor, base font, and CMap encoding. External CMap streams are parsed when possible while still preserving the referenced stream object number.

    PdfDocument::read_colour_space

    fn PdfDocument::read_colour_space(self : PdfDocument, resources : PdfObject, object : PdfObject) -> PdfColourSpace? raise PdfError

    Parse a colour-space object using the document and resource dictionary.

    The parser resolves resource colour-space names and supports device spaces, pattern spaces with a base space, calibrated Gray/RGB/Lab spaces, ICCBased spaces, Indexed spaces, Separation spaces, and DeviceN spaces. Unsupported or malformed colour spaces return None; malformed numeric fields may raise PdfError.

    PdfDocument::read_destination

    fn PdfDocument::read_destination(self : PdfDocument, object : PdfObject, shallow? : Bool) -> PdfDestination raise PdfError

    Reads and normalizes a PDF destination object.

    When shallow is false, named and string destinations are resolved through the document catalog when possible. Unknown or malformed destination shapes are represented as DestNull.

    PdfDocument::read_encoding

    fn PdfDocument::read_encoding(self : PdfDocument, font : PdfObject) -> PdfEncoding raise PdfError

    Read the simple-font encoding from a font dictionary.

    Name encodings are recognized directly. Encoding dictionaries combine /BaseEncoding and /Differences; TrueType encodings additionally fall back to StandardEncoding for undefined entries. Missing or unrecognized encodings use PdfImplicitInFontFile.

    PdfDocument::read_font

    fn PdfDocument::read_font(self : PdfDocument, font : PdfObject) -> PdfFont raise PdfError

    Read any supported PDF font dictionary.

    The result is classified as standard 14, simple, or CID-keyed. A /ToUnicode stream, when present and parseable, is attached to the parsed font so extractors prefer explicit Unicode mappings.

    PdfDocument::read_font_descriptor

    fn PdfDocument::read_font_descriptor(self : PdfDocument, font : PdfObject) -> PdfFontDescriptor? raise PdfError

    Read the /FontDescriptor dictionary attached to a font.

    Missing descriptors return None. Present descriptors are parsed tolerantly for optional numeric fields, while malformed required shapes such as an invalid /FontBBox still raise through the underlying object readers.

    PdfDocument::read_font_metrics

    fn PdfDocument::read_font_metrics(self : PdfDocument, font : PdfObject) -> Array[Double]? raise PdfError

    Read normalized one-byte font metrics for a simple or Type 3 font.

    The result contains 256 entries when /Widths, /FirstChar, and /LastChar are present and well formed. Missing metrics return None; malformed bounds or width arrays raise the corresponding font error.

    PdfDocument::read_name_tree

    fn PdfDocument::read_name_tree(self : PdfDocument, tree : PdfObject) -> Array[(Bytes, PdfObject)]

    Read all entries from a PDF name tree as sorted byte-string keys.

    Malformed trees whose keys are not PdfString values return an empty array. Well-formed entries are sorted by byte order and duplicate keys are collapsed by the deduplication pass.

    PdfDocument::read_number_tree

    fn PdfDocument::read_number_tree(self : PdfDocument, tree : PdfObject) -> Array[(Int, PdfObject)]

    Read all entries from a PDF number tree as sorted integer keys.

    Malformed trees whose keys are not PdfInteger values return an empty array. Well-formed entries are sorted numerically and duplicate keys are collapsed by the deduplication pass.

    PdfDocument::read_optional_content_groups

    fn PdfDocument::read_optional_content_groups(self : PdfDocument) -> PdfOptionalContent? raise PdfError

    Read catalog /OCProperties from the document.

    Returns None when the catalog has no optional-content properties. When properties are present, OCG entries are returned with their indirect object numbers so callers can preserve or renumber references before writing.

    PdfDocument::read_page_labels

    fn PdfDocument::read_page_labels(self : PdfDocument) -> Array[PdfPageLabel] raise PdfError

    Read the document catalog /PageLabels number tree.

    The returned start_page values are converted from PDF's zero-based page indexes to the public 1-based page numbering used by this module. Documents without page labels return an empty array.

    PdfDocument::read_simple_font

    fn PdfDocument::read_simple_font(self : PdfDocument, font : PdfObject) -> PdfSimpleFont raise PdfError

    Parse a simple-font dictionary.

    Supported subtypes are Type1, MMType1, Type3, and TrueType. The returned value includes optional descriptors, metrics, Type 3 CharProc data, and the resolved simple-font encoding.

    PdfDocument::read_standard14_font

    fn PdfDocument::read_standard14_font(self : PdfDocument, font : PdfObject) -> PdfStandardFontData raise PdfError

    Read a standard 14 font dictionary.

    The dictionary must contain a recognized /BaseFont; its encoding is read with read_encoding so custom differences are preserved.

    PdfDocument::recrypt_with_password

    fn PdfDocument::recrypt_with_password(self : PdfDocument, password : BytesView) -> PdfDocument raise PdfError

    Re-encrypt a previously decrypted document using its saved ARC4 settings.

    The document must have saved encryption state from a successful decrypt. The supplied password is authenticated against that state before the original encryption dictionary shape is restored.

    PdfDocument::recrypt_with_password_aesv2

    fn PdfDocument::recrypt_with_password_aesv2(self : PdfDocument, password : BytesView) -> PdfDocument raise PdfError

    Re-encrypt a decrypted AESV2 document using native random IVs.

    The document must carry saved encryption state from a previous decrypt operation; password is used to recover the file key for re-encryption.

    PdfDocument::recrypt_with_password_aesv2_with_iv_provider

    fn PdfDocument::recrypt_with_password_aesv2_with_iv_provider(self : PdfDocument, password : BytesView, iv_provider : (Int, Int, Int) -> Bytes raise PdfError) -> PdfDocument raise PdfError

    Re-encrypt a decrypted AESV2 document using its saved encryption settings.

    iv_provider supplies fresh IVs for encrypted object data. The saved encryption state determines passwords, permissions, and crypt-filter shape.

    PdfDocument::recrypt_with_password_aesv3

    fn PdfDocument::recrypt_with_password_aesv3(self : PdfDocument, password : BytesView) -> PdfDocument raise PdfError

    Re-encrypt a decrypted AESV3 document using native random IVs.

    The document must carry saved encryption state from a previous decrypt operation; password is used to recover the file key for re-encryption.

    PdfDocument::recrypt_with_password_aesv3_with_iv_provider

    fn PdfDocument::recrypt_with_password_aesv3_with_iv_provider(self : PdfDocument, password : BytesView, iv_provider : (Int, Int, Int) -> Bytes raise PdfError) -> PdfDocument raise PdfError

    Re-encrypt a decrypted AESV3 document using its saved encryption settings.

    iv_provider supplies fresh IVs for encrypted object data. The saved encryption state supplies the existing AESV3 password entries and file key wrapping metadata.

    PdfDocument::referenced_object_numbers

    fn PdfDocument::referenced_object_numbers(self : PdfDocument, object : PdfObject, no_follow_entries? : ArrayView[PdfName], no_follow_contains? : ArrayView[(PdfName, PdfObject)]) -> Array[Int]

    Returns sorted object numbers reachable from object.

    Indirect references are followed through the document. Dictionary keys in no_follow_entries are skipped, and dictionaries containing any no_follow_contains marker entry are not traversed.

    PdfDocument::remove_bookmarks

    fn PdfDocument::remove_bookmarks(self : PdfDocument) -> PdfDocument raise PdfError

    Return a copy of the document with catalog /Outlines removed.

    The original document is not mutated; the returned document has a new root object and trailer root reference.

    PdfDocument::remove_chain

    fn PdfDocument::remove_chain(self : PdfDocument, chain : ArrayView[PdfName]) -> Bool raise PdfError

    Remove a nested value along a path rooted at the trailer dictionary.

    Returns true when an entry was removed and false when the path is absent. Empty chains raise DictionaryExpected. A single-key chain is treated as an invalid request when the key exists, preserving the trailer root rather than removing one of its direct entries.

    PdfDocument::remove_duplicate_fonts

    fn PdfDocument::remove_duplicate_fonts(self : PdfDocument) -> Unit

    Removes duplicate embedded font streams from this document.

    Streams are considered duplicates when both their dictionaries and decoded byte payloads match. References to duplicate streams are rewired to the first matching stream and duplicate objects are removed.

    PdfDocument::remove_object

    fn PdfDocument::remove_object(self : PdfDocument, number : Int) -> Unit

    Remove an object from the document and record a deletion event.

    PdfDocument::remove_optional_content_groups

    fn PdfDocument::remove_optional_content_groups(self : PdfDocument) -> PdfDocument raise PdfError

    Return a copy of the document with catalog /OCProperties removed.

    The original document is not mutated; the returned document receives a new root object and trailer root reference.

    PdfDocument::remove_page_labels

    fn PdfDocument::remove_page_labels(self : PdfDocument) -> PdfDocument raise PdfError

    Return a copy of the document with catalog /PageLabels removed.

    The original document is not mutated; the returned document has a new root object and trailer root reference.

    PdfDocument::remove_unreferenced

    fn PdfDocument::remove_unreferenced(self : PdfDocument) -> Unit raise PdfError

    Remove objects that are no longer reachable from the trailer or root.

    References to deleted pages are first nulled from destinations and actions. The document is mutated in place.

    PdfDocument::renumber_objects

    fn PdfDocument::renumber_objects(self : PdfDocument, changes : ArrayView[(Int, Int)]) -> PdfDocument raise PdfError

    Return a copy of the document with object numbers remapped.

    changes maps old object numbers to new object numbers; omitted objects keep their original number. All indirect references, the root reference, trailer dictionary, and object-stream metadata are updated. Duplicate or nonpositive target numbers raise InvalidObjectNumber.

    PdfDocument::renumber_objects_by_offset

    fn PdfDocument::renumber_objects_by_offset(self : PdfDocument, offset : Int) -> PdfDocument raise PdfError

    Return a copy with every object number increased by offset.

    offset == 0 returns a plain copy. Negative offsets raise InvalidObjectNumber.

    PdfDocument::renumber_objects_compact

    fn PdfDocument::renumber_objects_compact(self : PdfDocument) -> PdfDocument raise PdfError

    Return a copy whose objects are numbered compactly from 1 in object order.

    PdfDocument::renumber_pages

    fn PdfDocument::renumber_pages(self : PdfDocument, pages : ArrayView[PdfPage]) -> Array[PdfPage] raise PdfError

    Rename page resources so every page has independent resource names.

    Content streams and inline-image dictionaries are rewritten to use the new names, and each page resource dictionary is updated. This returns new page records; the source document object table is not rewritten.

    PdfDocument::replace_chain

    fn PdfDocument::replace_chain(self : PdfDocument, chain : ArrayView[PdfName], value : PdfObject) -> Unit raise PdfError

    Replace a value along a path rooted at the document trailer dictionary.

    Each name in chain selects a dictionary entry. Names of the form /[n] select array entries. Missing intermediate dictionary entries are created as nested dictionaries, and indirect intermediate objects are updated in the document object table. Raises when the chain is empty or when a non-container or invalid array position is encountered.

    PdfDocument::replace_inherit

    fn PdfDocument::replace_inherit(self : PdfDocument, object_numbers : ArrayView[Int]) -> Unit raise PdfError

    Materialize inherited page attributes onto page dictionaries.

    For each object number, inherited /MediaBox, /CropBox, /Rotate, and /Resources values are copied onto the page object when available. This is useful before page extraction or object-level rewriting.

    PdfDocument::revision_read

    fn PdfDocument::revision_read(self : PdfDocument) -> Int

    Return the number of document revisions read from the input.

    PdfDocument::root

    fn PdfDocument::root(self : PdfDocument) -> Int

    Return the catalog root object number tracked on the document.

    PdfDocument::saved_encryption

    fn PdfDocument::saved_encryption(self : PdfDocument) -> PdfSavedEncryption?

    Return saved encryption metadata, if the document is encrypted.

    PdfDocument::select_object_numbers

    fn PdfDocument::select_object_numbers(self : PdfDocument, predicate : (PdfObject) -> Bool) -> Array[Int]

    Return parsed object numbers whose objects satisfy predicate.

    Deferred objects are not loaded by this helper. Results follow ascending object-number order.

    PdfDocument::set_first_xref

    fn PdfDocument::set_first_xref(self : PdfDocument, first_xref : Int) -> Unit

    Set the byte offset of the first xref section read from the input.

    PdfDocument::set_revision_read

    fn PdfDocument::set_revision_read(self : PdfDocument, revision_read : Int) -> Unit

    Set the number of document revisions read from the input.

    PdfDocument::set_root

    fn PdfDocument::set_root(self : PdfDocument, root : Int) -> Unit

    Set the catalog root object number.

    PdfDocument::set_saved_encryption

    fn PdfDocument::set_saved_encryption(self : PdfDocument, saved_encryption : PdfSavedEncryption?) -> Unit

    Set saved encryption metadata for the document.

    PdfDocument::set_trailer_dict

    fn PdfDocument::set_trailer_dict(self : PdfDocument, trailer_dict : PdfObject) -> Unit

    Replace the document trailer dictionary object.

    PdfDocument::set_version

    fn PdfDocument::set_version(self : PdfDocument, major : Int, minor : Int) -> Unit

    Set the PDF version stored on the document.

    PdfDocument::set_was_linearized

    fn PdfDocument::set_was_linearized(self : PdfDocument, was_linearized : Bool) -> Unit

    Set whether the source PDF was marked as linearized.

    PdfDocument::shortest_unused_prefix

    fn PdfDocument::shortest_unused_prefix(self : PdfDocument) -> String

    Return the shortest ASCII prefix unused by page resource names.

    The prefix is suitable for add_prefix when merging pages from independent documents with potentially colliding resource names.

    PdfDocument::stream_object_entries

    fn PdfDocument::stream_object_entries(self : PdfDocument) -> Array[(Int, Int, PdfStream)]

    Return parsed stream-object entries in object-number order.

    PdfDocument::target_of_page_number

    fn PdfDocument::target_of_page_number(self : PdfDocument, page_number : Int) -> PdfDestination raise PdfError

    Build a fit destination for a 1-based page number.

    Out-of-range page numbers return DestNull.

    PdfDocument::text_extractor_of_font

    fn PdfDocument::text_extractor_of_font(self : PdfDocument, font : PdfObject) -> PdfTextExtractor raise PdfError

    Read a font dictionary and return a text extractor for it.

    PdfDocument::trailer_dict

    fn PdfDocument::trailer_dict(self : PdfDocument) -> PdfObject

    Return the current trailer dictionary object.

    The returned object may share mutable container state with the document.

    PdfDocument::transform_annotations

    fn PdfDocument::transform_annotations(self : PdfDocument, matrix : TransformMatrix, rest : PdfObject) -> Unit raise PdfError

    Transform annotation geometry referenced by a page dictionary.

    Applies matrix to /Rect, /QuadPoints, and /L entries. Indirect annotations are updated in this document; direct annotation dictionaries in the page's /Annots array are updated in place.

    PdfDocument::transform_bookmark

    fn PdfDocument::transform_bookmark(self : PdfDocument, matrix : TransformMatrix, bookmark : PdfBookmark) -> PdfBookmark raise PdfError

    Transform a bookmark destination by a matrix.

    Only the destination is changed; level, text, open state, colour, and flags are preserved.

    PdfDocument::transform_destination

    fn PdfDocument::transform_destination(self : PdfDocument, matrix : TransformMatrix, destination : PdfDestination) -> PdfDestination raise PdfError

    Applies a page transform matrix to destination coordinates.

    Only destinations tied to page objects are transformed. Named destinations, string destinations, non-page-number actions, and already page-number-based targets are preserved.

    PdfDocument::transform_quadpoints

    fn PdfDocument::transform_quadpoints(self : PdfDocument, matrix : TransformMatrix, object : PdfObject) -> PdfObject

    Transform PDF annotation quadpoints in groups of eight coordinates.

    Each complete group is interpreted as four (x, y) pairs and transformed by matrix. A complete group containing a non-numeric value is preserved unchanged, as is any trailing partial group. Non-array inputs are returned unchanged.

    PdfDocument::transform_rect

    fn PdfDocument::transform_rect(self : PdfDocument, matrix : TransformMatrix, object : PdfObject) -> PdfObject raise PdfError

    Transform a rectangle and return the bounding PDF rectangle array.

    All four corners are transformed with matrix, then the axis-aligned bounds of those transformed points are written as [minX minY maxX maxY].

    PdfDocument::trim_structure_tree

    fn PdfDocument::trim_structure_tree(self : PdfDocument, page_numbers : ArrayView[Int]) -> Unit raise PdfError

    Trim structure-tree entries that point to pages outside the selected pages.

    page_numbers uses the same page-selection numbering as the page helpers. The document is mutated in place by deleting structure objects tied to removed pages and pruning /K arrays that reference them.

    PdfDocument::version

    fn PdfDocument::version(self : PdfDocument) -> (Int, Int)

    Return the PDF version as (major, minor).

    PdfDocument::was_linearized

    fn PdfDocument::was_linearized(self : PdfDocument) -> Bool

    Return whether the source PDF was marked as linearized.

    PdfDocument::what_encryption

    fn PdfDocument::what_encryption(self : PdfDocument) -> PdfEncryptionMethod? raise PdfError

    Return the document encryption method, or None for unencrypted documents.

    Unknown or unsupported encryption dictionaries may also return None after the dictionary has been parsed.

    PdfDocument::write_colour_space

    fn PdfDocument::write_colour_space(_self : PdfDocument, space : PdfColourSpace) -> PdfObject

    Serialize a colour space for writing into a PDF object graph.

    This delegates to pdf_object_of_colour_space and returns PdfNull when the parsed colour space is not representable as a valid PDF object.

    PdfDocument::write_encoding

    fn PdfDocument::write_encoding(self : PdfDocument, encoding : PdfEncoding) -> Int raise PdfError

    Write a custom encoding dictionary and return its object number.

    Currently this supports /Differences over an implicit base encoding, which is the form needed by the font writer. Unsupported encodings raise EncodingWriteUnsupported.

    PdfDocument::write_font

    fn PdfDocument::write_font(self : PdfDocument, font : PdfFont, objnum? : Int?) -> Int raise PdfError

    Write a parsed font into the document and return its object number.

    Standard fonts, Type 3 fonts with descriptors, and TrueType fonts with descriptors are supported. objnum can force the destination object number for rewrite workflows. Unsupported font shapes raise FontWriteUnsupported.

    PdfDocument::write_optional_content_groups

    fn PdfDocument::write_optional_content_groups(self : PdfDocument, optional_content : PdfOptionalContent) -> PdfDocument raise PdfError

    Return a copy of the document with catalog /OCProperties replaced.

    OCG dictionaries are written using the object numbers stored in optional_content.ocgs. Configuration dictionaries are added as new objects, and the original document is left unchanged.

    PdfDocument::write_page_labels

    fn PdfDocument::write_page_labels(self : PdfDocument, labels : ArrayView[PdfPageLabel]) -> PdfDocument raise PdfError

    Return a copy of the document with catalog /PageLabels replaced.

    Public start_page values are written as zero-based PDF number-tree keys. Passing an empty label list removes any existing page-label tree.

    PdfEncoding

    pub(all) enum PdfEncoding {
    PdfImplicitInFontFile
    PdfStandardEncoding
    PdfMacRomanEncoding
    PdfWinAnsiEncoding
    PdfMacExpertEncoding
    PdfCustomEncoding(PdfEncoding, Array[PdfEncodingDifference])
    PdfFillUndefinedWithStandard(PdfEncoding)
    } derive(Eq, ToJson,
    Debug
    )

    Simple-font character encoding.

    PdfCustomEncoding layers /Differences over a base encoding. PdfFillUndefinedWithStandard models TrueType behavior where undefined entries fall back to StandardEncoding.

    PdfEncoding::debug_name

    fn PdfEncoding::debug_name(self : PdfEncoding) -> String

    Return a human-readable encoding label.

    PdfEncoding::pdf_name

    fn PdfEncoding::pdf_name(self : PdfEncoding) -> PdfName?

    Return the PDF name for a built-in simple-font encoding.

    Custom, implicit, and fallback encodings do not have a direct PDF name and return None.

    PdfEncoding::reverse_table

    fn PdfEncoding::reverse_table(self : PdfEncoding) -> Array[(PdfName, Int)]

    Expand this encoding to glyph-name to character-code entries.

    The order follows table; duplicate glyph names are preserved rather than collapsed.

    PdfEncoding::table

    fn PdfEncoding::table(self : PdfEncoding) -> Array[(Int, PdfName)]

    Expand this encoding to a table of defined character-code to glyph-name entries.

    Only codes with a known glyph name are emitted. The table is ordered by increasing one-byte character code.

    PdfEncodingDifference

    pub(all) struct PdfEncodingDifference {
    name : PdfName
    code : Int
    } derive(Eq, ToJson,
    Debug
    )

    One /Differences entry in a simple-font encoding dictionary.

    code is the one-byte character code that maps to name.

    PdfEncryptionMethod

    pub(all) enum PdfEncryptionMethod {
    PdfEncryption40Bit
    PdfEncryption128Bit
    PdfEncryptionAES128(Bool)
    PdfEncryptionAES256(Bool)
    PdfEncryptionAES256ISO(Bool)
    PdfEncryptionAlreadyEncrypted
    } derive(Eq, ToJson,
    Debug
    )

    Encryption method detected from or requested for a document.

    AES entries carry the effective EncryptMetadata flag. The PdfEncryptionAlreadyEncrypted value is used by writer paths that preserve existing encrypted object data rather than decrypting and re-encrypting it.

    PdfEncryptionValues

    pub(all) struct PdfEncryptionValues {
    crypt_type : PdfCryptType
    user_entry : Bytes
    owner_entry : Bytes
    permissions : Int
    file_id : Bytes
    encrypt_metadata : Bool
    permissions_entry : Bytes?
    user_encryption_key : Bytes?
    owner_encryption_key : Bytes?
    } derive(Eq, ToJson,
    Debug
    )

    Parsed standard-security-handler values from an encryption dictionary.

    Password entries, permission masks, file IDs, and optional AESV3 wrapping entries are stored as PDF bytes. crypt_type describes the actual object encryption algorithm used for strings and streams.

    PdfEncryptionValues::authenticate_owner_password

    fn PdfEncryptionValues::authenticate_owner_password(self : PdfEncryptionValues, password : BytesView, no_encrypt_metadata? : Bool) -> Bool raise PdfError

    Authenticate an owner password against parsed encryption values.

    For pre-AESV3 handlers this first recovers the padded user password from the owner entry, then authenticates it as a user password.

    PdfEncryptionValues::authenticate_user_password

    fn PdfEncryptionValues::authenticate_user_password(self : PdfEncryptionValues, password : BytesView, no_encrypt_metadata? : Bool) -> Bool raise PdfError

    Authenticate a user password against parsed encryption values.

    password is the raw PDF password byte sequence. AESV3 and earlier revisions use their respective standard-security algorithms. The optional metadata flag can force the revision-4 no-metadata key derivation path.

    PdfEncryptionValues::file_key_for_owner_password

    fn PdfEncryptionValues::file_key_for_owner_password(self : PdfEncryptionValues, password : BytesView, no_encrypt_metadata? : Bool) -> Bytes? raise PdfError

    Return the file key for a valid owner password.

    A wrong password returns None; malformed encryption values or corrupt AESV3 permission entries raise PdfError.

    PdfEncryptionValues::file_key_for_user_password

    fn PdfEncryptionValues::file_key_for_user_password(self : PdfEncryptionValues, password : BytesView, no_encrypt_metadata? : Bool) -> Bytes? raise PdfError

    Return the file key for a valid user password.

    A wrong password returns None; malformed encryption values or corrupt AESV3 permission entries raise PdfError.

    PdfFont

    pub(all) enum PdfFont {
    PdfFontStandard(PdfStandardFontData)
    PdfFontSimple(PdfSimpleFont)
    PdfFontCIDKeyed(PdfCIDKeyedFont)
    } derive(Eq, ToJson,
    Debug
    )

    Parsed font model used by text extraction and font writing.

    PdfFont::debug_name

    fn PdfFont::debug_name(self : PdfFont) -> String

    Return a human-readable label for a parsed font.

    PdfFont::is_identity_h

    fn PdfFont::is_identity_h(self : PdfFont) -> Bool

    Test whether this font is a Type 0 font using /Identity-H.

    PdfFont::is_identity_v

    fn PdfFont::is_identity_v(self : PdfFont) -> Bool

    Test whether this font is a Type 0 font using /Identity-V.

    PdfFont::text_extractor

    fn PdfFont::text_extractor(self : PdfFont) -> PdfTextExtractor

    Build a text extractor for an already parsed font.

    PdfFont::uses_two_byte_codes

    fn PdfFont::uses_two_byte_codes(self : PdfFont) -> Bool

    Return true when this font consumes fixed two-byte text character codes.

    PdfFontDescriptor

    pub(all) struct PdfFontDescriptor {
    ascent : Double
    descent : Double
    avgwidth : Double
    maxwidth : Double
    flags : Int
    fontbbox : PdfRectangle
    italicangle : Double
    capheight : Double
    xheight : Double
    stemv : Double
    fontfile : PdfFontFile?
    charset : Array[PdfName]?
    tounicode : Array[(Int, Bytes)]?
    } derive(Eq, ToJson,
    Debug
    )

    Parsed PDF font descriptor metrics and optional embedded font metadata.

    Numeric fields use PDF glyph-space units. tounicode stores decoded /ToUnicode mappings when the surrounding font dictionary provides them, so text extraction can prefer explicit Unicode mappings over glyph names.

    PdfFontFile

    pub(all) enum PdfFontFile {
    PdfFontFile(Int)
    PdfFontFile2(Int)
    PdfFontFile3(Int)
    } derive(Eq, ToJson,
    Debug
    )

    Reference to an embedded font program stream in a font descriptor.

    The integer is the object number for /FontFile, /FontFile2, or /FontFile3; the constructor records which descriptor key supplied it.

    PdfFunction

    pub(all) struct PdfFunction {
    func : PdfFunctionKind
    domain : Array[Double]
    range : Array[Double]?
    } derive(Eq, ToJson,
    Debug
    )

    Parsed PDF function with common domain and optional output range.

    domain is stored as low/high pairs, one pair per input. range, when present, is stored as output low/high pairs and is used to clamp evaluation results.

    PdfFunction::debug_string

    fn PdfFunction::debug_string(self : PdfFunction) -> String

    Format a parsed function as multi-line diagnostic text.

    The output follows CamlPDF's debug printer shape and is intended for inspection, not for writing a PDF function object.

    PdfFunction::eval

    fn PdfFunction::eval(self : PdfFunction, inputs : ArrayView[Double]) -> Array[Double] raise PdfError

    Evaluate a PDF function for the supplied inputs.

    Inputs are clamped to domain before dispatch. The evaluated output is clamped to range when one is present. Raises BadFunctionEvaluation when arities, sampled-table indexes, calculator stack types, or child stitching bounds are invalid.

    PdfFunctionKind

    pub(all) enum PdfFunctionKind {
    PdfFunctionSampled(PdfSampledFunction)
    PdfFunctionInterpolation(PdfInterpolationFunction)
    PdfFunctionStitching(PdfStitchingFunction)
    PdfFunctionCalculator(PdfCalculatorFunction)
    } derive(Eq, ToJson,
    Debug
    )

    Discriminated PDF function body for supported /FunctionType values.

    PdfImage

    pub(all) enum PdfImage {
    PdfJPEG(Bytes, Array[Double]?)
    PdfJPEG2000(Bytes, Array[Double]?)
    PdfJBIG2(Bytes, Array[Double]?, Int?)
    PdfRawImage(Int, Int, PdfPixelLayout, Bytes)
    } derive(Eq, ToJson,
    Debug
    )

    Extracted PDF image data.

    JPEG, JPEG2000, and JBIG2 variants keep their encoded bytes and optional decode array. PdfJBIG2 also carries the optional /JBIG2Globals object number. PdfRawImage stores width, height, layout, and decoded pixel bytes.

    PdfInterpolationFunction

    pub(all) struct PdfInterpolationFunction {
    c0 : Array[Double]
    c1 : Array[Double]
    n : Double
    } derive(Eq, ToJson,
    Debug
    )

    PDF function type 2, exponential interpolation.

    c0 and c1 are the output vectors at the low and high ends of the input domain, and n is the exponent used to shape interpolation between them.

    PdfLexeme

    pub(all) enum PdfLexeme {
    LexNull
    LexBool(Bool)
    LexInt(Int)
    LexReal(Double)
    LexString(Bytes)
    LexName(PdfName)
    LexLeftSquare
    LexRightSquare
    LexLeftDict
    LexRightDict
    LexStream(PdfStreamData)
    LexEndStream
    LexObj
    LexEndObj
    LexR
    LexComment(Bytes)
    StopLexing
    LexNone
    } derive(Eq, ToJson,
    Debug
    )

    Token produced by the low-level PDF lexer.

    String, name, and comment payloads are byte-oriented PDF data. StopLexing is an internal stop marker used when object lexing reaches stream/xref boundaries, and LexNone means no token matched at the current cursor position.

    PdfName

    pub(all) struct PdfName(Bytes) derive(Eq, ToJson,
    Debug
    )

    A PDF name token stored as its raw bytes without the leading slash.

    Names are byte-oriented in the PDF file format. Keeping the original bytes avoids accidental UTF-16 or UTF-8 interpretation while still allowing explicit views and owned-byte access.

    PdfName::byte_length

    fn PdfName::byte_length(self : PdfName) -> Int

    Returns the byte length of this PDF name.

    PdfName::bytes

    fn PdfName::bytes(self : PdfName) -> Bytes

    Returns the owned bytes backing this PDF name.

    PdfName::view

    fn PdfName::view(self : PdfName) -> BytesView

    Returns a read-only view of the bytes backing this PDF name.

    PdfObject

    pub(all) enum PdfObject {
    PdfNull
    PdfBoolean(Bool)
    PdfInteger(Int)
    PdfReal(Double)
    PdfString(Bytes)
    PdfNameObject(PdfName)
    PdfArray(Array[PdfObject])
    PdfDictionary(Array[(PdfName, PdfObject)])
    PdfStreamObject(PdfStream)
    PdfIndirect(Int)
    } derive(Eq, ToJson,
    Debug
    )

    The core in-memory representation of a parsed PDF object.

    Strings and names are byte-oriented PDF values, not MoonBit Unicode strings. PdfIndirect(number) is an unresolved reference by object number; callers that need the referenced object should resolve it through a PdfDocument.

    PdfObject::add_dict_entry

    fn PdfObject::add_dict_entry(self : PdfObject, key : PdfName, value : PdfObject) -> PdfObject raise PdfError

    Add or replace a dictionary entry.

    PdfNull is promoted to a one-entry dictionary. Existing keys are replaced in place. New keys are inserted using the historical CamlPDF order, which places the new entry before existing entries. Stream objects mutate their stream dictionary and return the same stream object.

    PdfObject::dictionary_view

    fn PdfObject::dictionary_view(self : PdfObject) -> ArrayView[(PdfName, PdfObject)]?

    Borrow the dictionary entries of a dictionary-like object.

    Plain dictionaries return their entries. Stream objects return the entries of their stream dictionary when that dictionary is itself a PdfDictionary. Other objects return None.

    PdfObject::find_indirect

    fn PdfObject::find_indirect(self : PdfObject, key : PdfName) -> Int? raise PdfError

    Return the object number of an immediate indirect dictionary entry.

    Only plain dictionaries are accepted. Missing keys and non-indirect values return None; non-dictionary inputs raise DictionaryExpected.

    PdfObject::get_stream

    fn PdfObject::get_stream(self : PdfObject) -> Unit raise PdfError

    Materialize a stream in place.

    Deferred stream data is read, decrypted if needed, stored back as StreamGot, and /Length is corrected when the stream dictionary is a PDF dictionary. Calling this on an already materialized stream is a no-op. Non-stream objects raise ParseStreamExpected.

    PdfObject::lookup_immediate

    fn PdfObject::lookup_immediate(self : PdfObject, key : PdfName) -> PdfObject?

    Look up a key without resolving indirect references.

    Dictionary and stream-dictionary entries are searched in stored order. The returned object is the immediate value stored under key; use document-level lookup helpers when indirect references should be resolved.

    PdfObject::remove_dict_entry

    fn PdfObject::remove_dict_entry(self : PdfObject, key : PdfName) -> PdfObject raise PdfError

    Remove a dictionary entry if present.

    Missing keys are ignored for dictionaries. Stream objects mutate their stream dictionary and return the same stream object. Non-dictionary inputs raise DictionaryExpected.

    PdfObject::replace_dict_entry

    fn PdfObject::replace_dict_entry(self : PdfObject, key : PdfName, value : PdfObject) -> PdfObject raise PdfError

    Replace an existing dictionary entry.

    The key must already exist in a plain dictionary or stream dictionary. Missing keys and non-dictionary inputs raise DictionaryKeyNotFound.

    PdfObject::stream_bytes

    fn PdfObject::stream_bytes(self : PdfObject) -> Bytes raise PdfError

    Return a stream object's materialized bytes.

    StreamGot data is returned directly. Deferred StreamToGet data is read from its source cursor and decrypted if necessary, but this method does not mutate the stream object or update /Length; use get_stream for that. Non-stream objects raise ParseStreamExpected.

    PdfObject::unique_key

    fn PdfObject::unique_key(self : PdfObject, prefix : String) -> PdfName raise PdfError

    Generate a dictionary key with the form /<prefix><n> that is not in use.

    The scan starts at n = 0 and increments until the name is absent from the dictionary or stream dictionary. Non-dictionary-like objects raise DictionaryExpected.

    PdfObjectData

    pub(all) enum PdfObjectData {
    ObjectParsed(PdfObject)
    ObjectParsedAlreadyDecrypted(PdfObject)
    ObjectToParse
    ObjectToParseFromObjectStream(ObjectStreamReference)
    } derive(Eq, ToJson,
    Debug
    )

    Loading state for one entry in the document object table.

    Parsed variants hold objects that are ready to use. ObjectToParse marks an object that is known from an xref table but has not been read yet. ObjectToParseFromObjectStream records the object-stream location needed to load compressed objects lazily.

    PdfObjectEntry

    pub(all) struct PdfObjectEntry {
    data : PdfObjectData
    generation : Int
    } derive(Eq, ToJson,
    Debug
    )

    One object-table entry together with its generation number.

    The data field is mutable so parsers can replace deferred states with parsed objects after lazy loading.

    PdfObjectEvent

    pub(all) enum PdfObjectEvent {
    ObjectAltered
    ObjectDeleted
    } derive(Eq, ToJson,
    Debug
    )

    Mutation event recorded for incremental-write style bookkeeping.

    PdfObjectMap

    Sparse map from object number to object-table entry.

    This is a thin wrapper around a hash map. It does not track maximum object number or mutation events; use PdfObjects for document-level bookkeeping.

    PdfObjectMap::contains

    fn PdfObjectMap::contains(self : PdfObjectMap, number : Int) -> Bool

    Return whether number has an entry in the object map.

    PdfObjectMap::get_entry

    fn PdfObjectMap::get_entry(self : PdfObjectMap, number : Int) -> PdfObjectEntry?

    Return the object-table entry for number, if present.

    PdfObjectMap::length

    fn PdfObjectMap::length(self : PdfObjectMap) -> Int

    Return the number of entries in the object map.

    PdfObjectMap::lookup_parsed_or_null

    fn PdfObjectMap::lookup_parsed_or_null(self : PdfObjectMap, number : Int) -> PdfObject

    Return a parsed object or PdfNull for missing/deferred entries.

    Both normal parsed objects and already-decrypted parsed objects are returned. Deferred states such as ObjectToParse are treated as absent by this helper.

    PdfObjectMap::object_numbers

    fn PdfObjectMap::object_numbers(self : PdfObjectMap) -> Array[Int]

    Return all object numbers in ascending order.

    PdfObjectMap::remove

    fn PdfObjectMap::remove(self : PdfObjectMap, number : Int) -> Unit

    Remove an object-number entry from the map.

    Missing numbers are ignored.

    PdfObjectMap::set_entry

    fn PdfObjectMap::set_entry(self : PdfObjectMap, number : Int, entry : PdfObjectEntry) -> Unit

    Set or replace the entry for an object number.

    This low-level map operation does not update any mutation log.

    PdfObjects

    pub struct PdfObjects {
    max_object_number : Int
    object_map : PdfObjectMap
    object_stream_ids :
    HashMap
    [Int, Int]
    log : Array[(Int, PdfObjectEvent)]
    } derive(Eq, ToJson,
    Debug
    )

    Document object table with allocation, object-stream, and mutation metadata.

    PdfObjects owns the sparse object map, tracks the highest object number allocated so far, records object-stream identifiers, and stores an alteration log used by writers and tests.

    PdfObjects::add_object

    fn PdfObjects::add_object(self : PdfObjects, object : PdfObject, generation? : Int) -> Int

    Add a parsed object using the next available object number.

    Returns the allocated object number and records an ObjectAltered event.

    PdfObjects::add_object_given_number

    fn PdfObjects::add_object_given_number(self : PdfObjects, number : Int, object : PdfObject, generation? : Int) -> Unit

    Add or replace a parsed object at an explicit object number.

    This updates the maximum object number, stores an ObjectParsed entry, and appends ObjectAltered to the mutation log.

    PdfObjects::get_entry

    fn PdfObjects::get_entry(self : PdfObjects, number : Int) -> PdfObjectEntry?

    Return the object-table entry for number, if present.

    PdfObjects::length

    fn PdfObjects::length(self : PdfObjects) -> Int

    Return the number of object entries currently stored.

    PdfObjects::log

    fn PdfObjects::log(self : PdfObjects) -> Array[(Int, PdfObjectEvent)]

    Return a copy of the object mutation log.

    PdfObjects::lookup_object_or_null

    fn PdfObjects::lookup_object_or_null(self : PdfObjects, number : Int) -> PdfObject

    Return a parsed object by number, or PdfNull if it is absent or deferred.

    PdfObjects::map_objects_in_place

    fn PdfObjects::map_objects_in_place(self : PdfObjects, transform : (PdfObject) -> PdfObject) -> Unit

    Transform every parsed object in place.

    Parsed and already-decrypted entries keep their state tags after the object value is transformed. Deferred entries are left unchanged.

    PdfObjects::max_object_number

    fn PdfObjects::max_object_number(self : PdfObjects) -> Int

    Return the highest object number allocated or loaded so far.

    PdfObjects::object_numbers

    fn PdfObjects::object_numbers(self : PdfObjects) -> Array[Int]

    Return stored object numbers in ascending order.

    PdfObjects::parsed_entries

    fn PdfObjects::parsed_entries(self : PdfObjects) -> Array[(Int, Int, PdfObject)]

    Return parsed object entries as (number, generation, object) triples.

    Results are sorted by object number and exclude deferred entries.

    PdfObjects::remove_object

    fn PdfObjects::remove_object(self : PdfObjects, number : Int) -> Unit

    Remove an object entry and record a deletion event.

    The deletion is logged even if the object number was not present.

    PdfObjects::set_entry

    fn PdfObjects::set_entry(self : PdfObjects, number : Int, entry : PdfObjectEntry) -> Unit

    Set or replace an object-table entry without logging an alteration.

    The tracked maximum object number is raised when number exceeds the previous maximum.

    PdfObjects::stream_entries

    fn PdfObjects::stream_entries(self : PdfObjects) -> Array[(Int, Int, PdfStream)]

    Return parsed stream objects as (number, generation, stream) triples.

    Results are sorted by object number and exclude non-stream or deferred entries.

    PdfOcg

    pub(all) struct PdfOcg {
    name : Bytes
    intent : Array[PdfName]
    usage : PdfOcgUsage?
    } derive(Eq, ToJson,
    Debug
    )

    One PDF optional content group dictionary.

    The group's indirect object number is stored outside this record in PdfOptionalContent.ocgs; name is the raw PDF string bytes.

    PdfOcgAppDict

    pub(all) struct PdfOcgAppDict {
    event : PdfOcgEvent
    ocgs : Array[Int]
    category : Array[PdfName]
    } derive(Eq, ToJson,
    Debug
    )

    Optional-content usage application dictionary.

    ocgs contains indirect object numbers of optional content groups, and category stores the PDF usage-category names for the application.

    PdfOcgConfig

    pub(all) struct PdfOcgConfig {
    name : Bytes?
    creator : Bytes?
    base_state : PdfOcgState
    on : Array[Int]
    off : Array[Int]
    intent : Array[PdfName]
    usage_applications : Array[PdfOcgAppDict]
    order : Array[(Bytes?, Array[Int])]?
    list_mode : PdfOcgListMode
    radio_button_groups : Array[Array[Int]]?
    locked : Array[Int]
    } derive(Eq, ToJson,
    Debug
    )

    Optional-content configuration dictionary.

    Arrays such as on, off, locked, radio-button groups, and order entries contain OCG indirect object numbers. order preserves the PDF layer-panel grouping labels as raw string bytes.

    PdfOcgEvent

    pub(all) enum PdfOcgEvent {
    OcgView
    OcgPrint
    OcgExport
    } derive(Eq, ToJson,
    Debug
    )

    Event context used by optional-content usage application dictionaries.

    PdfOcgListMode

    pub(all) enum PdfOcgListMode {
    OcgAllPages
    OcgVisiblePages
    } derive(Eq, ToJson,
    Debug
    )

    Policy for whether the layer list is shown on all pages or only visible pages.

    PdfOcgState

    pub(all) enum PdfOcgState {
    OcgOn
    OcgOff
    OcgUnchanged
    } derive(Eq, ToJson,
    Debug
    )

    Default visibility state for optional content groups in a configuration.

    PdfOcgUsage

    pub(all) struct PdfOcgUsage {
    creator_info : (Bytes, PdfName)?
    language : (Bytes, PdfName?)?
    export_state : PdfName?
    zoom_min : Double?
    zoom_max : Double?
    print_subtype : PdfName?
    print_state : PdfName?
    view_state : PdfName?
    user : (PdfName, Array[Bytes])?
    page_element_subtype : PdfName?
    } derive(Eq, ToJson,
    Debug
    )

    Usage dictionary for a PDF optional content group.

    Byte fields preserve PDF string bytes exactly. Name fields preserve the corresponding PDF names for creator, language, export, zoom, print, view, user, and page-element usage hints.

    PdfOptionalContent

    pub(all) struct PdfOptionalContent {
    ocgs : Array[(Int, PdfOcg)]
    default_config : PdfOcgConfig
    configs : Array[PdfOcgConfig]
    } derive(Eq, ToJson,
    Debug
    )

    Complete catalog optional-content properties.

    ocgs pairs each group's existing indirect object number with the parsed group dictionary. default_config maps /D; configs maps alternate entries from /Configs.

    PdfPage

    pub(all) struct PdfPage {
    content : Array[PdfObject]
    mediabox : PdfObject
    resources : PdfObject
    rotate : PdfPageRotation
    rest : PdfObject
    } derive(Eq, ToJson,
    Debug
    )

    In-memory page description used by page-tree read and write helpers.

    content stores stream objects or indirect stream references. mediabox, resources, and rest preserve PDF objects so byte-oriented dictionary data is not forced through MoonBit strings.

    PdfPageLabel

    pub(all) struct PdfPageLabel {
    label_style : PdfPageLabelStyle
    label_prefix : Bytes?
    start_page : Int
    start_value : Int
    } derive(Eq, ToJson,
    Debug
    )

    One page-label range.

    start_page is 1-based. start_value is the numeric value shown on that page before style formatting, and label_prefix is stored as PDF bytes.

    PdfPageLabelStyle

    pub(all) enum PdfPageLabelStyle {
    PageLabelDecimalArabic
    PageLabelUppercaseRoman
    PageLabelLowercaseRoman
    PageLabelUppercaseLetters
    PageLabelLowercaseLetters
    PageLabelNoLabelPrefixOnly
    } derive(Eq, ToJson,
    Debug
    )

    Numbering style used for a page-label range.

    PageLabelNoLabelPrefixOnly means no numeric suffix is generated; only the optional prefix contributes to the visible label.

    PdfPageLabelStyle::debug_name

    fn PdfPageLabelStyle::debug_name(self : PdfPageLabelStyle) -> String

    Return a stable debug name for a page-label style.

    PdfPageRotation

    pub(all) enum PdfPageRotation {
    Rotate0
    Rotate90
    Rotate180
    Rotate270
    } derive(Eq, ToJson,
    Debug
    )

    Page rotation normalized to the four rotations allowed by PDF page dictionaries.

    PdfParsedCMap

    pub(all) struct PdfParsedCMap {
    map : Array[(Int, Bytes)]
    cid_map : Array[(Int, Int)]
    notdef_map : Array[(Int, Int)]
    codespaces : Array[PdfCMapCodeSpace]
    usecmap : PdfName?
    wmode : Int?
    cmap_name : PdfName?
    cmap_type : Int?
    cid_system_info : PdfCIDSystemInfo?
    } derive(Eq, ToJson,
    Debug
    )

    Parsed CMap or ToUnicode stream data.

    map stores character-code to UTF-16BE bytes from bfchar/bfrange, cid_map stores character-code to CID mappings, and notdef_map stores notdef fallback CIDs. Optional metadata is taken from the stream body or stream dictionary when available.

    PdfParsedIndirectObject

    pub(all) struct PdfParsedIndirectObject {
    number : Int
    generation : Int
    object : PdfObject
    } derive(Eq, ToJson,
    Debug
    )

    A parsed indirect object with object number, generation, and payload.

    PdfPermission

    pub(all) enum PdfPermission {
    PdfNoEdit
    PdfNoPrint
    PdfNoCopy
    PdfNoAnnot
    PdfNoForms
    PdfNoExtract
    PdfNoAssemble
    PdfNoHqPrint
    } derive(Eq, ToJson,
    Debug
    )

    Permission that may be denied by a PDF standard security handler.

    These values are expressed as a "ban list" in the public API: passing PdfNoPrint means printing is denied. They are converted to and from the PDF /P permission bit mask by pdf_p_of_permissions and pdf_permissions_of_p.

    PdfPixelLayout

    pub(all) enum PdfPixelLayout {
    PdfBPP1
    PdfBPP8
    PdfBPP24
    PdfBPP48
    } derive(Eq, ToJson,
    Debug
    )

    Pixel layout for extracted raw image data.

    PdfRectangle

    pub(all) struct PdfRectangle {
    min_x : Double
    min_y : Double
    max_x : Double
    max_y : Double
    } derive(Eq, ToJson,
    Debug
    )

    A normalized rectangle in PDF user-space coordinates.

    min_x and min_y are always the lower bounds, and max_x and max_y are always the upper bounds. Parsers normalize PDF rectangle arrays whose coordinates are written in the opposite order.

    PdfSampledFunction

    pub(all) struct PdfSampledFunction {
    size : Array[Int]
    order : Int
    encode : Array[Double]
    decode : Array[Double]
    bits_per_sample : Int
    samples : Array[Int]
    } derive(Eq, ToJson,
    Debug
    )

    PDF function type 0, sampled from a packed sample table.

    size gives the sample count for each input dimension. encode maps clamped domain inputs to sample coordinates, decode maps sample values to output values, and samples stores decoded integer samples with the first input dimension varying fastest.

    PdfSavedEncryption

    pub(all) struct PdfSavedEncryption {
    values : PdfEncryptionValues
    } derive(Eq, ToJson,
    Debug
    )

    Saved encryption state retained on a decrypted document.

    Recrypt helpers use this to put a previously encrypted document back into its original security-handler shape after edits.

    PdfSimpleFont

    pub(all) struct PdfSimpleFont {
    fonttype : PdfSimpleFontType
    basefont : PdfName?
    firstchar : Int
    lastchar : Int
    widths : Array[Int]
    fontdescriptor : PdfFontDescriptor?
    fontmetrics : Array[Double]?
    encoding : PdfEncoding
    } derive(Eq, ToJson,
    Debug
    )

    Parsed simple-font dictionary.

    The record preserves declared widths and descriptors when present. Missing metrics are resolved from standard-font fallback data where possible.

    PdfSimpleFont::debug_name

    fn PdfSimpleFont::debug_name(self : PdfSimpleFont) -> String

    Return a multi-line debug summary for this simple font.

    PdfSimpleFontType

    pub(all) enum PdfSimpleFontType {
    PdfType1
    PdfMMType1
    PdfType3(PdfType3Glyphs)
    PdfTrueType
    } derive(Eq, ToJson,
    Debug
    )

    Simple-font subtype recognized by the PDF text layer.

    Type 1, MMType1, Type 3, and TrueType fonts all use one-byte character codes after their encoding differences have been applied.

    PdfSimpleFontType::debug_name

    fn PdfSimpleFontType::debug_name(self : PdfSimpleFontType) -> String

    Return a human-readable simple-font subtype label.

    Type 3 labels include the declared CharProc names to make debugging parsed glyph programs easier.

    PdfStandardFont

    pub(all) enum PdfStandardFont {
    PdfTimesRoman
    PdfTimesBold
    PdfTimesItalic
    PdfTimesBoldItalic
    PdfHelvetica
    PdfHelveticaBold
    PdfHelveticaOblique
    PdfHelveticaBoldOblique
    PdfCourier
    PdfCourierBold
    PdfCourierOblique
    PdfCourierBoldOblique
    PdfSymbol
    PdfZapfDingbats
    } derive(Eq, ToJson,
    Debug
    )

    The built-in PDF standard 14 font faces.

    These values name the base fonts that a conforming PDF reader is expected to know without an embedded font program. The variants match the canonical PDF names used in /BaseFont entries.

    PdfStandardFont::afm_data

    Returns the Adobe Font Metrics data for this standard font.

    PdfStandardFont::baseline_adjustment

    fn PdfStandardFont::baseline_adjustment(self : PdfStandardFont) -> Int

    Return a synthetic baseline adjustment for simple standard-font placement.

    The value is derived from the font ascent-like metrics used by the original CamlPDF helpers and is expressed in glyph-space units.

    PdfStandardFont::flags

    fn PdfStandardFont::flags(self : PdfStandardFont) -> Int

    Return PDF font descriptor flags for this standard font.

    The flags distinguish symbolic fonts, fixed-pitch Courier faces, and the nonsymbolic roman faces according to the PDF font descriptor bit layout.

    PdfStandardFont::name

    fn PdfStandardFont::name(self : PdfStandardFont) -> String

    Return the canonical standard-font name without the leading PDF slash.

    PdfStandardFont::pdf_name

    fn PdfStandardFont::pdf_name(self : PdfStandardFont) -> PdfName

    Return the canonical PDF name object for this standard font.

    The returned name includes the leading slash in the underlying PdfName bytes and is suitable for /BaseFont dictionary entries.

    PdfStandardFont::stemv

    fn PdfStandardFont::stemv(self : PdfStandardFont) -> Int

    Return the standard-font StemV descriptor value used when writing fonts.

    PdfStandardFont::text_width

    fn PdfStandardFont::text_width(self : PdfStandardFont, encoding : PdfEncoding, text : BytesView, kern? : Bool) -> Int

    Computes the width of byte-encoded text for this standard font.

    PdfStandardFontData

    pub(all) struct PdfStandardFontData {
    font : PdfStandardFont
    encoding : PdfEncoding
    } derive(Eq, ToJson,
    Debug
    )

    Parsed standard-font data with its active character encoding.

    Standard 14 fonts do not carry embedded metrics in normal PDF files, so extraction combines the font identity with the chosen simple-font encoding.

    PdfStandardFontData::debug_name

    fn PdfStandardFontData::debug_name(self : PdfStandardFontData) -> String

    Return a compact debug label for this standard font data.

    PdfStandardFontData::text_width

    fn PdfStandardFontData::text_width(self : PdfStandardFontData, text : BytesView, kern? : Bool) -> Int

    Computes the width of byte-encoded text using this standard-font data and its encoding.

    PdfStitchingFunction

    pub(all) struct PdfStitchingFunction {
    functions : Array[PdfFunction]
    bounds : Array[Double]
    stitch_encode : Array[Double]
    } derive(Eq, ToJson,
    Debug
    )

    PDF function type 3, stitching several child functions over one input.

    bounds partitions the parent domain, and stitch_encode maps each chosen segment into the selected child function's input domain.

    PdfStream

    pub(all) struct PdfStream {
    dictionary : PdfObject
    data : PdfStreamData
    } derive(Eq, ToJson,
    Debug
    )

    A PDF stream object: dictionary metadata plus stream bytes.

    The dictionary and data fields are mutable because helpers such as get_stream and the dictionary update methods materialize stream data and update stream dictionaries in place.

    PdfStreamData

    pub(all) enum PdfStreamData {
    StreamGot(Bytes)
    StreamToGet(ToGet)
    } derive(Eq, ToJson,
    Debug
    )

    Storage state for a PDF stream body.

    StreamGot stores already materialized bytes. StreamToGet stores a deferred slice of an input buffer, optionally with stream decryption metadata that is applied when the data is read.

    PdfStreamDataCrypt

    pub(all) enum PdfStreamDataCrypt {
    PdfStreamDataNoCrypt
    PdfStreamDataArc4Decrypt(Int, Int, Bytes, Int)
    PdfStreamDataAesV2Decrypt(Int, Int, Bytes, Int)
    PdfStreamDataAesV3Decrypt(Bytes)
    } derive(Eq, ToJson,
    Debug
    )

    Decryption metadata associated with deferred stream data.

    The variants correspond to the stream ciphers supported by the PDF security handler. Object-specific ciphers store object number, generation, file key, and key length; AES-V3 stores the already derived file key.

    PdfStreamEncoding

    pub(all) enum PdfStreamEncoding {
    PdfStreamASCIIHex
    PdfStreamASCII85
    PdfStreamRunLength
    PdfStreamFlate
    PdfStreamCCITT(Int, Int)
    PdfStreamCCITTG4(Int, Int)
    } derive(Eq, ToJson,
    Debug
    )

    Stream encoding requested by high-level stream encode helpers.

    CCITT variants carry image columns and rows because those values are needed in /DecodeParms when writing fax-compressed image streams.

    PdfStreamEncoding::filter_name

    fn PdfStreamEncoding::filter_name(self : PdfStreamEncoding) -> PdfName

    Return the PDF filter name for this stream encoding.

    PdfStreamPredictor

    pub(all) enum PdfStreamPredictor {
    PdfStreamPredictorTIFF2
    PdfStreamPredictorPNGNone
    PdfStreamPredictorPNGSub
    PdfStreamPredictorPNGUp
    PdfStreamPredictorPNGAverage
    PdfStreamPredictorPNGPaeth
    PdfStreamPredictorPNGOptimum
    } derive(Eq, ToJson,
    Debug
    )

    PNG/TIFF predictor requested when encoding stream data.

    Predictor values correspond to PDF /Predictor numbers.

    PdfStreamPredictor::number

    fn PdfStreamPredictor::number(self : PdfStreamPredictor) -> Int

    Return the PDF /Predictor number for this predictor.

    PdfTargetPage

    pub(all) enum PdfTargetPage {
    TargetPageObject(Int)
    TargetOtherDocPageNumber(Int)
    } derive(Eq, ToJson,
    Debug
    )

    A destination target page reference.

    PDF destination arrays may refer either to a page object or to a page number in another document.

    PdfTextExtractor

    pub(all) struct PdfTextExtractor {
    font : PdfFont
    } derive(Eq, ToJson,
    Debug
    )

    Text extractor bound to a parsed font.

    The extractor converts PDF text-string bytes to character codes, glyph names, and Unicode codepoints according to the font's encoding data.

    PdfTextExtractor::charcode_of_codepoint

    fn PdfTextExtractor::charcode_of_codepoint(self : PdfTextExtractor, codepoint : Int) -> Int?

    Return a PDF character code that can encode one Unicode codepoint.

    The lookup prefers explicit ToUnicode reverse mappings, then predefined or external CMap reverse lookup, then simple-font glyph names. None means the current font has no known single-codepoint representation.

    PdfTextExtractor::codepoints_of_text

    fn PdfTextExtractor::codepoints_of_text(self : PdfTextExtractor, text : BytesView) -> Array[Int] raise PdfError

    Extract Unicode codepoints from PDF text bytes.

    /ToUnicode mappings take precedence. External CMaps, predefined CMaps, glyph names, and font-specific fallbacks are used when no explicit ToUnicode mapping exists. Multi-codepoint glyph names are flattened into the returned array.

    PdfTextExtractor::glyphnames_and_codepoints_of_text

    fn PdfTextExtractor::glyphnames_and_codepoints_of_text(self : PdfTextExtractor, text : BytesView) -> Array[PdfTextGlyph] raise PdfError

    Resolve glyph names and Unicode codepoints for each character code in text.

    This lower-level extractor exposes both sides of the mapping. The input is a PDF text byte sequence, not a MoonBit String, and malformed byte segmentation raises PdfError.

    PdfTextExtractor::glyphnames_of_text

    fn PdfTextExtractor::glyphnames_of_text(self : PdfTextExtractor, text : BytesView) -> Array[PdfName] raise PdfError

    Resolve only glyph names from PDF text bytes.

    This bypasses Unicode conversion and is useful for callers that need the encoded glyph identity rather than extracted text.

    PdfTextExtractor::text_width

    fn PdfTextExtractor::text_width(self : PdfTextExtractor, text : BytesView) -> Double raise PdfError

    Measure PDF text bytes in glyph-space units for this extractor's font.

    Text bytes are segmented according to the font encoding. Malformed byte sequences raise PdfError, and missing metrics contribute width 0.

    PdfTextGlyph

    pub(all) struct PdfTextGlyph {
    glyphname : PdfName
    codepoints : Array[Int]
    } derive(Eq, ToJson,
    Debug
    )

    Extracted glyph result for one character code.

    glyphname is the resolved PDF glyph name and codepoints is the Unicode scalar sequence inferred from ToUnicode, CMap, or Adobe glyph-list data.

    PdfTristimulusPoint

    pub(all) struct PdfTristimulusPoint {
    x : Double
    y : Double
    z : Double
    } derive(Eq, ToJson,
    Debug
    )

    A CIE tristimulus point used by calibrated PDF colour spaces.

    The fields represent the X, Y, and Z components used for white point and black point entries in /CalGray, /CalRGB, and /Lab dictionaries.

    PdfType3Glyphs

    pub(all) struct PdfType3Glyphs {
    fontbbox : PdfRectangle
    fontmatrix : TransformMatrix
    charprocs : Array[(PdfName, PdfObject)]
    resources : PdfObject
    } derive(Eq, ToJson,
    Debug
    )

    Type 3 font glyph-program data.

    charprocs keeps glyph names paired with their drawing streams and resources is the Type 3 resource dictionary used when interpreting those glyph programs.

    PdfUnit

    pub(all) enum PdfUnit {
    PdfPoint
    Inch
    Centimetre
    Millimetre
    } derive(Eq, ToJson,
    Debug
    )

    Units accepted by page and geometry helpers.

    PDF coordinates are ultimately expressed in points, but the public API keeps common paper and layout units explicit at call sites.

    PdfVersion

    pub(all) struct PdfVersion {
    major : Int
    minor : Int
    } derive(Eq, ToJson,
    Debug
    )

    Parsed PDF header version.

    The fields correspond to the digits in a %PDF-major.minor header.

    PdfWriteEncryption

    pub(all) struct PdfWriteEncryption {
    encryption_method : PdfEncryptionMethod
    user_password : Bytes
    owner_password : Bytes
    denied_permissions : Array[PdfPermission]
    } derive(Eq, ToJson,
    Debug
    )

    Encryption options for pdf_write_document_options.

    Passwords are stored as owned PDF bytes so callers can pass borrowed BytesView values safely.

    PdfWriteMode

    pub(all) enum PdfWriteMode {
    PdfWriteClassic
    PdfWriteXRefStream
    PdfWriteCompressedXRefStream
    } derive(Eq, ToJson,
    Debug
    )

    Cross-reference format used when serializing a document.

    Classic writes a traditional xref table and trailer. XRefStream writes an uncompressed xref stream, and CompressedXRefStream wraps that stream in Flate compression.

    Point2

    pub(all) struct Point2 {
    x : Double
    y : Double
    } derive(Eq, ToJson,
    Debug
    )

    A two-dimensional point in PDF user-space coordinates.

    ToGet

    pub(all) struct ToGet {
    input : ByteCursor
    position : Int
    length : Int
    crypt : PdfStreamDataCrypt
    } derive(Eq, ToJson,
    Debug
    )

    A deferred stream-data slice read from an input cursor.

    position and length identify the raw byte range in input; crypt records the decryption operation to apply when the bytes are materialized. This lets the reader keep large stream bodies lazy until a caller requests their bytes.

    ToGet::crypt

    fn ToGet::crypt(self : ToGet) -> PdfStreamDataCrypt

    Return the decryption metadata for a deferred stream slice.

    ToGet::input

    fn ToGet::input(self : ToGet) -> ByteCursor

    Return the source cursor used by a deferred stream slice.

    ToGet::length

    fn ToGet::length(self : ToGet) -> Int

    Return the byte length of a deferred stream slice.

    ToGet::position

    fn ToGet::position(self : ToGet) -> Int

    Return the start position of a deferred stream slice.

    The value is interpreted relative to the ByteCursor's offset when the stream is materialized.

    TransformDecomposition

    pub(all) struct TransformDecomposition {
    scale : Double
    aspect : Double
    rotation : Double
    shear : Double
    translate_x : Double
    translate_y : Double
    } derive(Eq, ToJson,
    Debug
    )

    The decomposed components of an affine transform matrix.

    Values are expressed as scale, aspect ratio, rotation, shear, and translation components suitable for recomposition.

    TransformMatrix

    pub(all) struct TransformMatrix {
    a : Double
    b : Double
    c : Double
    d : Double
    e : Double
    f : Double
    } derive(Eq, ToJson,
    Debug
    )

    A PDF affine transform matrix.

    The fields correspond to PDF's six-operand matrix [a b c d e f], where a point is transformed as x' = a*x + c*y + e and y' = b*x + d*y + f.

    TransformMatrix::apply

    fn TransformMatrix::apply(self : TransformMatrix, point : Point2) -> Point2

    Applies this matrix to a point.

    TransformMatrix::debug_string

    fn TransformMatrix::debug_string(self : TransformMatrix) -> String

    Formats a matrix as its six comma-separated operands.

    TransformMatrix::decompose

    Decomposes this matrix into scale, aspect, rotation, shear, and translation components.

    Non-finite and underflowed intermediate values are normalized to zero so the result is stable for malformed or degenerate matrices.

    TransformMatrix::invert

    Returns the inverse of this matrix.

    Raises PdfError::MatrixNotInvertable when the matrix determinant is zero or too small to produce a finite inverse.

    TransformOp

    pub(all) enum TransformOp {
    Scale(Point2, Double, Double)
    Rotate(Point2, Double)
    Translate(Double, Double)
    ShearX(Point2, Double)
    ShearY(Point2, Double)
    } derive(Eq, ToJson,
    Debug
    )

    A high-level affine transform operation.

    Operation lists preserve CamlPDF's transform model; they can be rendered for diagnostics or lowered to TransformMatrix for application to points.

    TransformOp::debug_string

    fn TransformOp::debug_string(self : TransformOp) -> String

    Formats one transform operation in CamlPDF-compatible debug text.

    bit_writer_new

    fn bit_writer_new() -> BitWriter

    Creates an empty bit writer.

    bitstream_of_bytes

    fn bitstream_of_bytes(data : Bytes, source? : String) -> BitStream

    Creates a bit stream over owned PDF bytes.

    The optional source label is forwarded to the underlying cursor and is used in parse error messages.

    bitstream_of_cursor

    fn bitstream_of_cursor(input : ByteCursor) -> BitStream

    Creates a bit stream that reads from an existing byte cursor.

    bitstream_of_view

    fn bitstream_of_view(data : BytesView, source? : String) -> BitStream

    Creates a bit stream over a read-only byte view.

    The returned reader does not copy data; callers that need ownership should pass owned bytes explicitly.

    byte_cursor_of_bytes

    fn byte_cursor_of_bytes(data : Bytes, source? : String) -> ByteCursor

    Creates a cursor over owned PDF bytes.

    The cursor borrows the byte storage through a view and does not copy it.

    byte_cursor_of_view

    fn byte_cursor_of_view(data : BytesView, source? : String) -> ByteCursor

    Creates a cursor over a byte view.

    The optional source label appears in parse error messages.

    byte_output_new

    fn byte_output_new(initial_size? : Int) -> ByteOutput raise PdfError

    Creates an empty output buffer.

    initial_size preallocates zero-filled capacity but does not count as written output. Raises PdfError::InvalidReadLength for negative sizes.

    paper_a0

    let paper_a0 : PaperSize

    ISO A0 paper, 841 mm by 1189 mm.

    paper_a1

    let paper_a1 : PaperSize

    ISO A1 paper, 594 mm by 841 mm.

    paper_a10

    let paper_a10 : PaperSize

    ISO A10 paper, 26 mm by 37 mm.

    paper_a2

    let paper_a2 : PaperSize

    ISO A2 paper, 420 mm by 594 mm.

    paper_a3

    let paper_a3 : PaperSize

    ISO A3 paper, 297 mm by 420 mm.

    paper_a4

    let paper_a4 : PaperSize

    ISO A4 paper, 210 mm by 297 mm.

    paper_a5

    let paper_a5 : PaperSize

    ISO A5 paper, 148 mm by 210 mm.

    paper_a6

    let paper_a6 : PaperSize

    ISO A6 paper, 105 mm by 148 mm.

    paper_a7

    let paper_a7 : PaperSize

    ISO A7 paper, 74 mm by 105 mm.

    paper_a8

    let paper_a8 : PaperSize

    ISO A8 paper, 52 mm by 74 mm.

    paper_a9

    let paper_a9 : PaperSize

    ISO A9 paper, 37 mm by 52 mm.

    paper_size_make

    fn paper_size_make(unit : PdfUnit, width : Double, height : Double) -> PaperSize

    Creates a paper size from a unit, width, and height.

    paper_uslegal

    let paper_uslegal : PaperSize

    US Legal paper, 8.5 inches by 14 inches.

    paper_usletter

    let paper_usletter : PaperSize

    US Letter paper, 8.5 inches by 11 inches.

    pdf_add_annotation

    fn pdf_add_annotation(document : PdfDocument, page : PdfPage, annotation : PdfAnnotation) -> PdfPage raise PdfError

    Compatibility wrapper for PdfDocument::add_annotation.

    pdf_add_bookmarks

    fn pdf_add_bookmarks(bookmarks : ArrayView[PdfBookmark], document : PdfDocument) -> PdfDocument raise PdfError

    Compatibility wrapper for PdfDocument::add_bookmarks.

    pdf_add_pagetree

    fn pdf_add_pagetree(pages : ArrayView[PdfPage], document : PdfDocument) -> (PdfDocument, Int) raise PdfError

    Copy a document, add a page tree, and return the copy with the tree root.

    pdf_add_prefix

    fn pdf_add_prefix(document : PdfDocument, prefix : String) -> Unit raise PdfError

    Compatibility wrapper for PdfDocument::add_prefix.

    pdf_add_root

    fn pdf_add_root(page_root_number : Int, extras : ArrayView[(PdfName, PdfObject)], document : PdfDocument) -> PdfDocument raise PdfError

    Copy a document, add a catalog root, and return the copy.

    pdf_aes_cbc_decrypt

    fn pdf_aes_cbc_decrypt(key : BytesView, data : BytesView, remove_padding? : Bool) -> Bytes raise PdfError

    Decrypt AES-CBC data whose first block is the IV.

    Data shorter than or equal to one block decrypts to empty bytes. Block lengths that are not multiples of 16 raise InvalidCryptoDataLength.

    pdf_aes_cbc_encrypt_with_iv

    fn pdf_aes_cbc_encrypt_with_iv(key : BytesView, iv : BytesView, data : BytesView) -> Bytes raise PdfError

    Encrypt bytes with AES-CBC and an explicit IV.

    PKCS-style padding is added and the returned bytes include the IV as the first block, matching PDF AES string and stream data layout.

    pdf_aes_decrypt_block

    fn pdf_aes_decrypt_block(key : BytesView, block : BytesView) -> Bytes raise PdfError

    Decrypt one 16-byte AES block with a 128-, 192-, or 256-bit key.

    pdf_aes_ecb_decrypt

    fn pdf_aes_ecb_decrypt(key : BytesView, data : BytesView, remove_padding? : Bool) -> Bytes raise PdfError

    Decrypt AES-ECB data.

    The input length must be a non-zero multiple of 16 unless it is empty. Padding is removed by default.

    pdf_aes_ecb_encrypt

    fn pdf_aes_ecb_encrypt(key : BytesView, data : BytesView) -> Bytes raise PdfError

    Encrypt AES-ECB data without adding padding.

    The input length must be a non-zero multiple of 16 unless it is empty.

    pdf_aes_encrypt_block

    fn pdf_aes_encrypt_block(key : BytesView, block : BytesView) -> Bytes raise PdfError

    Encrypt one 16-byte AES block with a 128-, 192-, or 256-bit key.

    pdf_aesv2_decrypt_object_data

    fn pdf_aesv2_decrypt_object_data(object_number : Int, generation : Int, file_key : BytesView, key_length_bits : Int, data : BytesView) -> Bytes raise PdfError

    Decrypt AESV2 object data bytes with the derived object key.

    data must include the leading CBC IV as stored in encrypted PDF strings and streams.

    pdf_aesv2_decrypt_pdf_object

    fn pdf_aesv2_decrypt_pdf_object(object_number : Int, generation : Int, file_key : BytesView, key_length_bits : Int, object : PdfObject, no_encrypt_metadata? : Bool) -> PdfObject raise PdfError

    Decrypt a PDF object using AESV2 with per-object derived keys.

    Deferred stream data is annotated with AESV2 crypt state so it can be decrypted lazily when the stream bytes are loaded.

    pdf_aesv2_encrypt_object_data

    fn pdf_aesv2_encrypt_object_data(object_number : Int, generation : Int, file_key : BytesView, key_length_bits : Int, data : BytesView, iv : BytesView) -> Bytes raise PdfError

    Encrypt bytes as AESV2 object data with an explicit CBC IV.

    The returned bytes include the IV prefix expected by PDF AESV2 strings and streams.

    pdf_aesv2_encrypt_pdf_object_with_iv_provider

    fn pdf_aesv2_encrypt_pdf_object_with_iv_provider(object_number : Int, generation : Int, file_key : BytesView, key_length_bits : Int, object : PdfObject, iv_provider : (Int) -> Bytes raise PdfError, no_encrypt_metadata? : Bool) -> PdfObject raise PdfError

    Encrypt a PDF object using AESV2 with per-object derived keys.

    The IV provider is called with a zero-based index for each encrypted string or stream inside the object. Identity crypt-filter streams are preserved.

    pdf_aesv3_decrypt_object_data

    fn pdf_aesv3_decrypt_object_data(file_key : BytesView, data : BytesView) -> Bytes raise PdfError

    Decrypt AESV3 object data bytes with the document file key.

    data must include the leading CBC IV.

    pdf_aesv3_decrypt_pdf_object

    fn pdf_aesv3_decrypt_pdf_object(file_key : BytesView, object : PdfObject, no_encrypt_metadata? : Bool) -> PdfObject raise PdfError

    Decrypt a PDF object using AESV3 with the file key directly.

    Deferred stream data is annotated with AESV3 crypt state so it can be decrypted lazily when the stream bytes are loaded.

    pdf_aesv3_encrypt_object_data

    fn pdf_aesv3_encrypt_object_data(file_key : BytesView, data : BytesView, iv : BytesView) -> Bytes raise PdfError

    Encrypt bytes as AESV3 object data with an explicit CBC IV.

    The returned bytes include the IV prefix expected by PDF AES strings and streams.

    pdf_aesv3_encrypt_pdf_object_with_iv_provider

    fn pdf_aesv3_encrypt_pdf_object_with_iv_provider(file_key : BytesView, object : PdfObject, iv_provider : (Int) -> Bytes raise PdfError, no_encrypt_metadata? : Bool) -> PdfObject raise PdfError

    Encrypt a PDF object using AESV3 with the file key directly.

    The IV provider is called with a zero-based index for each encrypted string or stream inside the object. Identity crypt-filter streams are preserved.

    pdf_annotation_make

    fn pdf_annotation_make(subtype : PdfAnnotationSubtype, contents? : Bytes?, border? : PdfAnnotationBorder, rectangle? : PdfRectangle, colour? : PdfAnnotationColour?, subject? : Bytes?) -> PdfAnnotation

    Build an annotation value with CamlPDF-compatible defaults.

    Defaults are no contents, no subject, a zero rectangle, default border, no colour, and no preserved extra dictionary entries.

    pdf_annotation_make_border

    fn pdf_annotation_make_border(width : Double, vertical_radius? : Double, horizontal_radius? : Double, style? : PdfAnnotationStyle, dash_array? : ArrayView[Int]) -> PdfAnnotationBorder

    Build an annotation border, copying the supplied dash array.

    pdf_annotations_of_page

    fn pdf_annotations_of_page(document : PdfDocument, page : PdfPage) -> Array[PdfAnnotation] raise PdfError

    Compatibility wrapper for PdfDocument::annotations_of_page.

    pdf_arc4_crypt

    fn pdf_arc4_crypt(key : BytesView, data : BytesView) -> Bytes raise PdfError

    Apply ARC4 to data with key.

    ARC4 is symmetric, so the same function encrypts and decrypts. Empty keys raise CryptoKeyExpected.

    pdf_arc4_crypt_object

    fn pdf_arc4_crypt_object(object_number : Int, generation : Int, file_key : BytesView, key_length_bits : Int, data : BytesView) -> Bytes raise PdfError

    ARC4-encrypt or decrypt data for one object using a file key.

    The per-object key is derived from object number and generation before ARC4 is applied.

    pdf_arc4_crypt_pdf_object

    fn pdf_arc4_crypt_pdf_object(object_number : Int, generation : Int, file_key : BytesView, key_length_bits : Int, object : PdfObject, no_encrypt_metadata? : Bool) -> PdfObject raise PdfError

    Apply ARC4 object encryption or decryption to a PDF object.

    ARC4 is symmetric. The object key is derived from object number, generation, file key, and key length. Streams using identity crypt filters, and metadata streams when no_encrypt_metadata=true, are left unchanged.

    pdf_array

    fn pdf_array(values : ArrayView[PdfObject]) -> PdfObject

    Construct a PDF array from a read-only view of object values.

    The outer array is newly allocated, but the contained PdfObject values are copied by value rather than deep-copied.

    pdf_ascii85_decode

    fn pdf_ascii85_decode(data : Bytes) -> Bytes raise PdfError

    Owned-byte wrapper for pdf_ascii85_decode_view.

    pdf_ascii85_decode_view

    fn pdf_ascii85_decode_view(data : BytesView) -> Bytes raise PdfError

    Decode PDF ASCII85Decode data.

    Whitespace is ignored. Missing terminators, malformed partial groups, invalid z placement, and overflowing groups raise InvalidASCII85Data.

    pdf_ascii85_encode

    fn pdf_ascii85_encode(data : Bytes) -> Bytes

    Owned-byte wrapper for pdf_ascii85_encode_view.

    pdf_ascii85_encode_view

    fn pdf_ascii85_encode_view(data : BytesView) -> Bytes

    Encode bytes using PDF ASCII85Decode syntax.

    Four zero bytes are compressed as z, partial final groups are shortened, and the result ends with ~>.

    pdf_ascii_hex_decode

    fn pdf_ascii_hex_decode(data : Bytes) -> Bytes raise PdfError

    Owned-byte wrapper for pdf_ascii_hex_decode_view.

    pdf_ascii_hex_decode_view

    fn pdf_ascii_hex_decode_view(data : BytesView) -> Bytes raise PdfError

    Decode PDF ASCIIHexDecode data.

    Whitespace is ignored and a trailing odd nibble is padded with zero when the > marker is reached. Invalid hex digits raise InvalidHexEscape.

    pdf_ascii_hex_encode

    fn pdf_ascii_hex_encode(data : Bytes) -> Bytes

    Owned-byte wrapper for pdf_ascii_hex_encode_view.

    pdf_ascii_hex_encode_view

    fn pdf_ascii_hex_encode_view(data : BytesView) -> Bytes

    Encode bytes using PDF ASCIIHexDecode syntax.

    The returned bytes are uppercase hexadecimal pairs followed by the > end-of-data marker.

    pdf_authenticate_owner_password

    fn pdf_authenticate_owner_password(no_encrypt_metadata : Bool, owner_password : BytesView, revision : Int, user_entry : BytesView, owner_entry : BytesView, permissions : Int, file_id : BytesView, key_length_bits : Int) -> Bool raise PdfError

    Authenticate a revision 2-4 owner password.

    This decrypts the owner entry to recover the padded user password and then validates that recovered password against the user entry.

    pdf_authenticate_owner_password_aesv3

    fn pdf_authenticate_owner_password_aesv3(iso : Bool, password : BytesView, user_entry : BytesView, owner_entry : BytesView) -> Bool raise PdfError

    Authenticate an AESV3 owner password entry.

    Owner authentication incorporates the 48-byte user entry as required by the AESV3 security algorithm. Short /O or /U entries raise PdfError.

    pdf_authenticate_user_password

    fn pdf_authenticate_user_password(no_encrypt_metadata : Bool, user_password : BytesView, revision : Int, user_entry : BytesView, owner_entry : BytesView, permissions : Int, file_id : BytesView, key_length_bits : Int) -> Bool raise PdfError

    Authenticate a revision 2-4 user password against a /U entry.

    pdf_authenticate_user_password_aesv3

    fn pdf_authenticate_user_password_aesv3(iso : Bool, password : BytesView, user_entry : BytesView) -> Bool raise PdfError

    Authenticate an AESV3 user password entry.

    iso selects the ISO/PDF 2.0 hash variant. Short /U entries raise EncryptionDictionaryEntryTooShort.

    pdf_banlist_of_p

    fn pdf_banlist_of_p(mask : Int) -> Array[PdfPermission]

    Compatibility alias for pdf_permissions_of_p.

    pdf_bookmark_black

    let pdf_bookmark_black : PdfBookmarkColour

    Default black bookmark colour.

    pdf_build_name_tree

    fn pdf_build_name_tree(is_number : Bool, document : PdfDocument, entries : ArrayView[(Bytes, PdfObject)]) -> PdfObject raise PdfError

    Build either a name tree or a number tree from byte-keyed entries.

    When is_number is false, this delegates to build_name_tree. When it is true, keys must be signed 32-bit decimal ASCII and are converted to integers before building a number tree; invalid keys raise NumberExpected.

    pdf_byte_of_int

    fn pdf_byte_of_int(value : Int) -> Byte raise PdfError

    Converts an integer to a byte.

    Raises PdfError::InvalidByte when value is outside 0..=255.

    pdf_bytes_concat_views

    fn pdf_bytes_concat_views(parts : ArrayView[BytesView]) -> Bytes

    Concatenates byte views into one owned PDF byte sequence.

    pdf_bytes_copy

    fn pdf_bytes_copy(values : BytesView) -> Bytes

    Copies a byte view into owned PDF bytes using indexed construction.

    This is useful when the input may alias data that will be mutated elsewhere.

    pdf_bytes_get

    fn pdf_bytes_get(bytes : Bytes, index : Int) -> Byte?

    Returns the byte at index, or None when the index is out of bounds.

    pdf_bytes_length

    fn pdf_bytes_length(bytes : Bytes) -> Int

    Returns the length of a PDF byte sequence.

    pdf_bytes_make

    fn pdf_bytes_make(length : Int, value? : Int) -> Bytes raise PdfError

    Creates owned PDF bytes of length filled with value.

    The default value is zero. Raises PdfError::InvalidReadLength for negative lengths and PdfError::InvalidByte for values outside 0..=255.

    pdf_bytes_map_int

    fn pdf_bytes_map_int(bytes : BytesView, f : (Int) -> Int) -> Bytes raise PdfError

    Maps every byte through an integer transformation and returns owned bytes.

    The callback receives each input byte as an Int. Raises PdfError::InvalidByte if a mapped value is outside 0..=255.

    pdf_bytes_of_array_view

    fn pdf_bytes_of_array_view(values : ArrayView[Byte]) -> Bytes

    Copies an array view of bytes into owned PDF bytes.

    pdf_bytes_of_date

    fn pdf_bytes_of_date(date : PdfDate) -> Bytes raise PdfError

    Formats a PDF date as an owned PDF byte string.

    Raises PdfError::BadDate if any field is outside the representable PDF date ranges.

    pdf_bytes_of_int_array

    fn pdf_bytes_of_int_array(values : ArrayView[Int]) -> Bytes raise PdfError

    Converts integer byte values to owned PDF bytes.

    Raises PdfError::InvalidByte if any value is outside 0..=255.

    pdf_bytes_of_int_arrays

    fn pdf_bytes_of_int_arrays(values : ArrayView[ArrayView[Int]]) -> Bytes raise PdfError

    Flattens arrays of integer byte values into owned PDF bytes.

    Raises PdfError::InvalidByte if any value is outside 0..=255.

    pdf_bytes_of_view

    fn pdf_bytes_of_view(values : BytesView) -> Bytes

    Copies a byte view into owned PDF bytes.

    pdf_bytes_to_array

    fn pdf_bytes_to_array(bytes : Bytes) -> Array[Byte]

    Copies PDF bytes into a resizable Array[Byte].

    pdf_bytes_to_fixed_array

    fn pdf_bytes_to_fixed_array(bytes : Bytes) -> FixedArray[Byte]

    Copies PDF bytes into a fixed-size byte array.

    pdf_ccitt_encode

    fn pdf_ccitt_encode(columns : Int, rows : Int, data : Bytes) -> Bytes raise PdfError

    Owned-byte wrapper for pdf_ccitt_encode_view.

    pdf_ccitt_encode_view

    fn pdf_ccitt_encode_view(columns : Int, rows : Int, data : BytesView) -> Bytes raise PdfError

    Encode 1-bit image data as CCITT Group 3 one-dimensional fax data.

    pdf_ccitt_g4_encode

    fn pdf_ccitt_g4_encode(columns : Int, rows : Int, data : Bytes) -> Bytes raise PdfError

    Owned-byte wrapper for pdf_ccitt_g4_encode_view.

    pdf_ccitt_g4_encode_view

    fn pdf_ccitt_g4_encode_view(columns : Int, rows : Int, data : BytesView) -> Bytes raise PdfError

    Encode 1-bit image data as CCITT Group 4 fax data.

    pdf_change_pages

    fn pdf_change_pages(change_references : Bool, document : PdfDocument, pages : ArrayView[PdfPage], matrices? : ArrayView[(Int, TransformMatrix)], changes? : ArrayView[(Int, Int)]) -> PdfDocument raise PdfError

    Compatibility wrapper for PdfDocument::change_pages.

    pdf_charcode_extractor_of_font

    fn pdf_charcode_extractor_of_font(document : PdfDocument, font : PdfObject, debug? : Bool) -> ((Int) -> Int?) raise PdfError

    Read a font dictionary and build a pure Unicode-to-charcode closure.

    debug is accepted for CamlPDF API compatibility; this implementation preserves pure lookup behavior and does not write missing-glyph diagnostics.

    pdf_charcode_extractor_of_font_real

    fn pdf_charcode_extractor_of_font_real(font : PdfFont, debug? : Bool) -> ((Int) -> Int?)

    Build a pure reverse lookup closure for an already parsed font.

    The returned closure maps one Unicode codepoint to the first matching PDF character code when the font can represent it. debug is accepted for CamlPDF API compatibility; this implementation does not write diagnostics.

    pdf_codepoint_of_pdfdocencoding_byte

    fn pdf_codepoint_of_pdfdocencoding_byte(value : Int) -> Int raise PdfError

    Decode one PDFDocEncoding byte to a Unicode codepoint.

    Undefined byte values raise InvalidPDFDocEncoding.

    pdf_codepoints_of_pdfdocencoding

    fn pdf_codepoints_of_pdfdocencoding(bytes : BytesView) -> Array[Int] raise PdfError

    Decode a PDFDocEncoding byte string to Unicode codepoints.

    pdf_codepoints_of_pdfdocstring

    fn pdf_codepoints_of_pdfdocstring(bytes : BytesView) -> Array[Int] raise PdfError

    Decode a PDF string to Unicode codepoints.

    BOM-prefixed strings are treated as UTF-16BE. Other byte strings are decoded as PDFDocEncoding.

    pdf_codepoints_of_text

    fn pdf_codepoints_of_text(extractor : PdfTextExtractor, text : BytesView) -> Array[Int] raise PdfError

    Compatibility wrapper for PdfTextExtractor::codepoints_of_text.

    pdf_codepoints_of_utf16be

    fn pdf_codepoints_of_utf16be(bytes : BytesView) -> Array[Int] raise PdfError

    Decode UTF-16BE bytes into Unicode scalar values.

    The input should not include the leading FE FF BOM; callers that receive a PDF Unicode string normally pass bytes[2:]. Odd lengths, lone surrogates, and malformed pairs raise InvalidUTF16BE.

    pdf_codepoints_of_utf8

    fn pdf_codepoints_of_utf8(bytes : BytesView) -> Array[Int] raise PdfError

    Decode UTF-8 bytes into Unicode scalar values.

    Overlong encodings, invalid continuation bytes, truncated sequences, and surrogate or out-of-range scalar values raise InvalidUTF8 or InvalidUnicodeCodepoint.

    pdf_colour_space_components

    fn pdf_colour_space_components(document : PdfDocument, resources : PdfObject, object : PdfObject) -> Int raise PdfError

    Compatibility wrapper for PdfDocument::colour_space_components.

    pdf_colour_space_of_device_name

    fn pdf_colour_space_of_device_name(name : PdfName) -> PdfColourSpace?

    Parse a built-in PDF device colour-space name.

    Accepts the standard names /DeviceGray, /DeviceRGB, /DeviceCMYK, and /Pattern, together with the abbreviated resource names /G, /RGB, and /CMYK.

    pdf_colour_space_of_object

    fn pdf_colour_space_of_object(object : PdfObject) -> PdfColourSpace?

    Parse a simple colour-space object without consulting resources.

    This recognizes device colour-space names, singleton arrays, and pattern-with-base arrays. Use PdfDocument::read_colour_space when resource lookup, calibrated spaces, ICC profiles, or indexed spaces are needed.

    pdf_content_begin_artifact

    fn pdf_content_begin_artifact() -> PdfContentOp

    Return the marked-content operation that begins a PDF/UA artifact.

    pdf_content_bytes_of_op

    fn pdf_content_bytes_of_op(op : PdfContentOp) -> Bytes raise PdfError

    Serialize one content operator to PDF content-stream bytes.

    pdf_content_bytes_of_ops

    fn pdf_content_bytes_of_ops(ops : ArrayView[PdfContentOp]) -> Bytes raise PdfError

    Serialize content operators to PDF content-stream bytes.

    Operators are separated with whitespace. Op_Unknown bytes are emitted as captured. Inline images with no filter are Flate-encoded and written with inline /F /Fl and /L metadata; inline images with existing filters keep their supplied encoded data and decode parameters.

    pdf_content_concat_stream_views

    fn pdf_content_concat_stream_views(streams : ArrayView[BytesView]) -> Bytes

    Concatenate already-decoded content stream views with a single space between them.

    pdf_content_concat_streams

    fn pdf_content_concat_streams(streams : ArrayView[Bytes]) -> Bytes

    Concatenate already-decoded content streams with a single space between them.

    pdf_content_end_artifact

    fn pdf_content_end_artifact() -> PdfContentOp

    Return the marked-content operation that ends the current PDF/UA artifact.

    pdf_content_stream_of_ops

    fn pdf_content_stream_of_ops(ops : ArrayView[PdfContentOp]) -> PdfObject raise PdfError

    Build an uncompressed PDF stream object from content operators.

    The returned stream dictionary contains /Length for the serialized byte length and no outer stream filter.

    pdf_cryptprimitives_aes_decrypt_data

    fn pdf_cryptprimitives_aes_decrypt_data(nk : Int, key : ArrayView[Int], data : BytesView, remove_padding? : Bool) -> Bytes raise PdfError

    CamlPDF-compatible AES-CBC decrypt helper with integer-array keys.

    nk is the number of 32-bit key words and must match the supplied key.

    pdf_cryptprimitives_aes_decrypt_data_ecb

    fn pdf_cryptprimitives_aes_decrypt_data_ecb(nk : Int, key : ArrayView[Int], data : BytesView, remove_padding? : Bool) -> Bytes raise PdfError

    CamlPDF-compatible AES-ECB decrypt helper with integer-array keys.

    pdf_cryptprimitives_aes_encrypt_data_ecb

    fn pdf_cryptprimitives_aes_encrypt_data_ecb(nk : Int, key : ArrayView[Int], data : BytesView) -> Bytes raise PdfError

    CamlPDF-compatible AES-ECB encrypt helper with integer-array keys.

    pdf_cryptprimitives_aes_encrypt_data_with_firstblock

    fn pdf_cryptprimitives_aes_encrypt_data_with_firstblock(nk : Int, key : ArrayView[Int], data : BytesView, firstblock : BytesView) -> Bytes raise PdfError

    CamlPDF-compatible AES-CBC encrypt helper with explicit first block.

    firstblock is the IV that will be prefixed to the returned encrypted data.

    pdf_cryptprimitives_crypt

    fn pdf_cryptprimitives_crypt(key : ArrayView[Int], data : BytesView) -> Bytes raise PdfError

    CamlPDF-compatible ARC4 helper with integer-array keys.

    The key array is interpreted as big-endian bytes through pdf_bytes_of_int_array.

    pdf_cryptprimitives_decrypt_stream_data

    fn pdf_cryptprimitives_decrypt_stream_data(crypt_type : PdfCryptType, encrypt : Bool, file_encryption_key : BytesView?, object_number : Int, generation : Int, key : ArrayView[Int], key_length_bits : Int, revision : Int, data : BytesView, firstblock? : BytesView?) -> Bytes raise PdfError

    Encrypt or decrypt stream bytes using the selected crypt type.

    For revisions 5 and 6 the supplied file_encryption_key is used directly. For earlier revisions an object key is derived from key. AES encryption requires firstblock as the IV; missing IVs raise RandomBytesUnavailable.

    pdf_cryptprimitives_find_hash

    fn pdf_cryptprimitives_find_hash(crypt_type : PdfCryptType, object_number : Int, generation : Int, key : ArrayView[Int], key_length_bits : Int) -> Array[Int] raise PdfError

    CamlPDF-compatible wrapper returning the object key as an integer array.

    pdf_date_of_bytes

    fn pdf_date_of_bytes(bytes : Bytes) -> PdfDate raise PdfError

    Parses a PDF date from owned PDF bytes.

    pdf_date_of_object

    fn pdf_date_of_object(object : PdfObject) -> PdfDate raise PdfError

    Extracts and parses a PDF date from a PdfString object.

    Raises PdfError::BadDate if the object is not a string or if the date payload is malformed.

    pdf_date_of_string

    fn pdf_date_of_string(text : String) -> PdfDate raise PdfError

    Parses a PDF date from an ASCII string.

    Raises PdfError::BadDate for malformed or out-of-range dates.

    pdf_date_of_view

    fn pdf_date_of_view(bytes : BytesView) -> PdfDate raise PdfError

    Parses a PDF date from a byte view.

    Both strings with and without the D: prefix are accepted. Missing optional date fields use the PDF defaults described on PdfDate. Raises PdfError::BadDate for malformed or out-of-range dates.

    pdf_decode_filter_bytes

    fn pdf_decode_filter_bytes(filter : PdfName, data : Bytes) -> Bytes raise PdfError

    Decode owned bytes with a single PDF filter name.

    Identity and Flate paths avoid an extra copy where possible.

    pdf_decode_filter_view

    fn pdf_decode_filter_view(filter : PdfName, data : BytesView) -> Bytes raise PdfError

    Decode bytes with a single PDF filter name.

    Recognizes long and abbreviated filter names. /Crypt is treated as an identity filter at this byte-dispatch layer; unsupported filters raise FilterNotSupported.

    pdf_decode_predictor

    fn pdf_decode_predictor(predictor : Int, colors : Int, bits_per_component : Int, columns : Int, data : Bytes) -> Bytes raise PdfError

    Owned-byte wrapper for pdf_decode_predictor_view.

    Predictor 1 returns the original owned bytes unchanged.

    pdf_decode_predictor_view

    fn pdf_decode_predictor_view(predictor : Int, colors : Int, bits_per_component : Int, columns : Int, data : BytesView) -> Bytes raise PdfError

    Decode data after applying a PDF predictor.

    Predictor 1 is identity, 2 is TIFF horizontal differencing, and 10..15 are PNG predictors. Invalid image geometry or unsupported predictors raise PdfError.

    pdf_decode_stream

    fn pdf_decode_stream(object : PdfObject) -> PdfObject raise PdfError

    Decode all supported filter stages from a direct stream object.

    pdf_decode_stream_onestage

    fn pdf_decode_stream_onestage(object : PdfObject) -> PdfObject raise PdfError

    Decode exactly one filter stage from a stream object.

    The first filter and matching decode parameters are removed from the stream dictionary, and /Length is refreshed. Non-stream objects raise ParseStreamExpected.

    pdf_decrypt_pdf

    fn pdf_decrypt_pdf(document : PdfDocument, user_password : BytesView, owner_password? : BytesView?, no_encrypt_metadata? : Bool) -> (PdfDocument?, Array[PdfPermission]) raise PdfError

    CamlPDF-shaped decrypt helper returning document and denied permissions.

    A failed authentication returns (None, current_permissions), while malformed encryption dictionaries raise PdfError.

    pdf_decrypt_pdf_owner

    fn pdf_decrypt_pdf_owner(document : PdfDocument, owner_password : BytesView, no_encrypt_metadata? : Bool) -> PdfDocument? raise PdfError

    CamlPDF-shaped owner-password decrypt helper.

    pdf_decrypt_single_stream

    fn pdf_decrypt_single_stream(document : PdfDocument, object_number : Int, generation : Int, stream : PdfObject, user_password? : BytesView?, owner_password? : BytesView?, no_encrypt_metadata? : Bool) -> PdfObject? raise PdfError

    Compatibility wrapper for PdfDocument::decrypt_single_stream.

    pdf_default_version

    let pdf_default_version : PdfVersion

    Fallback version used when a PDF header cannot be found.

    pdf_deterministic_aes_iv_provider_from_seed

    fn pdf_deterministic_aes_iv_provider_from_seed(seed : BytesView) -> ((Int, Int, Int) -> Bytes raise PdfError)

    Build a deterministic AES IV provider from a seed.

    The returned callback derives 16-byte IVs from the seed, object number, generation, and per-object IV index. It is intended for reproducible tests and fixtures; production encryption should use a cryptographically secure random provider.

    pdf_deterministic_aesv3_random_provider_from_seed

    fn pdf_deterministic_aesv3_random_provider_from_seed(seed : BytesView) -> ((PdfAesV3RandomField, Int) -> Bytes raise PdfError)

    Build a deterministic AESV3 random-field provider from a seed.

    The provider derives field-specific bytes for file keys, salts, and permissions padding. It is useful for stable test fixtures, not for production encryption.

    pdf_dictionary

    fn pdf_dictionary(entries : ArrayView[(PdfName, PdfObject)]) -> PdfObject

    Construct a PDF dictionary from a read-only view of name/value entries.

    Entry order is preserved exactly as supplied. Duplicate keys are not normalized by this constructor; lookup helpers return the first matching entry.

    pdf_document_empty

    fn pdf_document_empty() -> PdfDocument

    Construct an empty PDF document with CamlPDF-compatible defaults.

    The default version is 1.0, the root object number is 0, the trailer is an empty dictionary, and revision_read starts at 1.

    pdf_document_of_parsed_indirect_objects

    fn pdf_document_of_parsed_indirect_objects(objects : ArrayView[PdfParsedIndirectObject], version? : PdfVersion) -> PdfDocument

    Build a document from already parsed indirect objects.

    Objects are loaded at their existing object numbers and generations without recording mutation events. The document version defaults to pdf_default_version.

    pdf_encode_filter_bytes

    fn pdf_encode_filter_bytes(filter : PdfName, data : Bytes) -> Bytes raise PdfError

    Encode owned bytes with a single PDF filter name.

    pdf_encode_filter_bytes_with_flate_level

    fn pdf_encode_filter_bytes_with_flate_level(filter : PdfName, data : Bytes, flate_level : Int) -> Bytes raise PdfError

    Encode owned bytes with a single PDF filter name and explicit Flate level.

    pdf_encode_filter_view

    fn pdf_encode_filter_view(filter : PdfName, data : BytesView) -> Bytes raise PdfError

    Encode bytes with a single PDF filter name.

    pdf_encode_filter_view_with_flate_level

    fn pdf_encode_filter_view_with_flate_level(filter : PdfName, data : BytesView, flate_level : Int) -> Bytes raise PdfError

    Encode bytes with a single PDF filter name and explicit Flate level.

    flate_level follows the zlib range accepted by the Flate encoder.

    pdf_encode_predictor

    fn pdf_encode_predictor(predictor : Int, colors : Int, bits_per_component : Int, columns : Int, data : Bytes) -> Bytes raise PdfError

    Owned-byte wrapper for pdf_encode_predictor_view.

    Predictor 1 returns the original owned bytes unchanged.

    pdf_encode_predictor_view

    fn pdf_encode_predictor_view(predictor : Int, colors : Int, bits_per_component : Int, columns : Int, data : BytesView) -> Bytes raise PdfError

    Encode data with a PDF predictor.

    Predictor 1 is identity, 2 is TIFF horizontal differencing, 10..14 use fixed PNG row filters, and 15 chooses the lowest-scoring PNG filter per row.

    pdf_encode_stream_with_encoding

    fn pdf_encode_stream_with_encoding(encoding : PdfStreamEncoding, object : PdfObject, only_if_smaller? : Bool, predictor? : PdfStreamPredictor?, predictor_columns? : Int, flate_level? : Int?) -> PdfObject raise PdfError

    Encode a stream using a typed encoding description.

    CCITT encodings write fax /DecodeParms; other encodings may optionally apply a predictor before the filter. CCITT does not accept predictors.

    pdf_encode_stream_with_filter

    fn pdf_encode_stream_with_filter(filter : PdfName, object : PdfObject, only_if_smaller? : Bool, flate_level? : Int?) -> PdfObject raise PdfError

    Encode a stream object with one filter.

    The new filter is prepended to existing filters and /Length is refreshed. When only_if_smaller is true, the original stream is returned if encoded data is not smaller than the original stream data.

    pdf_encode_stream_with_filter_and_predictor

    fn pdf_encode_stream_with_filter_and_predictor(filter : PdfName, predictor : Int, colors : Int, bits_per_component : Int, columns : Int, object : PdfObject, only_if_smaller? : Bool, flate_level? : Int?) -> PdfObject raise PdfError

    Encode a stream after first applying predictor encoding.

    /DecodeParms are added for the predictor, the filter is prepended, and /Length is refreshed. only_if_smaller compares encoded data against the original stream data.

    pdf_encoding_of_name

    fn pdf_encoding_of_name(name : PdfName) -> PdfEncoding?

    Recognize a built-in simple-font encoding name.

    pdf_encrypt_pdf_128bit

    fn pdf_encrypt_pdf_128bit(document : PdfDocument, user_password : BytesView, owner_password : BytesView, denied_permissions : ArrayView[PdfPermission], file_id? : BytesView) -> PdfDocument raise PdfError

    Compatibility wrapper for PdfDocument::encrypt_128bit.

    pdf_encrypt_pdf_40bit

    fn pdf_encrypt_pdf_40bit(document : PdfDocument, user_password : BytesView, owner_password : BytesView, denied_permissions : ArrayView[PdfPermission], file_id? : BytesView) -> PdfDocument raise PdfError

    Compatibility wrapper for PdfDocument::encrypt_40bit.

    pdf_encrypt_pdf_AES

    fn pdf_encrypt_pdf_AES(document : PdfDocument, encrypt_metadata : Bool, user_password : BytesView, owner_password : BytesView, denied_permissions : ArrayView[PdfPermission], file_id? : BytesView) -> PdfDocument raise PdfError

    CamlPDF-compatible AESV2 encryption wrapper using native randomness.

    pdf_encrypt_pdf_AES256

    fn pdf_encrypt_pdf_AES256(document : PdfDocument, encrypt_metadata : Bool, user_password : BytesView, owner_password : BytesView, denied_permissions : ArrayView[PdfPermission], file_id? : BytesView) -> PdfDocument raise PdfError

    CamlPDF-compatible AESV3/AES-256 encryption wrapper using native randomness.

    pdf_encrypt_pdf_AES256ISO

    fn pdf_encrypt_pdf_AES256ISO(document : PdfDocument, encrypt_metadata : Bool, user_password : BytesView, owner_password : BytesView, denied_permissions : ArrayView[PdfPermission], file_id? : BytesView) -> PdfDocument raise PdfError

    CamlPDF-compatible ISO AESV3/AES-256 encryption wrapper using native randomness.

    pdf_encrypt_pdf_AES256ISO_with_providers

    fn pdf_encrypt_pdf_AES256ISO_with_providers(document : PdfDocument, encrypt_metadata : Bool, user_password : BytesView, owner_password : BytesView, denied_permissions : ArrayView[PdfPermission], random_provider : (PdfAesV3RandomField, Int) -> Bytes raise PdfError, iv_provider : (Int, Int, Int) -> Bytes raise PdfError, file_id? : BytesView) -> PdfDocument raise PdfError

    Compatibility wrapper for ISO AESV3 encryption with caller-supplied providers.

    pdf_encrypt_pdf_AES256_with_providers

    fn pdf_encrypt_pdf_AES256_with_providers(document : PdfDocument, encrypt_metadata : Bool, user_password : BytesView, owner_password : BytesView, denied_permissions : ArrayView[PdfPermission], random_provider : (PdfAesV3RandomField, Int) -> Bytes raise PdfError, iv_provider : (Int, Int, Int) -> Bytes raise PdfError, file_id? : BytesView) -> PdfDocument raise PdfError

    Compatibility wrapper for AESV3 encryption with caller-supplied providers.

    pdf_encrypt_pdf_AES_with_iv_provider

    fn pdf_encrypt_pdf_AES_with_iv_provider(document : PdfDocument, encrypt_metadata : Bool, user_password : BytesView, owner_password : BytesView, denied_permissions : ArrayView[PdfPermission], iv_provider : (Int, Int, Int) -> Bytes raise PdfError, file_id? : BytesView) -> PdfDocument raise PdfError

    Compatibility wrapper for AESV2 encryption with caller-supplied IVs.

    pdf_encryption_file_key

    fn pdf_encryption_file_key(no_encrypt_metadata : Bool, password : BytesView, revision : Int, owner_entry : BytesView, permissions : Int, file_id : BytesView, key_length_bits : Int) -> Bytes

    Derive the standard-security file key from a user password.

    This implements revisions 2-4 key derivation. AESV3 uses wrapped file keys instead and should go through the PdfEncryptionValues helpers.

    pdf_encryption_object_key

    fn pdf_encryption_object_key(crypt_type : PdfCryptType, object_number : Int, generation : Int, file_key : BytesView, key_length_bits : Int) -> Bytes

    Derive the per-object encryption key for a PDF object.

    The object number, generation, file key, key length, and AESV2 salt are hashed according to the PDF standard-security object-key algorithm.

    pdf_endpage

    fn pdf_endpage(document : PdfDocument) -> Int raise PdfError

    Compatibility wrapper for PdfDocument::endpage.

    pdf_endpage_fast

    fn pdf_endpage_fast(document : PdfDocument) -> Int raise PdfError

    Compatibility wrapper for PdfDocument::endpage_fast.

    pdf_eval_function

    fn pdf_eval_function(function : PdfFunction, inputs : ArrayView[Double]) -> Array[Double] raise PdfError

    Compatibility wrapper for PdfFunction::eval.

    pdf_flate_decode

    fn pdf_flate_decode(data : Bytes) -> Bytes raise PdfError

    Decode a zlib-wrapped Flate stream from owned bytes.

    On the native target this uses zlib FFI with a pure MoonBit fallback.

    pdf_flate_decode_view

    fn pdf_flate_decode_view(data : BytesView) -> Bytes raise PdfError

    Decode a zlib-wrapped Flate stream from a borrowed byte view.

    On the native target this tries zlib FFI first and falls back to the pure MoonBit decoder if the native call fails. Invalid compressed data raises InvalidFlateData.

    pdf_flate_encode

    fn pdf_flate_encode(data : Bytes) -> Bytes

    Encode owned bytes with the default compression level.

    On the native target this tries zlib at level 6 and falls back to the pure MoonBit encoder if the native call fails.

    pdf_flate_encode_view

    fn pdf_flate_encode_view(data : BytesView) -> Bytes

    Encode borrowed bytes with the default compression level.

    On the native target this tries zlib at level 6 and falls back to the pure MoonBit encoder if the native call fails.

    pdf_flate_encode_view_with_level

    fn pdf_flate_encode_view_with_level(data : BytesView, level : Int) -> Bytes raise PdfError

    Encode borrowed bytes as a zlib-wrapped Flate stream.

    level must be in the zlib range 0..9; invalid levels raise InvalidFlateData. On the native target this tries the zlib FFI first and falls back to the pure MoonBit encoder if the native call fails.

    pdf_flate_encode_with_level

    fn pdf_flate_encode_with_level(data : Bytes, level : Int) -> Bytes raise PdfError

    Encode owned bytes as a zlib-wrapped Flate stream.

    level must be in the zlib range 0..9; invalid levels raise InvalidFlateData. On the native target this uses zlib FFI with a pure MoonBit fallback.

    pdf_format_real

    fn pdf_format_real(value : Double) -> Bytes raise PdfError

    Compatibility alias for pdf_write_real.

    pdf_generate_id

    fn pdf_generate_id(path : String, get_time : () -> Double) -> PdfObject

    Generates a PDF trailer /ID array from a path and caller-supplied time source.

    The digest construction follows CamlPDF's path-plus-time behavior. When CAMLPDF_REPRODUCIBLE_IDS=true, the seed is fixed so tests and reproducible builds can produce stable IDs.

    pdf_get_encryption_values

    fn pdf_get_encryption_values(document : PdfDocument) -> PdfEncryptionValues raise PdfError

    Compatibility wrapper for PdfDocument::encryption_values.

    pdf_get_image_24bpp

    fn pdf_get_image_24bpp(document : PdfDocument, resources : PdfObject, image : PdfObject) -> PdfImage raise PdfError

    Compatibility wrapper for PdfDocument::get_image_24bpp.

    pdf_get_jpeg_data

    fn pdf_get_jpeg_data(input : ByteCursor) -> Bytes raise PdfError

    Reads JPEG data from a cursor through the EOI marker.

    This is the standalone form of ByteCursor::read_jpeg_data.

    pdf_glyphnames_of_text

    fn pdf_glyphnames_of_text(extractor : PdfTextExtractor, text : BytesView) -> Array[PdfName] raise PdfError

    Compatibility wrapper for PdfTextExtractor::glyphnames_of_text.

    pdf_image_bpc

    fn pdf_image_bpc(document : PdfDocument, image : PdfObject) -> PdfObject?

    Compatibility wrapper for PdfDocument::bpc.

    pdf_image_colspace

    fn pdf_image_colspace(document : PdfDocument, image : PdfObject, resources : PdfObject) -> PdfColourSpace raise PdfError

    Compatibility wrapper for PdfDocument::colspace.

    pdf_int_array_of_bytes

    fn pdf_int_array_of_bytes(bytes : BytesView) -> Array[Int]

    Converts bytes to an array of integer byte values.

    pdf_is_delimiter_byte

    fn pdf_is_delimiter_byte(value : Int) -> Bool

    Return whether a byte is a PDF token delimiter.

    Delimiters are parentheses, slash, angle brackets, square brackets, braces, and percent.

    pdf_is_encrypted

    fn pdf_is_encrypted(document : PdfDocument) -> Bool

    Compatibility wrapper for PdfDocument::is_encrypted.

    pdf_is_identity_h

    fn pdf_is_identity_h(font : PdfFont) -> Bool

    Compatibility wrapper for PdfFont::is_identity_h.

    pdf_is_linearized

    fn pdf_is_linearized(data : BytesView) -> Bool

    Return whether the input appears to be a linearized PDF.

    The check reads the first indirect object after the header and looks for a numeric /Linearized entry. Parse failures are treated as false.

    pdf_is_newline_byte

    fn pdf_is_newline_byte(value : Int) -> Bool

    Return whether a byte is a PDF line break byte.

    pdf_is_not_whitespace_byte

    fn pdf_is_not_whitespace_byte(value : Int) -> Bool

    Return whether a byte is not PDF white space.

    pdf_is_unicode_string

    fn pdf_is_unicode_string(bytes : BytesView) -> Bool

    Test whether a PDF string starts with the UTF-16BE byte-order mark.

    PDF "Unicode strings" are byte strings beginning with FE FF; the input is intentionally a BytesView rather than a MoonBit String.

    pdf_is_whitespace_byte

    fn pdf_is_whitespace_byte(value : Int) -> Bool

    Return whether a byte is PDF white space.

    Recognized values are NUL, horizontal tab, line feed, form feed, carriage return, and space.

    pdf_is_whitespace_or_delimiter_byte

    fn pdf_is_whitespace_or_delimiter_byte(value : Int) -> Bool

    Return whether a byte terminates a regular PDF token.

    pdf_lex_bytes

    fn pdf_lex_bytes(data : Bytes) -> Array[PdfLexeme] raise PdfError

    Lex all tokens from owned PDF bytes.

    pdf_lex_single_view

    fn pdf_lex_single_view(data : BytesView) -> PdfLexeme raise PdfError

    Lex a single token from a borrowed byte view.

    pdf_lex_view

    fn pdf_lex_view(data : BytesView) -> Array[PdfLexeme] raise PdfError

    Lex all tokens from a borrowed byte view.

    pdf_lexeme_debug_name

    fn pdf_lexeme_debug_name(lexeme : PdfLexeme) -> String

    Return the constructor name of a lexeme for diagnostics and snapshots.

    pdf_lzw_decode

    fn pdf_lzw_decode(data : Bytes, early_change? : Int) -> Bytes raise PdfError

    Owned-byte wrapper for pdf_lzw_decode_view.

    pdf_lzw_decode_view

    fn pdf_lzw_decode_view(data : BytesView, early_change? : Int) -> Bytes raise PdfError

    Decode PDF LZW data from a byte view.

    early_change controls when code width grows; PDF streams default to 1. Malformed codes or bitstream errors raise InvalidLZWData.

    pdf_make_font

    fn pdf_make_font(fontname : PdfName, encoding : PdfEncoding) -> PdfObject raise PdfError

    Build a simple Type 1 font dictionary for a base font and named encoding.

    Only encodings with a direct PDF name can be written this way; custom or implicit encodings raise EncodingWriteUnsupported.

    pdf_make_hex_pdf_string

    fn pdf_make_hex_pdf_string(bytes : BytesView) -> Bytes

    Compatibility alias for pdf_write_hex_string.

    pdf_make_owner_password_entry

    fn pdf_make_owner_password_entry(revision : Int, owner_password : BytesView, user_password : BytesView, key_length_bits : Int) -> Bytes raise PdfError

    Build the /O owner-password entry for revisions 2-4.

    A blank owner password follows PDF behavior by using the user password as the owner-password source.

    pdf_make_pdf_string

    fn pdf_make_pdf_string(bytes : BytesView) -> Bytes

    Compatibility alias for pdf_write_literal_string.

    pdf_make_user_password_entry

    fn pdf_make_user_password_entry(no_encrypt_metadata : Bool, user_password : BytesView, revision : Int, owner_entry : BytesView, permissions : Int, file_id : BytesView, key_length_bits : Int) -> Bytes raise PdfError

    Build the /U user-password entry for revisions 2-4.

    The entry is derived from the user password, owner entry, permission mask, file ID, key length, and metadata-encryption flag.

    pdf_md5_digest

    fn pdf_md5_digest(data : BytesView) -> Bytes

    Return the MD5 digest of data.

    pdf_merge_documents

    fn pdf_merge_documents(documents : ArrayView[PdfDocument], ranges : ArrayView[Array[Int]], retain_numbering? : Bool, retain_bookmarks? : Bool, retain_optional_content? : Bool, retain_acroforms? : Bool, retain_named_destinations? : Bool, retain_name_dictionary? : Bool, retain_structure_tree? : Bool, add_toplevel_document? : Bool, retain_info? : Bool, retain_catalog_entries? : Bool, remove_duplicate_fonts? : Bool) -> PdfDocument raise PdfError

    Merges selected page ranges from multiple documents into one document.

    Each entry in ranges belongs to the document at the same index and uses one-based page numbers. The retain flags control whether numbering, bookmarks, optional-content data, AcroForms, named destinations, name dictionary entries, structure trees, info dictionaries, and catalog entries are copied into the output. Raises PdfError::PageTreeExpected when the document and range lists do not align.

    pdf_merge_name_trees_no_clash

    fn pdf_merge_name_trees_no_clash(document : PdfDocument, trees : ArrayView[PdfObject]) -> PdfObject

    Compatibility wrapper for PdfDocument::merge_name_trees_no_clash.

    pdf_merge_number_trees_no_clash

    fn pdf_merge_number_trees_no_clash(document : PdfDocument, trees : ArrayView[PdfObject]) -> PdfObject

    Compatibility wrapper for PdfDocument::merge_number_trees_no_clash.

    pdf_merge_pdfs

    fn pdf_merge_pdfs(retain_numbering : Bool, remove_duplicate_fonts : Bool, names : ArrayView[String], documents : ArrayView[PdfDocument], ranges : ArrayView[Array[Int]], process_struct_trees? : Bool, add_toplevel_document? : Bool) -> PdfDocument raise PdfError

    CamlPDF-shaped convenience wrapper for merging PDFs.

    names must have the same length as documents; it is retained for API compatibility with CamlPDF's merge entry point. Structure-tree processing and optional top-level /Document wrapping are controlled by the optional flags.

    pdf_merge_structure_trees

    fn pdf_merge_structure_trees(document : PdfDocument, documents : ArrayView[PdfDocument], add_toplevel_document? : Bool) -> Int? raise PdfError

    Merge structure tree roots from source documents into a target document.

    Returns the resulting structure-tree root object number, or None when no source document has a structure tree. When multiple roots are merged, parent trees and root metadata are combined in document; add_toplevel_document wraps merged children in a PDF 2.0 top-level /Document structure element.

    pdf_minimum_valid_pdf

    fn pdf_minimum_valid_pdf() -> PdfDocument raise PdfError

    Build the smallest useful PDF document: one blank A4 page and a catalog.

    pdf_name_of_bytes

    fn pdf_name_of_bytes(bytes : Bytes) -> PdfName

    Wraps owned bytes as a PDF name without copying.

    The bytes are expected to be the name payload without the leading slash.

    pdf_name_of_colour_space

    fn pdf_name_of_colour_space(space : PdfColourSpace) -> PdfName?

    Compatibility wrapper for PdfColourSpace::name.

    pdf_name_of_view

    fn pdf_name_of_view(bytes : BytesView) -> PdfName

    Copies a byte view and wraps it as a PDF name.

    The bytes are expected to be the name payload without the leading slash.

    pdf_no_more

    let pdf_no_more : Int

    Sentinel returned by legacy byte-reading helpers when the cursor is past the end of input.

    Newer APIs usually return Byte?, but this value preserves the CamlPDF-style integer cursor contract used by parser code.

    pdf_object_entry

    fn pdf_object_entry(data : PdfObjectData, generation? : Int) -> PdfObjectEntry

    Construct an object-table entry.

    The generation defaults to 0, matching newly created PDF objects.

    pdf_object_map_empty

    fn pdf_object_map_empty() -> PdfObjectMap

    Construct an empty object-number map.

    pdf_object_of_colour_space

    fn pdf_object_of_colour_space(space : PdfColourSpace) -> PdfObject?

    Convert a parsed colour space back into a PDF object.

    Returns None when the colour space cannot be serialized losslessly, such as an indexed table with invalid component values or a base colour space that itself cannot be represented.

    pdf_object_of_date

    fn pdf_object_of_date(date : PdfDate) -> PdfObject raise PdfError

    Formats a PDF date as a PdfString object.

    Raises PdfError::BadDate if any field is outside the representable PDF date ranges.

    pdf_object_of_destination

    fn pdf_object_of_destination(destination : PdfDestination) -> PdfObject

    Converts a normalized destination back to a PDF object.

    pdf_object_of_function

    fn pdf_object_of_function(document : PdfDocument, function : PdfFunction) -> PdfObject

    Compatibility wrapper for PdfDocument::pdf_object_of_function.

    pdf_object_of_matrix

    fn pdf_object_of_matrix(matrix : TransformMatrix) -> PdfObject

    Convert a transformation matrix into its six-number PDF array form.

    pdf_objects_empty

    fn pdf_objects_empty() -> PdfObjects

    Construct an empty document object table.

    The next allocated object number will be 1; the mutation log starts empty.

    pdf_objects_of_entries

    fn pdf_objects_of_entries(entries : ArrayView[(Int, PdfObjectEntry)]) -> PdfObjects

    Build a document object table from explicit numbered entries.

    Entries are installed without recording alteration events. The maximum object number is derived from the supplied numbers.

    pdf_ocg_default_config

    fn pdf_ocg_default_config() -> PdfOcgConfig

    Return the PDF default optional-content configuration used when none is set.

    The default has base state OcgOn, /Intent /View, no explicit on/off lists, no order, no radio-button groups, and no locked groups.

    pdf_of_pages

    fn pdf_of_pages(document : PdfDocument, page_numbers : ArrayView[Int], retain_numbering? : Bool, process_struct_tree? : Bool) -> PdfDocument raise PdfError

    Compatibility wrapper for PdfDocument::pdf_of_pages.

    pdf_optional_content_merge

    fn pdf_optional_content_merge(documents : ArrayView[PdfDocument]) -> PdfOptionalContent? raise PdfError

    Merge optional-content metadata from already-renumbered documents.

    Documents without optional content are skipped. Indirect object numbers are copied as-is into the merged result, so callers must renumber source documents before merging when object numbers may collide.

    pdf_p_of_permissions

    fn pdf_p_of_permissions(permissions : ArrayView[PdfPermission]) -> Int

    Convert denied permissions to a PDF /P permission mask.

    The input is a ban list. Required reserved bits are set according to the PDF standard-security-handler convention.

    pdf_pad_password

    fn pdf_pad_password(password : BytesView) -> Bytes

    Pad or truncate a raw PDF password to 32 bytes.

    Passwords are byte sequences. Inputs longer than 32 bytes are truncated; shorter inputs are filled with the standard PDF padding sequence.

    pdf_page_blank

    fn pdf_page_blank(paper : PaperSize) -> PdfPage

    Build a blank page for a named paper size.

    pdf_page_custom

    fn pdf_page_custom(rectangle : PdfObject) -> PdfPage

    Build a blank page using an explicit PDF rectangle object as /MediaBox.

    pdf_page_int_of_rotation

    fn pdf_page_int_of_rotation(rotation : PdfPageRotation) -> Int

    Convert a normalized page rotation to the integer stored in /Rotate.

    pdf_page_label_add_label

    fn pdf_page_label_add_label(end_page : Int, labels : ArrayView[PdfPageLabel], label : PdfPageLabel, range_end_page : Int) -> Array[PdfPageLabel]

    Insert or replace a label range over a page interval.

    Existing ranges after range_end_page are preserved, and a continuation range is inserted when needed so later labels keep their previous numbering.

    pdf_page_label_basic

    let pdf_page_label_basic : PdfPageLabel

    Default decimal page-label range starting at page 1 with value 1.

    pdf_page_label_coalesce

    fn pdf_page_label_coalesce(labels : ArrayView[PdfPageLabel]) -> Array[PdfPageLabel]

    Collapse adjacent page-label ranges that produce the same numbering stream.

    Ranges are merged only when their style, prefix, and start_page -start_value offset are identical, so visible labels for every page remain unchanged.

    pdf_page_label_complete

    fn pdf_page_label_complete(labels : ArrayView[PdfPageLabel]) -> Array[PdfPageLabel]

    Ensure a label list has an initial range covering page 1.

    Empty lists or lists that start after page 1 receive pdf_page_label_basic.

    pdf_page_label_merge

    fn pdf_page_label_merge(pdfs : ArrayView[PdfDocument], ranges : ArrayView[Array[Int]]) -> Array[PdfPageLabel] raise PdfError

    Merge page labels for selected pages from several source documents.

    ranges contains 1-based source page numbers for each document. The merged result preserves the visible labels from those source pages at their new concatenated positions and coalesces adjacent equivalent ranges.

    Raises if the document and range arrays have different lengths, or if a source document's page-label tree cannot be read.

    pdf_page_label_of_page_number

    fn pdf_page_label_of_page_number(page_number : Int, labels : ArrayView[PdfPageLabel]) -> PdfPageLabel?

    Find the active page-label range for a 1-based page number.

    The input ranges are expected in document order. Returns None when the document has no page-label ranges.

    pdf_page_label_of_single

    fn pdf_page_label_of_single(page_number : Int, label : PdfPageLabel) -> PdfPageLabel

    Return the effective page-label range for one concrete page.

    The returned range keeps the style and prefix, but normalizes start_page and start_value to the numeric value displayed on page_number.

    pdf_page_label_style_of_string

    fn pdf_page_label_style_of_string(text : String) -> PdfPageLabelStyle raise PdfError

    Parse a debug-style page-label style name.

    Unknown names raise PageLabelStyleExpected.

    pdf_page_label_text_of_page_number

    fn pdf_page_label_text_of_page_number(page_number : Int, labels : ArrayView[PdfPageLabel]) -> Bytes?

    Render the visible label text for a 1-based page number.

    Returns None when there are no label ranges. Label prefixes are returned as raw PDF bytes, preserving the encoding stored in the PDF string.

    pdf_page_label_text_of_single

    fn pdf_page_label_text_of_single(page_number : Int, label : PdfPageLabel) -> Bytes

    Render the visible label text for one page within a label range.

    The optional prefix bytes are copied first. The numeric suffix is calculated from the range's 1-based start_page and start_value, then formatted with the range style.

    pdf_page_object_number

    fn pdf_page_object_number(document : PdfDocument, page_number : Int) -> Int? raise PdfError

    Compatibility wrapper for PdfDocument::page_object_number.

    pdf_page_process_stub

    fn[A, B, C] pdf_page_process_stub(process : (A, B) -> C raise, number : A, page : B) -> (C, A, TransformMatrix) raise

    Adapter for callbacks that process page-like values and return identity geometry.

    This preserves the CamlPDF callback shape by returning the callback result, original number, and identity transform matrix.

    pdf_page_protect

    fn pdf_page_protect(ops : ArrayView[PdfContentOp]) -> Array[PdfContentOp]

    Return balancing graphics-state operators for an existing operator list.

    If the list contains more q saves than Q restores, matching restores are returned. Otherwise the result is empty.

    pdf_page_rectangle_of_paper

    fn pdf_page_rectangle_of_paper(paper : PaperSize) -> PdfObject

    Build a PDF rectangle object for a named paper size.

    The rectangle is [0 0 width height] in points.

    pdf_page_reference_numbers

    fn pdf_page_reference_numbers(document : PdfDocument) -> Array[Int] raise PdfError

    Compatibility wrapper for PdfDocument::page_reference_numbers.

    pdf_page_rotation_of_int

    fn pdf_page_rotation_of_int(value : Int) -> PdfPageRotation raise PdfError

    Convert a PDF /Rotate integer to a normalized rotation.

    Multiples equivalent to 0, 90, 180, and 270 degrees are accepted. Other values raise PageRotationExpected.

    pdf_pagenumber_of_target

    fn pdf_pagenumber_of_target(document : PdfDocument, destination : PdfDestination) -> Int raise PdfError

    Compatibility wrapper for PdfDocument::page_number_of_target.

    pdf_pages_of_pagetree

    fn pdf_pages_of_pagetree(document : PdfDocument) -> Array[PdfPage] raise PdfError

    Compatibility wrapper for PdfDocument::pages_of_pagetree.

    pdf_parse_cmap

    fn pdf_parse_cmap(document : PdfDocument, cmap : PdfObject) -> PdfParsedCMap raise PdfError

    Compatibility wrapper for PdfDocument::parse_cmap.

    pdf_parse_cmap_data

    fn pdf_parse_cmap_data(data : BytesView) -> PdfParsedCMap

    Parse raw CMap or ToUnicode bytes into mapping tables and metadata.

    The parser accepts common CMap sections such as code-space ranges, bfchar/bfrange, CID ranges, notdef ranges, /UseCMap, /WMode, and CID-system metadata. Unrecognized or malformed sections are skipped rather than causing a document-level failure.

    pdf_parse_content_ops_from_bytes

    fn pdf_parse_content_ops_from_bytes(data : Bytes) -> Array[PdfContentOp] raise PdfError

    Parse standalone content bytes without document or resource context.

    This is suitable for ordinary operators and inline images that can be read from explicit length or filter markers. Use the document methods when stream decoding or resource-based inline-image sizing is required.

    pdf_parse_content_ops_from_view

    fn pdf_parse_content_ops_from_view(data : BytesView) -> Array[PdfContentOp] raise PdfError

    Parse a standalone content byte view without document or resource context.

    pdf_parse_function

    fn pdf_parse_function(document : PdfDocument, function_object : PdfObject) -> PdfFunction raise PdfError

    Compatibility wrapper for PdfDocument::parse_function.

    pdf_parse_indirect_object_from_bytes

    fn pdf_parse_indirect_object_from_bytes(data : Bytes) -> PdfParsedIndirectObject raise PdfError

    Parses one indirect object from owned PDF bytes.

    pdf_parse_indirect_object_from_view

    fn pdf_parse_indirect_object_from_view(data : BytesView) -> PdfParsedIndirectObject raise PdfError

    Parses one indirect object from a byte view.

    pdf_parse_indirect_object_lexemes

    fn pdf_parse_indirect_object_lexemes(lexemes : ArrayView[PdfLexeme]) -> PdfParsedIndirectObject raise PdfError

    Parses one indirect object from lexemes.

    Raises PdfError::ParseIndirectObjectExpected if the input does not start with an indirect object header.

    pdf_parse_indirect_objects

    fn pdf_parse_indirect_objects(lexemes : ArrayView[PdfLexeme]) -> Array[PdfParsedIndirectObject] raise PdfError

    Parses every complete indirect object from a lexeme sequence.

    Raises PdfError::ParseIndirectObjectExpected when an expected indirect object header is malformed.

    pdf_parse_lexemes

    fn pdf_parse_lexemes(lexemes : ArrayView[PdfLexeme]) -> Array[PdfObject] raise PdfError

    Parses all top-level PDF objects from lexemes.

    Comments are skipped. Arrays and dictionaries are parsed recursively, and indirect-reference triples are collapsed into PdfIndirect objects.

    pdf_parse_object_from_bytes

    fn pdf_parse_object_from_bytes(data : Bytes) -> PdfObject raise PdfError

    Lexes and parses exactly one PDF object from owned PDF bytes.

    pdf_parse_object_from_view

    fn pdf_parse_object_from_view(data : BytesView) -> PdfObject raise PdfError

    Lexes and parses exactly one PDF object from a byte view.

    pdf_parse_single_lexeme_object

    fn pdf_parse_single_lexeme_object(lexemes : ArrayView[PdfLexeme]) -> PdfObject raise PdfError

    Parses exactly one top-level PDF object from lexemes.

    Raises PdfError::ParseSingleObjectExpected if the input contains zero or more than one object.

    pdf_parse_stream_object_from_bytes

    fn pdf_parse_stream_object_from_bytes(data : Bytes) -> PdfParsedIndirectObject raise PdfError

    Parse a single indirect stream object from owned bytes.

    The input should contain one indirect-object header, a stream dictionary, stream data, endstream, and endobj.

    pdf_parse_stream_object_from_view

    fn pdf_parse_stream_object_from_view(data : BytesView) -> PdfParsedIndirectObject raise PdfError

    Parse a single indirect stream object from a borrowed byte view.

    Malformed /Length values are recovered by scanning to endstream when possible, matching the stream recovery used by the primitive reader.

    pdf_password_padding

    fn pdf_password_padding() -> Bytes

    Return the standard 32-byte PDF password padding sequence.

    pdf_pdfdocencoding_byte_of_codepoint

    fn pdf_pdfdocencoding_byte_of_codepoint(codepoint : Int) -> Byte?

    Return the PDFDocEncoding byte for a Unicode codepoint, if representable.

    The lookup preserves CamlPDF compatibility for the fi ligature by mapping U+FB01 to byte 0x93.

    pdf_pdfdocencoding_of_codepoints

    fn pdf_pdfdocencoding_of_codepoints(codepoints : ArrayView[Int]) -> Bytes?

    Encode codepoints as PDFDocEncoding when every scalar is representable.

    Returns None instead of falling back to UTF-16BE; use pdf_pdfdocstring_of_codepoints for the PDF string policy fallback.

    pdf_pdfdocstring_of_codepoints

    fn pdf_pdfdocstring_of_codepoints(codepoints : ArrayView[Int]) -> Bytes raise PdfError

    Encode codepoints as a PDF string.

    PDFDocEncoding is used when all codepoints are representable; otherwise the result is a BOM-prefixed UTF-16BE string.

    pdf_pdfdocstring_of_utf8

    fn pdf_pdfdocstring_of_utf8(bytes : BytesView) -> Bytes raise PdfError

    Convert UTF-8 bytes to the compact PDF string representation.

    The result uses PDFDocEncoding when possible and UTF-16BE otherwise.

    pdf_permissions

    fn pdf_permissions(document : PdfDocument) -> Array[PdfPermission] raise PdfError

    Compatibility wrapper for PdfDocument::permissions.

    pdf_permissions_of_p

    fn pdf_permissions_of_p(mask : Int) -> Array[PdfPermission]

    Decode a PDF /P permission mask to denied permissions.

    The returned array is a ban list ordered from later permission bits down to basic print/edit/copy permissions.

    pdf_postpend_operators

    fn pdf_postpend_operators(document : PdfDocument, operators : ArrayView[PdfContentOp], page : PdfPage, fast? : Bool) -> PdfPage raise PdfError

    Compatibility wrapper for PdfDocument::postpend_operators.

    pdf_prepend_operators

    fn pdf_prepend_operators(document : PdfDocument, operators : ArrayView[PdfContentOp], page : PdfPage, fast? : Bool) -> PdfPage raise PdfError

    Compatibility wrapper for PdfDocument::prepend_operators.

    pdf_print_function

    fn pdf_print_function(function : PdfFunction) -> Unit

    Print the function's diagnostic representation to standard output.

    pdf_read_afm

    fn pdf_read_afm(data : BytesView) -> PdfAfmData raise PdfError

    Parses Adobe Font Metrics data from bytes.

    The parser extracts top-level headers, character widths, name-width pairs, and kerning pairs. Raises PdfError::AfmExpected or PdfError::NumberExpected for malformed metric sections.

    pdf_read_bookmarks

    fn pdf_read_bookmarks(document : PdfDocument, preserve_actions? : Bool) -> Array[PdfBookmark] raise PdfError

    Compatibility wrapper for PdfDocument::read_bookmarks.

    pdf_read_classic_document_from_bytes

    fn pdf_read_classic_document_from_bytes(data : Bytes) -> PdfDocument raise PdfError

    Read a classic-xref PDF from owned bytes.

    pdf_read_classic_document_from_view

    fn pdf_read_classic_document_from_view(data : BytesView) -> PdfDocument raise PdfError

    Read a PDF using classic xref metadata.

    This strict reader follows startxref, xref tables/streams, and trailer /Prev links, loads referenced objects, resolves object streams, and records document metadata. It does not use reconstruction fallback.

    pdf_read_classic_document_revision_from_bytes

    fn pdf_read_classic_document_revision_from_bytes(data : Bytes, revision : Int) -> PdfDocument raise PdfError

    Read one classic-xref document revision from owned bytes.

    pdf_read_classic_document_revision_from_view

    fn pdf_read_classic_document_revision_from_view(data : BytesView, revision : Int) -> PdfDocument raise PdfError

    Read one classic-xref document revision.

    Revision 1 is the newest revision; larger revision numbers select older revisions by following trailer /Prev links. Invalid or unavailable revisions raise BadRevision.

    pdf_read_colour_space

    fn pdf_read_colour_space(document : PdfDocument, resources : PdfObject, object : PdfObject) -> PdfColourSpace? raise PdfError

    Compatibility wrapper for PdfDocument::read_colour_space.

    pdf_read_destination

    fn pdf_read_destination(document : PdfDocument, object : PdfObject, shallow? : Bool) -> PdfDestination raise PdfError

    Reads and normalizes a PDF destination object.

    This is the standalone form of PdfDocument::read_destination.

    pdf_read_document_from_bytes

    fn pdf_read_document_from_bytes(data : Bytes) -> PdfDocument raise PdfError

    Read a PDF document from owned PDF bytes.

    pdf_read_document_from_bytes_with_passwords

    fn pdf_read_document_from_bytes_with_passwords(data : Bytes, user_password? : BytesView?, owner_password? : BytesView?) -> PdfDecryptionResult? raise PdfError

    Read and decrypt a PDF document from owned PDF bytes.

    pdf_read_document_from_view

    fn pdf_read_document_from_view(data : BytesView) -> PdfDocument raise PdfError

    Read a PDF document from a borrowed byte view.

    This is the high-level non-password reader. It first tries the strict classic xref reader and probes the page tree; for selected structural errors it falls back to reconstruction by scanning indirect objects.

    pdf_read_document_from_view_with_passwords

    fn pdf_read_document_from_view_with_passwords(data : BytesView, user_password? : BytesView?, owner_password? : BytesView?) -> PdfDecryptionResult? raise PdfError

    Read and decrypt a PDF document using optional passwords.

    This is the high-level password-aware reader. It uses the same reconstruction fallback policy as pdf_read_document_from_view before attempting decryption. Unencrypted documents return a copied document inside Some(...).

    pdf_read_document_revision_from_bytes

    fn pdf_read_document_revision_from_bytes(data : Bytes, revision : Int) -> PdfDocument raise PdfError

    Read one document revision from owned PDF bytes.

    pdf_read_document_revision_from_bytes_with_passwords

    fn pdf_read_document_revision_from_bytes_with_passwords(data : Bytes, revision : Int, user_password? : BytesView?, owner_password? : BytesView?) -> PdfDecryptionResult? raise PdfError

    Read and decrypt one PDF revision from owned bytes.

    pdf_read_document_revision_from_view

    fn pdf_read_document_revision_from_view(data : BytesView, revision : Int) -> PdfDocument raise PdfError

    Read one document revision from a borrowed byte view.

    Revision selection uses strict classic-xref parsing and does not use the reconstruction fallback used by pdf_read_document_from_view.

    pdf_read_document_revision_from_view_with_passwords

    fn pdf_read_document_revision_from_view_with_passwords(data : BytesView, revision : Int, user_password? : BytesView?, owner_password? : BytesView?) -> PdfDecryptionResult? raise PdfError

    Read and decrypt one PDF revision using optional passwords.

    Revision 1 is the newest revision. The returned value is None when the document is encrypted and neither supplied password can decrypt it; otherwise it contains the decrypted document and permission information.

    pdf_read_font

    fn pdf_read_font(document : PdfDocument, font : PdfObject) -> PdfFont raise PdfError

    Compatibility wrapper for PdfDocument::read_font.

    pdf_read_header_from_bytes

    fn pdf_read_header_from_bytes(data : Bytes) -> PdfVersion raise PdfError

    Read a PDF header version from owned PDF bytes.

    pdf_read_header_from_view

    fn pdf_read_header_from_view(data : BytesView) -> PdfVersion raise PdfError

    Read a PDF header version from a borrowed byte view.

    pdf_read_name_tree

    fn pdf_read_name_tree(document : PdfDocument, tree : PdfObject) -> Array[(Bytes, PdfObject)]

    Compatibility wrapper for PdfDocument::read_name_tree.

    pdf_read_number_tree

    fn pdf_read_number_tree(document : PdfDocument, tree : PdfObject) -> Array[(Bytes, PdfObject)]

    Compatibility wrapper that returns number-tree keys as decimal ASCII bytes.

    This mirrors APIs that represent both name and number tree keys as PdfBytes; each integer key is encoded with Int::to_string.

    pdf_read_ocg

    fn pdf_read_ocg(document : PdfDocument) -> PdfOptionalContent? raise PdfError

    Compatibility wrapper for PdfDocument::read_optional_content_groups.

    pdf_read_page_labels

    fn pdf_read_page_labels(document : PdfDocument) -> Array[PdfPageLabel] raise PdfError

    Compatibility wrapper for PdfDocument::read_page_labels.

    pdf_read_primitive_document_from_bytes

    fn pdf_read_primitive_document_from_bytes(data : Bytes) -> PdfDocument raise PdfError

    Parse a primitive document from owned PDF bytes.

    pdf_read_primitive_document_from_view

    fn pdf_read_primitive_document_from_view(data : BytesView) -> PdfDocument raise PdfError

    Parse indirect objects by scanning the byte stream without xref tables.

    This primitive reader is useful for fixtures and damaged files. It reads the header, then scans indirect object syntax and stream bodies in sequence; it does not interpret trailer/xref metadata or decrypt the document.

    pdf_recrypt_pdf

    fn pdf_recrypt_pdf(document : PdfDocument, password : BytesView, renumber? : Bool) -> PdfDocument raise PdfError

    Re-encrypt a decrypted ARC4 document, optionally compact-renumbering first.

    AES documents require pdf_recrypt_pdf_with_iv_provider so fresh IVs can be supplied.

    pdf_recrypt_pdf_with_iv_provider

    fn pdf_recrypt_pdf_with_iv_provider(document : PdfDocument, password : BytesView, iv_provider : (Int, Int, Int) -> Bytes raise PdfError, renumber? : Bool) -> PdfDocument raise PdfError

    Re-encrypt a decrypted document, optionally compact-renumbering first.

    AES documents use iv_provider; ARC4 documents ignore it. The input must carry saved encryption state from a previous decrypt.

    pdf_recurse_array

    fn pdf_recurse_array(transform : (PdfObject) -> PdfObject, values : ArrayView[PdfObject]) -> PdfObject

    Apply a one-level transformation to array elements.

    This helper does not recursively traverse nested dictionaries or arrays by itself; callers provide a transform that decides how each child object is rewritten.

    pdf_recurse_dict

    fn pdf_recurse_dict(transform : (PdfObject) -> PdfObject, entries : ArrayView[(PdfName, PdfObject)], preserve_order? : Bool) -> PdfObject

    Apply a one-level transformation to dictionary values.

    By default the resulting dictionary entries are reversed to match the historical CamlPDF construction order. Pass preserve_order=true when the incoming order must be retained.

    pdf_remove_bookmarks

    fn pdf_remove_bookmarks(document : PdfDocument) -> PdfDocument raise PdfError

    Compatibility wrapper for PdfDocument::remove_bookmarks.

    pdf_remove_duplicate_fonts

    fn pdf_remove_duplicate_fonts(document : PdfDocument) -> Unit

    Removes duplicate embedded font streams from a document.

    This is the standalone form of PdfDocument::remove_duplicate_fonts.

    pdf_remove_ocg

    fn pdf_remove_ocg(document : PdfDocument) -> PdfDocument raise PdfError

    Compatibility wrapper for PdfDocument::remove_optional_content_groups.

    pdf_remove_page_labels

    fn pdf_remove_page_labels(document : PdfDocument) -> PdfDocument raise PdfError

    Compatibility wrapper for PdfDocument::remove_page_labels.

    pdf_renumber_documents

    fn pdf_renumber_documents(documents : ArrayView[PdfDocument]) -> Array[PdfDocument] raise PdfError

    Return copies of documents renumbered into one non-overlapping sequence.

    The first document starts at object number 1; each following document starts after the previous document's object count. This is primarily used before merging documents that may have colliding object numbers.

    pdf_renumber_pages

    fn pdf_renumber_pages(document : PdfDocument, pages : ArrayView[PdfPage]) -> Array[PdfPage] raise PdfError

    Compatibility wrapper for PdfDocument::renumber_pages.

    pdf_renumber_parent_trees

    fn pdf_renumber_parent_trees(documents : ArrayView[PdfDocument]) -> Unit raise PdfError

    Renumber structure parent-tree keys across documents before merging.

    The documents are mutated in place. Parent-tree keys are reassigned to a single increasing sequence, and structure parent references inside each document are updated to match the rebuilt number trees.

    pdf_reverse_table_of_encoding

    fn pdf_reverse_table_of_encoding(encoding : PdfEncoding) -> Array[(PdfName, Int)]

    Compatibility wrapper for PdfEncoding::reverse_table.

    pdf_revisions_from_bytes

    fn pdf_revisions_from_bytes(data : Bytes) -> Int raise PdfError

    Count document revisions from owned PDF bytes.

    pdf_revisions_from_view

    fn pdf_revisions_from_view(data : BytesView) -> Int raise PdfError

    Count document revisions by following xref /Prev links.

    Revision 1 is the newest revision referenced by startxref; larger numbers walk backward through older revisions. Linearized hint-table revisions are excluded from the returned count.

    pdf_run_length_decode

    fn pdf_run_length_decode(data : Bytes) -> Bytes

    Owned-byte wrapper for pdf_run_length_decode_view.

    pdf_run_length_decode_view

    fn pdf_run_length_decode_view(data : BytesView) -> Bytes

    Decode PDF RunLengthDecode data.

    Decoding stops at the 128 end marker or end of input. Truncated trailing runs are decoded as far as bytes are available, matching the tolerant reader behavior used by CamlPDF.

    pdf_run_length_encode

    fn pdf_run_length_encode(data : Bytes) -> Bytes

    Owned-byte wrapper for pdf_run_length_encode_view.

    pdf_run_length_encode_view

    fn pdf_run_length_encode_view(data : BytesView) -> Bytes

    Encode bytes with PDF RunLengthDecode syntax.

    Literal runs and repeated-byte runs are emitted with the standard 128 end-of-data marker.

    pdf_secure_random_bytes

    fn pdf_secure_random_bytes(length : Int) -> Bytes raise PdfError

    Return cryptographically secure random bytes on the native target.

    The native stub uses the platform RNG (BCryptGenRandom on Windows and /dev/urandom on Unix-like systems). Negative lengths raise InvalidReadLength; RNG failures raise RandomBytesUnavailable.

    pdf_sha256_digest

    fn pdf_sha256_digest(data : BytesView) -> Bytes

    Return the SHA-256 digest of data.

    pdf_sha384_digest

    fn pdf_sha384_digest(data : BytesView) -> Bytes

    Return the SHA-384 digest of data.

    pdf_sha512_digest

    fn pdf_sha512_digest(data : BytesView) -> Bytes

    Return the SHA-512 digest of data.

    pdf_shortest_unused_prefix

    fn pdf_shortest_unused_prefix(document : PdfDocument) -> String

    Compatibility wrapper for PdfDocument::shortest_unused_prefix.

    pdf_simplify_utf16be

    fn pdf_simplify_utf16be(bytes : BytesView) -> Bytes raise PdfError

    Re-encode a UTF-16BE PDF string using PDFDocEncoding when possible.

    Non-Unicode input is returned as an owned copy. Malformed UTF-16BE raises InvalidUTF16BE.

    pdf_standard14_afm_data

    fn pdf_standard14_afm_data(font : PdfStandardFont) -> PdfAfmData

    Returns the Adobe Font Metrics data for a standard font.

    pdf_standard14_baseline_adjustment

    fn pdf_standard14_baseline_adjustment(font : PdfStandardFont) -> Int

    Returns the baseline adjustment used by CamlPDF for this standard font.

    pdf_standard14_flags_of_standard_font

    fn pdf_standard14_flags_of_standard_font(font : PdfStandardFont) -> Int

    Returns the PDF font descriptor flags for this standard font.

    pdf_standard14_stemv_of_standard_font

    fn pdf_standard14_stemv_of_standard_font(font : PdfStandardFont) -> Int

    Returns the /StemV value used when writing this standard font.

    pdf_standard14_text_width

    fn pdf_standard14_text_width(font : PdfStandardFont, encoding : PdfEncoding, text : BytesView, kern? : Bool) -> Int

    Computes the width of byte-encoded text in standard-font glyph units.

    When kern is true, AFM kerning pairs are included between adjacent character codes.

    pdf_standard14_textwidth

    fn pdf_standard14_textwidth(kern : Bool, encoding : PdfEncoding, font : PdfStandardFont, text : BytesView) -> Int

    CamlPDF-shaped wrapper for standard-14 text width calculation.

    pdf_standard_font_of_name

    fn pdf_standard_font_of_name(name : String) -> PdfStandardFont?

    Recognize a standard 14 font from an ASCII PDF font name.

    name is expected to include the leading slash, for example "/Helvetica". Common Microsoft aliases such as /Arial and /TimesNewRoman are accepted for CamlPDF compatibility.

    pdf_standard_font_of_pdf_name

    fn pdf_standard_font_of_pdf_name(name : PdfName) -> PdfStandardFont?

    Recognize a standard 14 font from a byte-oriented PDF name.

    This is the allocation-light variant used while parsing font dictionaries. It accepts the canonical PDF names and the same common aliases as pdf_standard_font_of_name.

    pdf_stream

    fn pdf_stream(dictionary : PdfObject, data : PdfStreamData) -> PdfObject

    Construct a PDF stream object from a dictionary object and stream data.

    The dictionary is stored as supplied. It is normally a PdfDictionary, but malformed inputs can carry other objects and will be reported by helpers that require dictionary metadata.

    pdf_string_of_bookmark

    fn pdf_string_of_bookmark(bookmark : PdfBookmark) -> Bytes raise PdfError

    Format a bookmark as a diagnostic byte string.

    The output includes level, title bytes, destination object, and open state; it is intended for debugging rather than PDF serialization.

    pdf_string_of_calculator

    fn pdf_string_of_calculator(ops : ArrayView[PdfCalculatorOp]) -> String

    Format calculator operations as a brace-delimited diagnostic program.

    pdf_string_of_colour_space

    fn pdf_string_of_colour_space(space : PdfColourSpace) -> String

    Compatibility wrapper for PdfColourSpace::debug_name.

    pdf_string_of_content_op

    fn pdf_string_of_content_op(op : PdfContentOp) -> Bytes raise PdfError

    Compatibility wrapper for pdf_content_bytes_of_op.

    The name follows CamlPDF, where strings were byte sequences; this function returns PdfBytes.

    pdf_string_of_content_ops

    fn pdf_string_of_content_ops(ops : ArrayView[PdfContentOp]) -> Bytes raise PdfError

    Compatibility wrapper for pdf_content_bytes_of_ops.

    The name follows CamlPDF, where strings were byte sequences; this function returns PdfBytes.

    pdf_string_of_date

    fn pdf_string_of_date(date : PdfDate) -> String raise PdfError

    Formats a PDF date as an ASCII string in PDF date syntax.

    Raises PdfError::BadDate if any field is outside the representable PDF date ranges.

    pdf_string_of_font

    fn pdf_string_of_font(font : PdfFont) -> String

    Compatibility wrapper for PdfFont::debug_name.

    pdf_string_of_function

    fn pdf_string_of_function(function : PdfFunction) -> String

    Compatibility wrapper for PdfFunction::debug_string.

    pdf_string_of_int_array

    fn pdf_string_of_int_array(values : ArrayView[Int]) -> Bytes raise PdfError

    Compatibility alias for converting one integer byte array to PDF bytes.

    pdf_string_of_int_arrays

    fn pdf_string_of_int_arrays(values : ArrayView[ArrayView[Int]]) -> Bytes raise PdfError

    Compatibility alias for pdf_bytes_of_int_arrays.

    CamlPDF models many byte strings as integer lists; this helper preserves that shape for callers ported from OCaml.

    pdf_string_of_lexeme

    fn pdf_string_of_lexeme(lexeme : PdfLexeme) -> String

    Return CamlPDF-style debug text for a single lexeme.

    Only numbers, strings, names, and null get value-specific rendering; other token kinds are rendered as GenLexNone.

    pdf_string_of_lexemes

    fn pdf_string_of_lexemes(lexemes : ArrayView[PdfLexeme]) -> String

    Return CamlPDF-style debug text for a sequence of lexemes.

    Each lexeme is placed on its own line with a leading space.

    pdf_string_of_page_label

    fn pdf_string_of_page_label(label : PdfPageLabel) -> Bytes

    Format a page-label range as a diagnostic byte string.

    pdf_string_of_pdf

    fn pdf_string_of_pdf(object : PdfObject) -> Bytes raise PdfError

    Compatibility alias for pdf_write_object.

    pdf_string_of_pdf_including_data

    fn pdf_string_of_pdf_including_data(object : PdfObject) -> Bytes raise PdfError

    Compatibility alias for pdf_write_object.

    Stream data is included because PdfStreamObject serialization writes the stream dictionary, stream marker, bytes, and endstream marker.

    pdf_string_of_standard_font

    fn pdf_string_of_standard_font(font : PdfStandardFont) -> String

    Compatibility wrapper for PdfStandardFont::name.

    pdf_table_of_encoding

    fn pdf_table_of_encoding(encoding : PdfEncoding) -> Array[(Int, PdfName)]

    Compatibility wrapper for PdfEncoding::table.

    pdf_target_of_pagenumber

    fn pdf_target_of_pagenumber(document : PdfDocument, page_number : Int) -> PdfDestination raise PdfError

    Compatibility wrapper for PdfDocument::target_of_page_number.

    pdf_text_extractor_of_font

    fn pdf_text_extractor_of_font(document : PdfDocument, font : PdfObject) -> PdfTextExtractor raise PdfError

    Compatibility wrapper for PdfDocument::text_extractor_of_font.

    pdf_text_extractor_of_font_real

    fn pdf_text_extractor_of_font_real(font : PdfFont) -> PdfTextExtractor

    Compatibility wrapper for PdfFont::text_extractor.

    pdf_transform_annotations

    fn pdf_transform_annotations(document : PdfDocument, matrix : TransformMatrix, rest : PdfObject) -> Unit raise PdfError

    Compatibility wrapper for PdfDocument::transform_annotations.

    pdf_transform_bookmark

    fn pdf_transform_bookmark(document : PdfDocument, matrix : TransformMatrix, bookmark : PdfBookmark) -> PdfBookmark raise PdfError

    Compatibility wrapper for PdfDocument::transform_bookmark.

    pdf_transform_destination

    fn pdf_transform_destination(document : PdfDocument, matrix : TransformMatrix, destination : PdfDestination) -> PdfDestination raise PdfError

    Applies a page transform matrix to destination coordinates.

    This is the standalone form of PdfDocument::transform_destination.

    pdf_trim_structure_tree

    fn pdf_trim_structure_tree(document : PdfDocument, page_numbers : ArrayView[Int]) -> Unit raise PdfError

    Compatibility wrapper for PdfDocument::trim_structure_tree.

    pdf_user_password_from_owner_password

    fn pdf_user_password_from_owner_password(revision : Int, owner_password : BytesView, owner_entry : BytesView, key_length_bits : Int) -> Bytes raise PdfError

    Recover the padded user-password bytes from a revision 2-4 owner password.

    The returned bytes are the padded/truncated internal password form, not a decoded MoonBit string.

    pdf_utf16be_of_codepoints

    fn pdf_utf16be_of_codepoints(codepoints : ArrayView[Int]) -> Bytes raise PdfError

    Encode Unicode scalar values as a PDF UTF-16BE string with BOM.

    Invalid scalar values, including surrogate codepoints, raise InvalidUnicodeCodepoint.

    pdf_utf8_of_codepoints

    fn pdf_utf8_of_codepoints(codepoints : ArrayView[Int]) -> Bytes raise PdfError

    Encode Unicode scalar values as UTF-8 bytes.

    Invalid scalar values, including surrogate codepoints, raise InvalidUnicodeCodepoint.

    pdf_utf8_of_pdfdocstring

    fn pdf_utf8_of_pdfdocstring(bytes : BytesView) -> Bytes raise PdfError

    Convert a PDF string byte sequence to UTF-8 bytes.

    pdf_what_encryption

    fn pdf_what_encryption(document : PdfDocument) -> PdfEncryptionMethod? raise PdfError

    Compatibility wrapper for PdfDocument::what_encryption.

    pdf_write_colour_space

    fn pdf_write_colour_space(document : PdfDocument, space : PdfColourSpace) -> PdfObject

    Compatibility wrapper for PdfDocument::write_colour_space.

    pdf_write_document

    fn pdf_write_document(document : PdfDocument) -> Bytes raise PdfError

    Serialize a complete document with a classic xref table.

    pdf_write_document_incremental_update

    fn pdf_write_document_incremental_update(original : Bytes, document : PdfDocument) -> Bytes raise PdfError

    Append a classic incremental update to original PDF bytes.

    Only objects marked as changed in document are written. The previous startxref position is read from original and emitted as /Prev.

    pdf_write_document_incremental_update_with_compressed_xref_stream

    fn pdf_write_document_incremental_update_with_compressed_xref_stream(original : Bytes, document : PdfDocument) -> Bytes raise PdfError

    Append an incremental update using a Flate-compressed xref stream.

    pdf_write_document_incremental_update_with_generated_id

    fn pdf_write_document_incremental_update_with_generated_id(original : Bytes, document : PdfDocument, path : String, mode? : PdfWriteMode) -> Bytes raise PdfError

    Append an incremental update after generating a current trailer ID.

    The generated ID is based on path and current document state and is applied to a copy of the document before writing.

    pdf_write_document_incremental_update_with_mode

    fn pdf_write_document_incremental_update_with_mode(original : Bytes, document : PdfDocument, mode : PdfWriteMode) -> Bytes raise PdfError

    Append an incremental update using the selected xref representation.

    pdf_write_document_incremental_update_with_xref_stream

    fn pdf_write_document_incremental_update_with_xref_stream(original : Bytes, document : PdfDocument) -> Bytes raise PdfError

    Append an incremental update using an uncompressed xref stream.

    pdf_write_document_options

    fn pdf_write_document_options(document : PdfDocument, encryption? : PdfWriteEncryption?, update_from? : Bytes?, make_id? : Bool, id_path? : String, mode? : PdfWriteMode, file_id? : BytesView, aes_iv_provider? : (Int, Int, Int) -> Bytes raise PdfError?, aesv3_random_provider? : (PdfAesV3RandomField, Int) -> Bytes raise PdfError?) -> Bytes raise PdfError

    One-call writer with optional encryption, IDs, incremental update, and mode.

    The input document is copied before IDs or encryption are applied. update_from selects incremental output. make_id controls generated trailer IDs for unencrypted writes; encrypted writes always use the provided file_id or generate one through the encryption helper. AES modes require the corresponding IV and random providers.

    pdf_write_document_with_compressed_xref_stream

    fn pdf_write_document_with_compressed_xref_stream(document : PdfDocument) -> Bytes raise PdfError

    Serialize a complete document with a Flate-compressed xref stream.

    pdf_write_document_with_generated_id

    fn pdf_write_document_with_generated_id(document : PdfDocument, path : String, mode? : PdfWriteMode) -> Bytes raise PdfError

    Serialize a complete document after generating a current trailer ID.

    The source document is copied before its ID is generated.

    pdf_write_document_with_mode

    fn pdf_write_document_with_mode(document : PdfDocument, mode : PdfWriteMode) -> Bytes raise PdfError

    Serialize a complete document using the selected xref representation.

    pdf_write_document_with_xref_stream

    fn pdf_write_document_with_xref_stream(document : PdfDocument) -> Bytes raise PdfError

    Serialize a complete document with an uncompressed xref stream.

    The output header is at least PDF 1.5, because xref streams require that version.

    pdf_write_encrypted_128bit_document

    fn pdf_write_encrypted_128bit_document(document : PdfDocument, user_password : BytesView, owner_password : BytesView, denied_permissions : ArrayView[PdfPermission], mode? : PdfWriteMode, file_id? : BytesView) -> Bytes raise PdfError

    Encrypt with 128-bit ARC4 revision 3 and serialize in the selected mode.

    pdf_write_encrypted_128bit_r4_document

    fn pdf_write_encrypted_128bit_r4_document(document : PdfDocument, user_password : BytesView, owner_password : BytesView, denied_permissions : ArrayView[PdfPermission], encrypt_metadata? : Bool, mode? : PdfWriteMode, file_id? : BytesView) -> Bytes raise PdfError

    Encrypt with revision-4 ARC4 crypt filters and serialize.

    encrypt_metadata=false follows the PDF revision-4 no-metadata behavior.

    pdf_write_encrypted_40bit_document

    fn pdf_write_encrypted_40bit_document(document : PdfDocument, user_password : BytesView, owner_password : BytesView, denied_permissions : ArrayView[PdfPermission], mode? : PdfWriteMode, file_id? : BytesView) -> Bytes raise PdfError

    Encrypt with 40-bit ARC4 and serialize in the selected write mode.

    pdf_write_encrypted_aesv2_document

    fn pdf_write_encrypted_aesv2_document(document : PdfDocument, user_password : BytesView, owner_password : BytesView, denied_permissions : ArrayView[PdfPermission], encrypt_metadata? : Bool, mode? : PdfWriteMode, file_id? : BytesView) -> Bytes raise PdfError

    Encrypt and serialize a document with AESV2 using native randomness.

    The encrypted document is written with the requested write mode. Supplying a file_id controls the trailer ID used for key derivation; IVs remain random.

    pdf_write_encrypted_aesv2_document_with_iv_provider

    fn pdf_write_encrypted_aesv2_document_with_iv_provider(document : PdfDocument, user_password : BytesView, owner_password : BytesView, denied_permissions : ArrayView[PdfPermission], iv_provider : (Int, Int, Int) -> Bytes raise PdfError, encrypt_metadata? : Bool, mode? : PdfWriteMode, file_id? : BytesView) -> Bytes raise PdfError

    Encrypt with AESV2 and serialize.

    iv_provider supplies IVs by object number, generation, and per-object index. This allows deterministic fixtures or secure caller-provided IVs.

    pdf_write_encrypted_aesv3_document

    fn pdf_write_encrypted_aesv3_document(document : PdfDocument, user_password : BytesView, owner_password : BytesView, denied_permissions : ArrayView[PdfPermission], iso? : Bool, encrypt_metadata? : Bool, mode? : PdfWriteMode, file_id? : BytesView) -> Bytes raise PdfError

    Encrypt and serialize a document with AESV3/AES-256 using native randomness.

    Set iso=true for the ISO/PDF 2.0 hash variant. The requested write mode is applied after encryption.

    pdf_write_encrypted_aesv3_document_with_providers

    fn pdf_write_encrypted_aesv3_document_with_providers(document : PdfDocument, user_password : BytesView, owner_password : BytesView, denied_permissions : ArrayView[PdfPermission], random_provider : (PdfAesV3RandomField, Int) -> Bytes raise PdfError, iv_provider : (Int, Int, Int) -> Bytes raise PdfError, iso? : Bool, encrypt_metadata? : Bool, mode? : PdfWriteMode, file_id? : BytesView) -> Bytes raise PdfError

    Encrypt with AESV3/AES-256 and serialize.

    random_provider supplies file keys, salts, and permissions padding; iv_provider supplies object-data IVs. iso=true selects the ISO/PDF 2.0 AESV3 hash variant.

    pdf_write_encrypted_aesv3_iso_document

    fn pdf_write_encrypted_aesv3_iso_document(document : PdfDocument, user_password : BytesView, owner_password : BytesView, denied_permissions : ArrayView[PdfPermission], encrypt_metadata? : Bool, mode? : PdfWriteMode, file_id? : BytesView) -> Bytes raise PdfError

    Encrypt and serialize a document with the ISO AESV3/AES-256 variant.

    pdf_write_encrypted_aesv3_iso_document_with_providers

    fn pdf_write_encrypted_aesv3_iso_document_with_providers(document : PdfDocument, user_password : BytesView, owner_password : BytesView, denied_permissions : ArrayView[PdfPermission], random_provider : (PdfAesV3RandomField, Int) -> Bytes raise PdfError, iv_provider : (Int, Int, Int) -> Bytes raise PdfError, encrypt_metadata? : Bool, mode? : PdfWriteMode, file_id? : BytesView) -> Bytes raise PdfError

    Encrypt with the ISO AESV3/AES-256 variant and serialize.

    pdf_write_encryption

    fn pdf_write_encryption(encryption_method : PdfEncryptionMethod, user_password : BytesView, owner_password : BytesView, denied_permissions : ArrayView[PdfPermission]) -> PdfWriteEncryption

    Build owned encryption options for the writer options API.

    pdf_write_font

    fn pdf_write_font(document : PdfDocument, font : PdfFont, objnum? : Int?) -> Int raise PdfError

    Compatibility wrapper for PdfDocument::write_font.

    pdf_write_hex_string

    fn pdf_write_hex_string(bytes : BytesView) -> Bytes

    Serialize bytes as a lowercase hexadecimal PDF string.

    pdf_write_indirect_object

    fn pdf_write_indirect_object(object : PdfParsedIndirectObject) -> Bytes raise PdfError

    Serialize one indirect object including obj and endobj wrappers.

    pdf_write_literal_string

    fn pdf_write_literal_string(bytes : BytesView) -> Bytes

    Serialize bytes as a PDF literal string.

    Delimiters, backslashes, common controls, and non-printable bytes are escaped according to PDF literal-string syntax.

    pdf_write_name

    fn pdf_write_name(name : PdfName) -> Bytes

    Serialize a PDF name object with required delimiter and hex escaping.

    The returned bytes include the leading slash.

    pdf_write_object

    fn pdf_write_object(object : PdfObject) -> Bytes raise PdfError

    Serialize a direct PDF object.

    Stream lengths are refreshed from the current stream data while writing.

    pdf_write_ocg

    fn pdf_write_ocg(document : PdfDocument, optional_content : PdfOptionalContent) -> PdfDocument raise PdfError

    Compatibility wrapper for PdfDocument::write_optional_content_groups.

    pdf_write_page_labels

    fn pdf_write_page_labels(document : PdfDocument, labels : ArrayView[PdfPageLabel]) -> PdfDocument raise PdfError

    Compatibility wrapper for PdfDocument::write_page_labels.

    pdf_write_real

    fn pdf_write_real(value : Double) -> Bytes raise PdfError

    Format a PDF real number as bytes.

    Scientific notation is expanded to PDF-compatible decimal form where possible. Non-finite or unparsable numeric text raises PdfError.

    point2

    fn point2(x : Double, y : Double) -> Point2

    Creates a two-dimensional point.

    stream_to_get

    fn stream_to_get(input : ByteCursor, position : Int, length : Int) -> ToGet

    Construct a deferred stream-data descriptor without encryption.

    The returned value references input and reads length bytes starting at position when materialized.

    transform_append

    fn transform_append(after : ArrayView[TransformOp], before : ArrayView[TransformOp]) -> Array[TransformOp]

    Concatenates two transform operation lists.

    The after operations are placed before the before operations to preserve the same ordering used by CamlPDF transform lists.

    transform_apply

    fn transform_apply(ops : ArrayView[TransformOp], point : Point2) -> Point2

    Compatibility alias for applying a transform operation list to a point.

    transform_apply_matrix

    fn transform_apply_matrix(matrix : TransformMatrix, point : Point2) -> Point2

    Applies a matrix to a point.

    transform_apply_ops

    fn transform_apply_ops(ops : ArrayView[TransformOp], point : Point2) -> Point2

    Applies a transform operation list to a point.

    transform_compose_op

    fn transform_compose_op(op : TransformOp, ops : ArrayView[TransformOp]) -> Array[TransformOp]

    Adds one operation to the front of an operation list, merging with the first operation when the two adjacent operations are compatible.

    Compatible adjacent translations, scales about the same origin, rotations about the same origin, and shears about the same origin are combined to keep operation lists compact.

    transform_decompose

    fn transform_decompose(matrix : TransformMatrix) -> TransformDecomposition

    Decomposes a matrix into scale, aspect, rotation, shear, and translation.

    transform_identity

    fn transform_identity() -> Array[TransformOp]

    Returns an empty transform operation list, representing identity.

    transform_identity_matrix

    let transform_identity_matrix : TransformMatrix

    The identity affine transform matrix.

    transform_matrix_compose

    fn transform_matrix_compose(after : TransformMatrix, before : TransformMatrix) -> TransformMatrix

    Composes two matrices so before is applied first and after second.

    transform_matrix_invert

    fn transform_matrix_invert(matrix : TransformMatrix) -> TransformMatrix raise PdfError

    Returns the inverse of a matrix.

    Raises PdfError::MatrixNotInvertable when the matrix cannot be inverted.

    transform_matrix_of_op

    fn transform_matrix_of_op(op : TransformOp) -> TransformMatrix

    Lowers one high-level transform operation to a matrix.

    transform_matrix_of_ops

    fn transform_matrix_of_ops(ops : ArrayView[TransformOp]) -> TransformMatrix

    Lowers an operation list to one composed matrix.

    transform_matrix_of_transform

    fn transform_matrix_of_transform(ops : ArrayView[TransformOp]) -> TransformMatrix

    Compatibility alias for lowering a transform operation list to a matrix.

    transform_recompose

    fn transform_recompose(parts : TransformDecomposition) -> TransformMatrix

    Recomposes a matrix from decomposed transform components.

    transform_recompose_components

    fn transform_recompose_components(scale : Double, aspect : Double, rotation : Double, shear : Double, translate_x : Double, translate_y : Double) -> TransformMatrix

    Recomposes a matrix from individual decomposition fields.

    transform_rotate

    fn transform_rotate(origin : Point2, angle : Double) -> TransformMatrix

    Creates a rotation matrix around origin.

    angle is measured in radians.

    transform_scale

    fn transform_scale(origin : Point2, sx : Double, sy : Double) -> TransformMatrix

    Creates a scale matrix around origin.

    transform_shear_x

    fn transform_shear_x(origin : Point2, factor : Double) -> TransformMatrix

    Creates an X-shear matrix around origin.

    transform_shear_y

    fn transform_shear_y(origin : Point2, factor : Double) -> TransformMatrix

    Creates a Y-shear matrix around origin.

    transform_string_of_matrix

    fn transform_string_of_matrix(matrix : TransformMatrix) -> String

    Formats a matrix as its six comma-separated operands.

    transform_string_of_op

    fn transform_string_of_op(op : TransformOp) -> String

    Formats one transform operation in CamlPDF-compatible debug text.

    transform_string_of_ops

    fn transform_string_of_ops(ops : ArrayView[TransformOp]) -> String

    Formats a transform operation list in display order.

    CamlPDF prints the most recently composed operation first, so this walks the input list in reverse.

    transform_string_of_transform

    fn transform_string_of_transform(ops : ArrayView[TransformOp]) -> String

    Compatibility alias for formatting a transform operation list.

    transform_translate

    fn transform_translate(tx : Double, ty : Double) -> TransformMatrix

    Creates a translation matrix.

    unit_centimetres

    fn unit_centimetres(value : Double, unit : PdfUnit) -> Double

    Converts a value from unit to centimetres.

    The PdfPoint path preserves CamlPDF's historical conversion constant for compatibility with existing output.

    unit_inches

    fn unit_inches(value : Double, unit : PdfUnit) -> Double

    Converts a value from unit to inches.

    unit_millimetres

    fn unit_millimetres(value : Double, unit : PdfUnit) -> Double

    Converts a value from unit to millimetres.

    unit_points

    fn unit_points(value : Double, unit : PdfUnit) -> Double

    Converts a value from unit to PDF points.