Kreuzberg.Page (kreuzberg v4.0.8)

View Source

Structure representing a single page extracted from a multi-page document.

Contains page-specific content, dimensions, and metadata when page-level extraction is enabled.

Fields

  • :number - Page number (1-indexed)
  • :content - Text content extracted from this page
  • :width - Page width in inches or centimeters
  • :height - Page height in inches or centimeters
  • :index - Zero-indexed page index (alternative to number)

Examples

iex> page = %Kreuzberg.Page{
...>   number: 1,
...>   content: "Page 1 content here",
...>   width: 8.5,
...>   height: 11.0
...> }
iex> page.number
1
iex> page.content
"Page 1 content here"

Summary

Functions

Creates a Page struct from a map.

Creates a new Page struct with required number and content.

Returns the page size as a {width, height} tuple.

Converts a Page struct to a map.

Types

t()

@type t() :: %Kreuzberg.Page{
  content: String.t() | nil,
  height: float() | nil,
  index: integer() | nil,
  number: integer() | nil,
  width: float() | nil
}

Functions

from_map(data)

@spec from_map(map()) :: t()

Creates a Page struct from a map.

Converts a plain map (typically from NIF/Rust) into a proper struct.

Parameters

  • data - A map containing page fields

Returns

A Page struct with matching fields populated.

Examples

iex> page_map = %{
...>   "number" => 1,
...>   "content" => "Page text",
...>   "width" => 8.5
...> }
iex> Kreuzberg.Page.from_map(page_map)
%Kreuzberg.Page{
  number: 1,
  content: "Page text",
  width: 8.5
}

new(number, content, opts \\ [])

@spec new(integer(), String.t(), keyword()) :: t()

Creates a new Page struct with required number and content.

Parameters

  • number - The page number (1-indexed)
  • content - The text content of the page
  • opts - Optional keyword list with:
    • :width - Page width
    • :height - Page height
    • :index - Zero-indexed page index

Returns

A Page struct with the provided number, content, and options.

Examples

iex> Kreuzberg.Page.new(1, "Page content")
%Kreuzberg.Page{number: 1, content: "Page content"}

iex> Kreuzberg.Page.new(
...>   2,
...>   "More content",
...>   width: 8.5,
...>   height: 11.0
...> )
%Kreuzberg.Page{
  number: 2,
  content: "More content",
  width: 8.5,
  height: 11.0
}

size(arg1)

@spec size(t()) :: {float(), float()} | nil

Returns the page size as a {width, height} tuple.

Useful for layout calculations and image sizing.

Parameters

  • page - A Page struct

Returns

A tuple {width, height} or nil if dimensions not available.

Examples

iex> page = %Kreuzberg.Page{width: 8.5, height: 11.0}
iex> Kreuzberg.Page.size(page)
{8.5, 11.0}

iex> page = %Kreuzberg.Page{number: 1}
iex> Kreuzberg.Page.size(page)
nil

to_map(page)

@spec to_map(t()) :: map()

Converts a Page struct to a map.

Useful for serialization and passing to external systems.

Parameters

  • page - A Page struct

Returns

A map with string keys representing all fields.

Examples

iex> page = %Kreuzberg.Page{number: 1, content: "text", width: 8.5}
iex> Kreuzberg.Page.to_map(page)
%{
  "number" => 1,
  "content" => "text",
  "width" => 8.5,
  ...
}