Read-only representation of a PDF document.
Summary
Types
Options accepted by the chars and chars! functions.
A span-extraction tuning preset, named after pdf_oxide's own
ExtractionProfile constants. A profile changes the TJ-offset and
word-margin thresholds used to turn glyphs into spans, before any word
clustering happens.
Options accepted by the to_html and to_html! functions.
Options accepted by the to_markdown and to_markdown! functions.
Options accepted by open/2, open!/2, from_binary/2, and from_binary!/2.
How a :region (or :exclude_regions) decides whether an object is inside
it.
Options tuning how glyph runs are merged into spans, accepted as
:span_merging. pdf_oxide's own bindings expose none of this.
Options accepted by the spans and spans! functions.
A handle on an open PDF document.
Options tuning pdf_oxide's spatial table detector. Accepted directly by
the tables functions, and as the :table_detection option of the text
functions.
Options accepted by the tables and tables! functions: every
table_detection_opts/0 key, plus
Options accepted by the text_lines and text_lines! functions.
Options accepted by the text and text! functions.
Options accepted by the words and words! functions.
Functions
Reads the annotations of the whole document.
Reads the annotations of the page at the given zero-based index.
Reads the annotations of the whole document, raising an error if it fails.
Reads the annotations of the page at the given zero-based index, raising an error if it fails.
Authenticates against the document's encryption with the given password.
Same as authenticate/2 but raises on error.
Extracts characters, each with its bounding box, font metadata and
typographic placement as a PdfElixide.Document.Char struct.
Extracts the characters of the page at the given zero-based index.
Extracts characters, raising an error if it fails.
Extracts the characters of the page at the given zero-based index, raising an error if it fails.
Releases the document's native memory immediately.
Returns whether the document has been released with close/1.
Returns whether the PDF document is encrypted.
Extracts the fonts of the whole document.
Extracts the fonts referenced by the page at the given zero-based index.
Extracts the fonts of the whole document, raising an error if it fails.
Extracts the fonts referenced by the page at the given zero-based index, raising an error if it fails.
Opens a PDF document from the given binary data.
Opens a PDF document from the given binary data, raising an error if it fails.
Returns whether the PDF document is a Tagged PDF with a structure tree, reporting a structure tree that cannot be read.
Returns whether the PDF document is a Tagged PDF with a structure tree.
Returns whether the PDF document contains XFA (XML Forms Architecture) form data, reporting a catalog that cannot be read.
Returns whether the PDF document contains XFA (XML Forms Architecture) form data.
Extracts the raster images of the whole document.
Extracts the raster images of the page at the given zero-based index.
Extracts the raster images of the whole document, raising an error if it fails.
Extracts the raster images of the page at the given zero-based index, raising an error if it fails.
Reads the document's Info dictionary metadata (title, author, dates, etc.).
Reads the document's Info dictionary metadata, raising an error if it fails.
Opens a PDF document from the specified file path.
Opens a PDF document from the specified file path, raising an error if it fails.
Reads the document outline — its bookmarks / table of contents.
Reads the document outline, raising an error if it fails.
Returns a lazy handle for the page at the given zero-based index.
Same as page/2 but raises an error if it fails.
Returns the number of pages in the given PDF document.
Returns the number of pages in the given PDF document, raising an error if it fails.
Returns the document's logical page labels — one per page, in page order.
Returns the document's logical page labels, raising an error if it fails.
Returns a lazy handle for every page in the document.
Extracts the vector paths of the whole document.
Extracts the vector paths of the page at the given zero-based index.
Extracts the vector paths of the whole document, raising an error if it fails.
Extracts the vector paths of the page at the given zero-based index, raising an error if it fails.
Reads the document's /P permission flags.
Reads the document's permission flags, raising an error if it fails.
Returns the file path from which the document was loaded, or nil if it was loaded from binary data.
Extracts spans — runs of text sharing one text state — as
PdfElixide.Document.Span structs.
Extracts the spans of the page at the given zero-based index.
Extracts spans, raising an error if it fails.
Extracts the spans of the page at the given zero-based index, raising an error if it fails.
Detects tables, as PdfElixide.Document.Table structs.
Detects the tables of the page at the given zero-based index.
Detects tables, raising an error if it fails.
Detects the tables of the page at the given zero-based index, raising an error if it fails.
Extracts text content.
Extracts the text content of the page at the given zero-based index.
Extracts text content, raising an error if it fails.
Extracts the text content of the page at the given zero-based index, raising an error if it fails.
Extracts text lines, each with its bounding box and constituent words as a
PdfElixide.Document.TextLine struct.
Extracts the text lines of the page at the given zero-based index.
Extracts text lines, raising an error if it fails.
Extracts the text lines of the page at the given zero-based index, raising an error if it fails.
Converts the document to HTML.
Converts the page at the given zero-based index to HTML.
Converts the document to HTML, raising an error if it fails.
Converts the page at the given zero-based index to HTML, raising an error if it fails.
Converts the document to Markdown.
Converts the page at the given zero-based index to Markdown.
Converts the document to Markdown, raising an error if it fails.
Converts the page at the given zero-based index to Markdown, raising an error if it fails.
Returns the PDF specification version of the given document as a {major, minor} tuple.
Extracts words, each with its bounding box and font metadata as a
PdfElixide.Document.Word struct.
Extracts the words of the page at the given zero-based index.
Extracts words, raising an error if it fails.
Extracts the words of the page at the given zero-based index, raising an error if it fails.
Reads the document's XMP (Extensible Metadata Platform) metadata.
Reads the document's XMP metadata, raising an error if it fails.
Types
@type chars_opts() :: [ region: PdfElixide.Geometry.Rect.t() | nil, region_mode: region_mode(), exclude_layers: [String.t()], exclude_inks: [String.t()] ]
Options accepted by the chars and chars! functions.
:region— aPdfElixide.Geometry.Rectkeeping only the characters inside it. Defaults tonil.:region_mode— how:regionmatches; seeregion_mode/0. Defaults to:intersects.:exclude_layers— names of optional-content (OCG) layers to suppress. Defaults to[].:exclude_inks— names of Separation/DeviceN inks to suppress. Defaults to[].
@type extraction_profile() ::
:conservative
| :tj_heavy
| :aggressive
| :balanced
| :academic
| :policy
| :form
| :government
| :scanned_ocr
| :adaptive
A span-extraction tuning preset, named after pdf_oxide's own
ExtractionProfile constants. A profile changes the TJ-offset and
word-margin thresholds used to turn glyphs into spans, before any word
clustering happens.
@type html_opts() :: [ preserve_layout: boolean(), detect_headings: boolean(), extract_tables: boolean(), include_images: boolean(), embed_images: boolean(), image_output_dir: Path.t() | nil, include_form_fields: boolean(), max_image_pixels: non_neg_integer() | nil, reading_order: :structure_tree | :column_aware | :top_to_bottom ]
Options accepted by the to_html and to_html! functions.
Only the options that upstream actually reads on its HTML path are
exposed, so every one of them changes the output. In particular
:bold_markers, :annotate_skipped_pages,
:strip_running_headers_footers and :expand_ligatures — all valid for
to_markdown/2 — are not part of this list, because pdf_oxide never
consults them while converting to HTML. Like any other undeclared key,
passing one is silently ignored rather than an error. A declared key
given a value of the wrong type is reported as
{:error, %PdfElixide.Error{reason: :other}}, with a message naming the
offending field, rather than raising.
:preserve_layout— emit one absolutely positioned<div>per text span, carrying that span's coordinates and font size in inline CSS (ptunits), in place of the semantic flow of<p>/<h1>/<ul>elements. Colour is written only for non-black text. Note that this mode emits only those positioned spans: headings, lists and tables are not produced, so:detect_headingsand:extract_tableshave no effect under it. Defaults tofalse.The result is not directly renderable, and reproducing the page needs two corrections from you. Upstream writes the PDF's own user-space coordinates verbatim, so the
topvalue is measured from the bottom of the page while CSStopmeasures from the top: flip it yourself withtop = height - y, taking the page height fromPdfElixide.Document.Page.height/1. And the per-page wrapperto_html/1emits carries no styling, so it is not a positioned containing block and gives the spans no page-sized box to resolve against — addposition: relativeand an explicit size to each wrapper, or every page will pile up in the same place.:detect_headings— cluster font sizes to emit<h1>–<h6>elements instead of plain<p>paragraphs. Defaults totrue.:extract_tables— detect tables and render them as<table>/<thead>/<tbody>markup, withcolspanandrowspanon the cells. Defaults totrue.:include_images— emit<img>elements. Defaults tofalse, since embedded images can add hundreds of kilobytes per page. Images are appended to the end of the page in a<div class="page-images">rather than placed at their position in the content.:embed_images— whentrue, images are inlined as base64 data URIs and:image_output_diris ignored. Whenfalse, they are written to:image_output_dirand referenced by path — and if that option isnil, no image is emitted at all. Only applies when:include_imagesistrue. Defaults totrue.:image_output_dir— directory to write extracted images to, used only when:include_imagesistrueand:embed_imagesisfalse. It is created if missing, and one that cannot be created is an:ioerror. The writes themselves are best-effort: upstream drops an image that fails to encode or write, so a successful call does not guarantee every image reached disk. Defaults tonil.Upstream interpolates the resulting path into the
srcattribute without HTML escaping, so a directory whose name contains"or&produces malformed markup. Never build this path from untrusted input: a crafted directory name can close the attribute and inject others.:include_form_fields— inline AcroForm field values at their positions on the page. Defaults totrue.:max_image_pixels— skip images whose width times height exceeds this count.nilmeanspdf_oxide's own 16 MP limit, not "no limit" — pass a large integer to lift it, or0to skip every image. Defaults tonil.:reading_order— how text blocks are ordered::structure_tree(follow a tagged PDF's structure tree, falling back to an XY-cut),:column_aware, or:top_to_bottom. Defaults to:structure_tree.
Defaults mirror pdf_oxide's ConversionOptions::default(), so calling
to_html/1 is equivalent to to_html/2 with no options.
@type markdown_opts() :: [ detect_headings: boolean(), extract_tables: boolean(), include_images: boolean(), embed_images: boolean(), image_output_dir: Path.t() | nil, include_form_fields: boolean(), strip_running_headers_footers: boolean(), expand_ligatures: boolean(), annotate_skipped_pages: boolean(), max_image_pixels: non_neg_integer() | nil, reading_order: :structure_tree | :column_aware | :top_to_bottom, bold_markers: :conservative | :aggressive ]
Options accepted by the to_markdown and to_markdown! functions.
:detect_headings— cluster font sizes to emit#headings instead of plain paragraphs. Defaults totrue.:extract_tables— detect tables and render them as Markdown tables. Defaults totrue.:include_images— emitimage syntax. Defaults tofalse, since embedded images can add hundreds of kilobytes per page.:embed_images— whentrue, images are inlined as base64 data URIs and:image_output_diris ignored. Whenfalse, they are written to:image_output_dirand referenced by path — and if that option isnil, no image is emitted at all. Only applies when:include_imagesistrue. Defaults totrue.:image_output_dir— directory to write extracted images to, used only when:include_imagesistrueand:embed_imagesisfalse. It is created if missing, and one that cannot be created is an:ioerror. The writes themselves are best-effort: upstream drops an image that fails to encode or write, so a successful call does not guarantee every image reached disk. Defaults tonil.:include_form_fields— inline AcroForm field values at their positions on the page. Defaults totrue.:strip_running_headers_footers— drop text lines that repeat in the top/bottom band of a majority of pages. Defaults tofalse.:expand_ligatures— expandU+FB00–U+FB06ligatures to their component letters (fitofi, and so on). Accepted for forward compatibility, but currently has no effect on Markdown output: upstream applies it only on its plain-text assembly path, which the Markdown converter does not use. Defaults tofalse.:annotate_skipped_pages— emit a block quote naming any page that is a scan with no usable text layer, rather than rendering it blank. Defaults totrue.:max_image_pixels— skip images whose width times height exceeds this count.nilmeanspdf_oxide's own 16 MP limit, not "no limit" — pass a large integer to lift it, or0to skip every image. Defaults tonil.:reading_order— how text blocks are ordered::structure_tree(follow a tagged PDF's structure tree, falling back to an XY-cut),:column_aware, or:top_to_bottom. Defaults to:structure_tree.:bold_markers—:conservativeapplies**only to content-bearing text;:aggressivealso wraps whitespace-only spans. Defaults to:conservative.
Defaults mirror pdf_oxide's ConversionOptions::default(), so calling
to_markdown/1 is equivalent to to_markdown/2 with no options.
@type open_opts() :: [{:password, String.t()}]
Options accepted by open/2, open!/2, from_binary/2, and from_binary!/2.
:password— password used to authenticate against an encrypted PDF. When the password is wrong, the call returns{:error, %PdfElixide.Error{reason: :wrong_password}}(or raises, for the bang variants). When omitted ornil, no authentication attempt is made beyondpdf_oxide's built-in empty-password try.
To check a password against an already-open document without treating a
wrong one as an error, use authenticate/2, which returns {:ok, false}
rather than a :wrong_password error.
@type region_mode() :: :intersects | :fully_contained | {:min_overlap, float()}
How a :region (or :exclude_regions) decides whether an object is inside
it.
:intersects— any overlap at all counts. The default, and whatpdf_oxideuses everywhere it does not take a mode.:fully_contained— the object's bounding box must lie entirely within the region.{:min_overlap, ratio}— at leastratioof the object's area must lie within the region.
:min_overlap details
ratio must be between 0.0 and 1.0; anything outside that range is
{:error, %PdfElixide.Error{reason: :other}}. The bound is checked here
rather than upstream, which validates it nowhere — no other pdf_oxide
binding can even select this mode, so an out-of-range value would otherwise
fail silently and wrongly (a negative one matches every object, and one
above 1.0 matches none).
Two behaviors worth knowing before choosing a value:
- The fraction is of the object's own area, not the region's. A large
element clipped by a small region scores low however much of the region
it covers, so
:min_overlapanswers "how much of this object is in the region?", never the reverse. {:min_overlap, 0.0}matches everything, including objects that do not touch the region at all — a non-overlapping object scores0.0, and the comparison is>=. Use:intersectsif you meant "any overlap".
@type span_merging_opts() :: [ preset: :default | :aggressive | :conservative | :adaptive | :legacy, space_threshold_em_ratio: float() | nil, conservative_threshold_pt: float() | nil, column_boundary_threshold_pt: float() | nil, severe_overlap_threshold_pt: float() | nil, use_adaptive_threshold: boolean() | nil, adaptive: keyword() | nil, detect_email_patterns: boolean() | nil, email_threshold_multiplier: float() | nil, detect_citation_markers: boolean() | nil, citation_font_size_ratio: float() | nil, merge_tm_tj_runs: boolean() | nil ]
Options tuning how glyph runs are merged into spans, accepted as
:span_merging. pdf_oxide's own bindings expose none of this.
:preset— the base configuration every other key overrides::default,:aggressive(merges across wider gaps),:conservative(splits more readily),:adaptive(derives thresholds from page gap statistics), or:legacy. Defaults to:default.:space_threshold_em_ratio— gap, as a fraction of font size, that becomes a space.:conservative_threshold_pt— floor gap in points below which no space is inserted.:column_boundary_threshold_pt— gap in points treated as a column break rather than a space.:severe_overlap_threshold_pt— negative gap indicating real glyph overlap.:use_adaptive_threshold— derive the space threshold from page gap statistics.:adaptive— a keyword list tuning that derivation::median_multiplier,:min_threshold_pt,:max_threshold_pt,:use_iqr,:min_samples. Only consulted when:use_adaptive_thresholdresolves totrue.:detect_email_patterns/:email_threshold_multiplier— keep addresses from being split at the@.:detect_citation_markers/:citation_font_size_ratio— treat small raised runs as citation markers.:merge_tm_tj_runs— whenfalse, every text-matrix operator starts a fresh span.
Every key except :preset defaults to nil, meaning "keep the preset's
value".
@type spans_opts() :: [ reading_order: :top_to_bottom | :column_aware | :structure, span_merging: span_merging_opts() | nil, region: PdfElixide.Geometry.Rect.t() | nil, region_mode: region_mode(), exclude_layers: [String.t()], exclude_inks: [String.t()] ]
Options accepted by the spans and spans! functions.
:reading_order— how spans are ordered::top_to_bottom(simple geometric sorting),:column_aware(XY-cut column detection), or:structure(follow a tagged PDF's structure tree). Defaults to:top_to_bottom. This ispdf_oxide's span-level reading order and names its values differently from the:reading_orderofmarkdown_opts/0, which is a separate upstream type.:span_merging— aspan_merging_opts/0keyword list, ornilfor upstream's default merging. Defaults tonil.:region— aPdfElixide.Geometry.Rectkeeping only the spans inside it. Defaults tonil.:region_mode— how:regionmatches; seeregion_mode/0. Defaults to:intersects.:exclude_layers— names of optional-content (OCG) layers to suppress. Defaults to[].:exclude_inks— names of Separation/DeviceN inks to suppress. Defaults to[].
:span_merging drops the other options
Upstream serves a merging configuration through a call that accepts
neither a reading order nor layer/ink filters. So when :span_merging is
set, :reading_order, :exclude_layers and :exclude_inks are ignored.
:region still applies — it is a post-filter, not an upstream argument.
@type t() :: %PdfElixide.Document{ page_count: non_neg_integer() | nil, ref: reference(), source_path: Path.t() | nil, version: {non_neg_integer(), non_neg_integer()} }
A handle on an open PDF document.
:version and :page_count arrive with the handle, from the same native call
that opens the document, and are served from the struct thereafter, since both
are immutable for a read-only document. A cached count cannot go stale: for an
encrypted document upstream either fails or returns the real /Count, and
authentication changes only whether the count is readable, never what it is.
:page_count is nil when the count could not be determined at open — an
encrypted document whose page tree needs a password, opened without one — in
which case page_count/1 asks the document instead.
@type table_detection_opts() :: [ preset: :default | :strict | :relaxed, enabled: boolean() | nil, horizontal_strategy: :lines | :text | :both | nil, vertical_strategy: :lines | :text | :both | nil, column_tolerance: float() | nil, row_tolerance: float() | nil, min_table_cells: non_neg_integer() | nil, min_table_columns: non_neg_integer() | nil, regular_row_ratio: float() | nil, max_table_columns: non_neg_integer() | nil, column_merge_threshold: float() | nil, v_split_gap: float() | nil, text_fallback: boolean() | nil ]
Options tuning pdf_oxide's spatial table detector. Accepted directly by
the tables functions, and as the :table_detection option of the text
functions.
:preset— the base configuration every other key overrides::default,:strict(demands ruling lines and regular rows) or:relaxed(tolerant, text-driven). Defaults to:default.:horizontal_strategy/:vertical_strategy— what evidence delimits cells on that axis::lines(ruling lines only),:text(glyph alignment only) or:both.:column_tolerance/:row_tolerance— coordinate slack in points when grouping cells into columns and rows.:min_table_cells/:min_table_columns— smallest grid accepted as a table.:max_table_columns— reject anything wider as a false positive.:regular_row_ratio— fraction of rows that must share the column count.:column_merge_threshold— slack for the post-clustering column merge pass.:v_split_gap— minimum gap between vertical-line groups that splits a cluster.:text_fallback— allow text-only detection when a page has no ruling lines. Ignored on thetextpath, where upstream forces it tofalse.:enabled— set tofalseto disable detection entirely.
Every key except :preset defaults to nil, meaning "keep the preset's
value". The Python bindings' table_settings dict reaches only five of
these.
@type tables_opts() :: [ {:region, PdfElixide.Geometry.Rect.t() | nil} | {atom(), term()} ]
Options accepted by the tables and tables! functions: every
table_detection_opts/0 key, plus
:region— aPdfElixide.Geometry.Rectkeeping only the tables overlapping it. Defaults tonil. There is no:region_mode: upstream filters tables by bounding-box intersection only.
Note that :region here keeps the detection options you passed, whereas
pdf_oxide's own region call silently substitutes its :relaxed preset.
Pass preset: :relaxed to ask for that explicitly.
@type text_lines_opts() :: [ include_artifacts: boolean(), region: PdfElixide.Geometry.Rect.t() | nil, region_mode: region_mode(), word_gap_threshold: float() | nil, line_gap_threshold: float() | nil, profile: extraction_profile() | nil ]
Options accepted by the text_lines and text_lines! functions.
The same options as words_opts/0 — including the upstream deprecation
of :word_gap_threshold and :profile documented there — plus:
:line_gap_threshold— the vertical gap in points that starts a new line.nillets upstream compute it. Defaults tonil, and is deprecated upstream alongside the other two.
@type text_opts() :: [ extract_tables: boolean(), expand_ligatures: boolean(), table_detection: table_detection_opts() | nil, region: PdfElixide.Geometry.Rect.t() | nil, region_mode: region_mode(), exclude_regions: [PdfElixide.Geometry.Rect.t()], exclude_regions_mode: region_mode(), exclude_layers: [String.t()], exclude_inks: [String.t()], on_page_error: :skip | :halt ]
Options accepted by the text and text! functions.
:extract_tables— detect tables and render them inline as space-padded, column-aligned rows. Defaults totrue, matchingpdf_oxide's ownextract_text.:expand_ligatures— expandU+FB00–U+FB06ligatures to their component letters (fitofi, and so on). Defaults tofalse. Unlike inmarkdown_opts/0, this one is live: upstream applies it on the plain-text assembly path, which is exactly the path this function uses.:table_detection— a keyword list tuning the spatial table detector; seetable_detection_opts/0. Only consulted when:extract_tablesistrue, and its:text_fallbackkey is ignored here — upstream forces it tofalseon the text path, so a page with no ruling lines yields no tables regardless. Defaults tonil(the upstream default config).:region— aPdfElixide.Geometry.Rectkeeping only the text inside it. An extractedbboxcan be handed straight back in. Defaults tonil.:region_mode— how:regionmatches; seeregion_mode/0. Defaults to:intersects.:exclude_regions— a list of rects whose text is dropped. Applied before:region, so exclusion wins. Defaults to[].:exclude_regions_mode— how:exclude_regionsmatch. Defaults to:intersects.:exclude_layers— names of optional-content (OCG) layers to suppress. Defaults to[].:exclude_inks— names of Separation/DeviceN inks to suppress. Defaults to[].:on_page_error— what a page that fails to extract does to the whole-document result::skipit (the default) or:halt, failing the call with the first page's error. See below.
:on_page_error and partly extractable documents
Read only on the whole-document arity. text/3 and
PdfElixide.Document.Page.text/2 extract one page and always return its
error, so the option is accepted and ignored there.
:skip matches pdf_oxide's extract_all_text, which is why it is the
default: a failed page contributes an empty string, the page separator is
emitted for it either way, and the call still returns {:ok, text} with
content silently missing. That is the wrong default for an indexing,
archival or compliance pipeline, where a document that lost a page must not
look like one that never had it — :halt gives those callers
{:error, %PdfElixide.Error{}} instead, with the failing page's zero-based
index prefixed to the message.
Note that :halt is not a general corruption detector: upstream degrades
almost every damaged page to empty text rather than an error — an
undecodable content stream, missing fonts, a scan with no text layer and an
undecryptable document all extract as "". What remains, and all
:halt can catch, is a page whose page-tree entry cannot be resolved at
all. Most other whole-document extractors (chars/1, words/1,
text_lines/1, spans/1, paths/1, images/1, annotations/1,
tables/1) fail the call on such a page unconditionally, having no upstream
counterpart whose policy they must match.
fonts/1 is the exception, and it needs no option: it does have an
upstream counterpart — PdfDocument::page_font_face_lookups — and follows
its policy, so an unresolvable page contributes no fonts and the document
still succeeds. fonts/1 and fonts/2 document what that makes an empty
list mean.
Layer and ink filtering drops the other options
pdf_oxide serves layer and ink filtering only through
extract_text_filtered / extract_text_filtered_in_rect, which build
their own conversion options internally and offer no way to pass ours.
So when :exclude_layers or :exclude_inks is non-empty, only
:region and :region_mode still apply — :extract_tables,
:expand_ligatures, :table_detection, :exclude_regions and
:exclude_regions_mode fall back to their upstream defaults
(:extract_tables to true, the rest to off). The Python bindings have
the same limitation and do not document it.
Options to_markdown/2 accepts but this function does not —
:reading_order, :include_form_fields, :strip_running_headers_footers
— are omitted because upstream's text assembler never reads them. Like any
other undeclared key, passing one is silently ignored.
@type words_opts() :: [ include_artifacts: boolean(), region: PdfElixide.Geometry.Rect.t() | nil, region_mode: region_mode(), word_gap_threshold: float() | nil, profile: extraction_profile() | nil ]
Options accepted by the words and words! functions.
:include_artifacts— keep spans tagged/Artifact(running headers and footers, page numbers, watermarks; ISO 32000-1 §14.8.2.2.1). Defaults totrue, which is the current behavior and what the Python bindings default to;falseselects upstream's spec-correct variant.:region— aPdfElixide.Geometry.Rectkeeping only the words inside it. Defaults tonil.:region_mode— how:regionmatches; seeregion_mode/0. Defaults to:intersects.:word_gap_threshold— the inter-glyph gap in points that starts a new word.nillets upstream compute it adaptively from page statistics (median character width × 0.3). Defaults tonil.:profile— aextraction_profile/0, ornilfor none. Defaults tonil.
:word_gap_threshold and :profile are deprecated upstream
pdf_oxide plans to move both to a separate advanced API (its Python
bindings already emit a DeprecationWarning for them), and :profile
in particular is documented as pending removal. :profile also does
more than its name suggests: passing any profile switches span
extraction to a different, legacy ordering path (XY-cut plus a row-aware
sort), so it can change word order and not merely word boundaries —
even for :conservative, which is nominally the default profile. Prefer
leaving both at nil.
Unlike the Python bindings, :region here composes with everything else:
it is applied after extraction, so it does not discard the thresholds or
the profile.
Functions
@spec annotations(t()) :: {:ok, [PdfElixide.Document.Annotation.t()]} | {:error, PdfElixide.Error.t()}
Reads the annotations of the whole document.
Returns every page's annotations concatenated into a single flat list, in page
order, as PdfElixide.Document.Annotation structs. Each carries its zero-based
:page index. Returns {:ok, []} when the document has no annotations.
@spec annotations(t(), non_neg_integer()) :: {:ok, [PdfElixide.Document.Annotation.t()]} | {:error, PdfElixide.Error.t()}
Reads the annotations of the page at the given zero-based index.
Returns {:ok, []} when the page has no annotations. Each annotation — a link,
sticky note, highlight, form widget, and so on — is carried as a
PdfElixide.Document.Annotation struct.
@spec annotations!(t()) :: [PdfElixide.Document.Annotation.t()]
Reads the annotations of the whole document, raising an error if it fails.
@spec annotations!(t(), non_neg_integer()) :: [PdfElixide.Document.Annotation.t()]
Reads the annotations of the page at the given zero-based index, raising an error if it fails.
@spec authenticate(t(), String.t()) :: {:ok, boolean()} | {:error, PdfElixide.Error.t()}
Authenticates against the document's encryption with the given password.
Returns {:ok, true} if authentication succeeded (or the PDF is not encrypted),
{:ok, false} if the password was wrong, or {:error, reason} on a PDF/crypto error.
Unlike open/2's :password option — where a wrong password is an
{:error, %PdfElixide.Error{reason: :wrong_password}} because the document
cannot be produced — this is a password check, so a wrong password is a
normal {:ok, false} result and {:error, _} is reserved for PDF/crypto
errors.
Same as authenticate/2 but raises on error.
Still returns false (does not raise) for a wrong password.
@spec chars(t(), chars_opts() | non_neg_integer()) :: {:ok, [PdfElixide.Document.Char.t()]} | {:error, PdfElixide.Error.t()}
Extracts characters, each with its bounding box, font metadata and
typographic placement as a PdfElixide.Document.Char struct.
With a keyword list (or nothing) as the second argument, returns every page's characters concatenated into a single flat list, in page order. With a zero-based integer, returns that single page's characters instead.
See chars_opts/0 for the available options.
@spec chars(t(), non_neg_integer(), chars_opts()) :: {:ok, [PdfElixide.Document.Char.t()]} | {:error, PdfElixide.Error.t()}
Extracts the characters of the page at the given zero-based index.
See chars_opts/0 for the available options.
@spec chars!(t(), chars_opts() | non_neg_integer()) :: [PdfElixide.Document.Char.t()]
Extracts characters, raising an error if it fails.
@spec chars!(t(), non_neg_integer(), chars_opts()) :: [PdfElixide.Document.Char.t()]
Extracts the characters of the page at the given zero-based index, raising an error if it fails.
@spec close(t()) :: :ok
Releases the document's native memory immediately.
A document holds its PDF data in memory on the Rust side, which is normally
freed only when the BEAM garbage-collects the handle — invisible to the VM's
memory accounting, so nothing pressures it to happen promptly. close/1 frees
it now, which matters for long-lived processes that open many documents.
Calling it is optional and idempotent.
Afterwards, functions that read the document return
{:error, %PdfElixide.Error{reason: :closed}}, and their bang variants raise
it. version/1, source_path/1 and page_count/1 keep working, since they
read the struct rather than the native handle — page_count/1 only for a
document whose count was determined at open, which is every document except an
encrypted one opened without a password. Any PdfElixide.Document.Image or
PdfElixide.Document.Font handles already extracted from the document remain
valid — they own their data independently.
doc = PdfElixide.Document.open!("sample.pdf")
text = PdfElixide.Document.text!(doc, 0)
:ok = PdfElixide.Document.close(doc)
Returns whether the document has been released with close/1.
Returns whether the PDF document is encrypted.
@spec fonts(t()) :: {:ok, [PdfElixide.Document.Font.t()]} | {:error, PdfElixide.Error.t()}
Extracts the fonts of the whole document.
Returns every page's fonts concatenated into a single flat list, in page order,
as PdfElixide.Document.Font structs. A font used on several pages appears once
per page.
A page whose fonts cannot be read contributes nothing and does not fail the
call — see fonts/2 for what that covers. Along with text/1 this is the
only whole-document extractor that tolerates such a page, and the only one
that does so with no option to say otherwise: both follow an upstream loop's
policy, and upstream's font walk has no :halt to offer.
@spec fonts(t(), non_neg_integer()) :: {:ok, [PdfElixide.Document.Font.t()]} | {:error, PdfElixide.Error.t()}
Extracts the fonts referenced by the page at the given zero-based index.
Returns {:ok, []} when the page references no fonts. Each font is carried as a
PdfElixide.Document.Font struct with its metadata; the raw embedded font
program (when present) is pulled on demand with PdfElixide.Document.Font.data/1.
An empty list also covers a page that could not be read. pdf_oxide's own
per-page font walk (PdfDocument::page_font_face_lookups) yields no fonts
rather than an error for a page whose page-tree entry does not resolve, a page
object that is not a dictionary, a dangling /Resources reference, or a font
that fails to load — and this binding follows that policy rather than
second-guessing it. Only an out-of-range index and a failed handle are errors.
Unlike has_structure_tree?/1, there is no strict variant to fall back on; a
caller who must know whether the page is readable at all can ask text/3,
which does propagate.
@spec fonts!(t()) :: [PdfElixide.Document.Font.t()]
Extracts the fonts of the whole document, raising an error if it fails.
@spec fonts!(t(), non_neg_integer()) :: [PdfElixide.Document.Font.t()]
Extracts the fonts referenced by the page at the given zero-based index, raising an error if it fails.
@spec from_binary(binary(), open_opts()) :: {:ok, t()} | {:error, PdfElixide.Error.t()}
Opens a PDF document from the given binary data.
Opens a PDF document from the given binary data, raising an error if it fails.
@spec has_structure_tree(t()) :: {:ok, boolean()} | {:error, PdfElixide.Error.t()}
Returns whether the PDF document is a Tagged PDF with a structure tree, reporting a structure tree that cannot be read.
The strict counterpart of has_structure_tree?/1, which cannot distinguish
false from a failure. pdf_oxide keeps the three states apart — tagged
({:ok, true}), untagged ({:ok, false}) and unparseable
({:error, %PdfElixide.Error{}}) — and this is where that third one survives.
There is no bang variant, for the same reason closed?/1 has none: the
predicate above already returns a bare boolean, and it is the only shape a
raising variant could add.
Returns whether the PDF document is a Tagged PDF with a structure tree.
Answers false for a document whose structure tree cannot be read as well
as for one that has none: a corrupt /StructTreeRoot is reported the same way
an untagged document is. Use has_structure_tree/1 to tell the two apart. A
handle that cannot be used at all — a closed document, a native panic — still
raises.
@spec has_xfa(t()) :: {:ok, boolean()} | {:error, PdfElixide.Error.t()}
Returns whether the PDF document contains XFA (XML Forms Architecture) form data, reporting a catalog that cannot be read.
The strict counterpart of has_xfa?/1. Note that only a broken document
reaches the error: pdf_oxide already answers {:ok, false} for every
structural absence — a catalog that is not a dictionary, a missing
/AcroForm, a missing /XFA — so an error here means the catalog itself or
the /AcroForm reference could not be resolved.
Has no bang variant, as has_structure_tree/1 explains.
Returns whether the PDF document contains XFA (XML Forms Architecture) form data.
Answers false for a document whose catalog or /AcroForm entry cannot be
read as well as for one that carries no XFA. Use has_xfa/1 to tell the two
apart; a closed document or a native panic still raises.
@spec images(t()) :: {:ok, [PdfElixide.Document.Image.t()]} | {:error, PdfElixide.Error.t()}
Extracts the raster images of the whole document.
Returns every page's images concatenated into a single flat list, in page
order, as PdfElixide.Document.Image structs. The pixel data is not carried on
the struct — encode it on demand with PdfElixide.Document.Image.to_binary/2
or PdfElixide.Document.Image.save/3.
@spec images(t(), non_neg_integer()) :: {:ok, [PdfElixide.Document.Image.t()]} | {:error, PdfElixide.Error.t()}
Extracts the raster images of the page at the given zero-based index.
Returns {:ok, []} when the page has no images. Each image — a photo, logo, or
scanned picture — is carried as a PdfElixide.Document.Image struct, which
holds the metadata and a handle rather than the pixel data itself; encode it on
demand with PdfElixide.Document.Image.to_binary/2 or
PdfElixide.Document.Image.save/3.
@spec images!(t()) :: [PdfElixide.Document.Image.t()]
Extracts the raster images of the whole document, raising an error if it fails.
@spec images!(t(), non_neg_integer()) :: [PdfElixide.Document.Image.t()]
Extracts the raster images of the page at the given zero-based index, raising an error if it fails.
@spec metadata(t()) :: {:ok, PdfElixide.Document.Metadata.t()} | {:error, PdfElixide.Error.t()}
Reads the document's Info dictionary metadata (title, author, dates, etc.).
Always returns a PdfElixide.Document.Metadata struct; a document with no
/Info dictionary yields one with every field nil. For XMP metadata, see
xmp_metadata/1.
@spec metadata!(t()) :: PdfElixide.Document.Metadata.t()
Reads the document's Info dictionary metadata, raising an error if it fails.
@spec open(Path.t(), open_opts()) :: {:ok, t()} | {:error, PdfElixide.Error.t()}
Opens a PDF document from the specified file path.
Opens a PDF document from the specified file path, raising an error if it fails.
@spec outline(t()) :: {:ok, [PdfElixide.Document.OutlineItem.t()]} | {:error, PdfElixide.Error.t()}
Reads the document outline — its bookmarks / table of contents.
Returns the top-level PdfElixide.Document.OutlineItem structs, each of which
may carry nested :children, forming a tree. Returns {:ok, []} when the
document has no outline.
@spec outline!(t()) :: [PdfElixide.Document.OutlineItem.t()]
Reads the document outline, raising an error if it fails.
@spec page(t(), non_neg_integer()) :: {:ok, PdfElixide.Document.Page.t()} | {:error, PdfElixide.Error.t()}
Returns a lazy handle for the page at the given zero-based index.
@spec page!(t(), non_neg_integer()) :: PdfElixide.Document.Page.t()
Same as page/2 but raises an error if it fails.
@spec page_count(t()) :: {:ok, non_neg_integer()} | {:error, PdfElixide.Error.t()}
Returns the number of pages in the given PDF document.
The count arrives with the handle from the call that opens the document and is
cached on the struct, so this normally costs nothing and keeps working after
close/1, as version/1 does.
The exception is a document whose page tree could not be read at open — an
encrypted one opened without a password. Nothing is cached for it, so the
count is read from the document on every call: an error until authenticate/2
succeeds, the real count afterwards, and {:error, %PdfElixide.Error{reason: :closed}}
once the document is closed.
@spec page_count!(t()) :: non_neg_integer()
Returns the number of pages in the given PDF document, raising an error if it fails.
@spec page_labels(t()) :: {:ok, [String.t()]} | {:error, PdfElixide.Error.t()}
Returns the document's logical page labels — one per page, in page order.
Page labels are the human-facing page numbers a PDF may define (e.g. "i",
"ii", "iii", "1", "2"), independent of the zero-based physical page
index. Pages outside any declared label range fall back to their decimal page
number, so the returned list always has one entry per page.
See also PdfElixide.Document.Page.label/1 for a single page's label.
Returns the document's logical page labels, raising an error if it fails.
@spec pages(t()) :: [PdfElixide.Document.Page.t()]
Returns a lazy handle for every page in the document.
Reads the page count cached on the struct, so it raises only for a document
whose count could not be determined at open — see page_count/1.
@spec paths(t()) :: {:ok, [PdfElixide.Document.Path.t()]} | {:error, PdfElixide.Error.t()}
Extracts the vector paths of the whole document.
Returns every page's paths concatenated into a single flat list, in page
order, as PdfElixide.Document.Path structs.
@spec paths(t(), non_neg_integer()) :: {:ok, [PdfElixide.Document.Path.t()]} | {:error, PdfElixide.Error.t()}
Extracts the vector paths of the page at the given zero-based index.
Returns {:ok, []} when the page has no vector graphics. Each path — a line,
curve, rectangle, or filled shape — is carried as a PdfElixide.Document.Path
struct.
@spec paths!(t()) :: [PdfElixide.Document.Path.t()]
Extracts the vector paths of the whole document, raising an error if it fails.
@spec paths!(t(), non_neg_integer()) :: [PdfElixide.Document.Path.t()]
Extracts the vector paths of the page at the given zero-based index, raising an error if it fails.
@spec permissions(t()) :: {:ok, PdfElixide.Document.Permissions.t() | nil} | {:error, PdfElixide.Error.t()}
Reads the document's /P permission flags.
Returns {:ok, %PdfElixide.Document.Permissions{}} for an encrypted document,
or {:ok, nil} when the document is not encrypted (no permission dictionary).
Per the PDF specification these flags are advisory; see
PdfElixide.Document.Permissions.
@spec permissions!(t()) :: PdfElixide.Document.Permissions.t() | nil
Reads the document's permission flags, raising an error if it fails.
Returns the file path from which the document was loaded, or nil if it was loaded from binary data.
@spec spans(t(), spans_opts() | non_neg_integer()) :: {:ok, [PdfElixide.Document.Span.t()]} | {:error, PdfElixide.Error.t()}
Extracts spans — runs of text sharing one text state — as
PdfElixide.Document.Span structs.
With a keyword list (or nothing) as the second argument, returns every page's spans concatenated into a single flat list, in page order. With a zero-based integer, returns that single page's spans instead.
See spans_opts/0 for the available options.
@spec spans(t(), non_neg_integer(), spans_opts()) :: {:ok, [PdfElixide.Document.Span.t()]} | {:error, PdfElixide.Error.t()}
Extracts the spans of the page at the given zero-based index.
See spans_opts/0 for the available options.
@spec spans!(t(), spans_opts() | non_neg_integer()) :: [PdfElixide.Document.Span.t()]
Extracts spans, raising an error if it fails.
@spec spans!(t(), non_neg_integer(), spans_opts()) :: [PdfElixide.Document.Span.t()]
Extracts the spans of the page at the given zero-based index, raising an error if it fails.
@spec tables(t(), tables_opts() | non_neg_integer()) :: {:ok, [PdfElixide.Document.Table.t()]} | {:error, PdfElixide.Error.t()}
Detects tables, as PdfElixide.Document.Table structs.
With a keyword list (or nothing) as the second argument, returns every page's tables concatenated into a single flat list, in page order. With a zero-based integer, returns that single page's tables instead.
Document.tables(doc)
Document.tables(doc, 0)
Document.tables(doc, 0, preset: :strict, row_tolerance: 1.5)Detection is heuristic — see PdfElixide.Document.Table for the
:real_grid? flag and how to filter out likely false positives, and
tables_opts/0 for the available options.
Every returned table keeps the detected table alive on the Rust side for
PdfElixide.Document.Table.to_markdown/2 and friends, so the whole-document
form holds all of them at once. Prefer the per-page arity, or
PdfElixide.Document.Table.close/1 as you go, on a table-dense document.
@spec tables(t(), non_neg_integer(), tables_opts()) :: {:ok, [PdfElixide.Document.Table.t()]} | {:error, PdfElixide.Error.t()}
Detects the tables of the page at the given zero-based index.
Returns {:ok, []} when the page has no detectable table. See
tables_opts/0 for the available options.
@spec tables!(t(), tables_opts() | non_neg_integer()) :: [ PdfElixide.Document.Table.t() ]
Detects tables, raising an error if it fails.
@spec tables!(t(), non_neg_integer(), tables_opts()) :: [ PdfElixide.Document.Table.t() ]
Detects the tables of the page at the given zero-based index, raising an error if it fails.
@spec text(t(), text_opts() | non_neg_integer()) :: {:ok, String.t()} | {:error, PdfElixide.Error.t()}
Extracts text content.
With a keyword list (or nothing) as the second argument, extracts the whole
document — every page's text concatenated in order, separated by a form-feed
(\f) page separator. With a zero-based integer, extracts that single page
instead.
Document.text(doc)
Document.text(doc, extract_tables: false)
Document.text(doc, 0)
Document.text(doc, 0, region: word.bbox)A page that fails to extract contributes an empty string to the
whole-document result rather than failing the call, matching pdf_oxide.
Its separator is emitted regardless, so the result always splits into
exactly page_count/1 parts and a skipped page reads as a blank one. Pass
on_page_error: :halt to fail the call instead; text_opts/0 describes
when a page can fail at all and why the other extractors do not offer the
choice.
See text_opts/0 for the available options.
@spec text(t(), non_neg_integer(), text_opts()) :: {:ok, String.t()} | {:error, PdfElixide.Error.t()}
Extracts the text content of the page at the given zero-based index.
See text_opts/0 for the available options.
@spec text!(t(), text_opts() | non_neg_integer()) :: String.t()
Extracts text content, raising an error if it fails.
@spec text!(t(), non_neg_integer(), text_opts()) :: String.t()
Extracts the text content of the page at the given zero-based index, raising an error if it fails.
@spec text_lines(t(), text_lines_opts() | non_neg_integer()) :: {:ok, [PdfElixide.Document.TextLine.t()]} | {:error, PdfElixide.Error.t()}
Extracts text lines, each with its bounding box and constituent words as a
PdfElixide.Document.TextLine struct.
With a keyword list (or nothing) as the second argument, returns every page's lines concatenated into a single flat list, in page order. With a zero-based integer, returns that single page's lines instead.
See text_lines_opts/0 for the available options.
@spec text_lines(t(), non_neg_integer(), text_lines_opts()) :: {:ok, [PdfElixide.Document.TextLine.t()]} | {:error, PdfElixide.Error.t()}
Extracts the text lines of the page at the given zero-based index.
See text_lines_opts/0 for the available options.
@spec text_lines!(t(), text_lines_opts() | non_neg_integer()) :: [ PdfElixide.Document.TextLine.t() ]
Extracts text lines, raising an error if it fails.
@spec text_lines!(t(), non_neg_integer(), text_lines_opts()) :: [ PdfElixide.Document.TextLine.t() ]
Extracts the text lines of the page at the given zero-based index, raising an error if it fails.
@spec to_html(t(), html_opts() | non_neg_integer()) :: {:ok, String.t()} | {:error, PdfElixide.Error.t()}
Converts the document to HTML.
With a keyword list (or nothing) as the second argument, converts the
whole document, wrapping each page in a
<div class="page" data-page="N"> element whose N is the one-based
page number. With a zero-based integer, converts that single page
instead, without the wrapper.
Document.to_html(doc)
Document.to_html(doc, detect_headings: false)
Document.to_html(doc, 0)The result is an HTML fragment, not a standalone document: there is no
doctype, no <html>/<body>, and no stylesheet — bring your own, or
wrap the fragment yourself. A page with no extractable content converts
to an empty string, as does a document that is encrypted and could not
be decrypted.
See html_opts/0 for the available options.
@spec to_html(t(), non_neg_integer(), html_opts()) :: {:ok, String.t()} | {:error, PdfElixide.Error.t()}
Converts the page at the given zero-based index to HTML.
See html_opts/0 for the available options.
@spec to_html!(t(), html_opts() | non_neg_integer()) :: String.t()
Converts the document to HTML, raising an error if it fails.
@spec to_html!(t(), non_neg_integer(), html_opts()) :: String.t()
Converts the page at the given zero-based index to HTML, raising an error if it fails.
@spec to_markdown(t(), markdown_opts() | non_neg_integer()) :: {:ok, String.t()} | {:error, PdfElixide.Error.t()}
Converts the document to Markdown.
With a keyword list (or nothing) as the second argument, converts the
whole document, joining pages with a --- thematic break — note that
this differs from text/1, which uses a form feed. With a zero-based
integer, converts that single page instead.
Document.to_markdown(doc)
Document.to_markdown(doc, detect_headings: false)
Document.to_markdown(doc, 0)See markdown_opts/0 for the available options.
@spec to_markdown(t(), non_neg_integer(), markdown_opts()) :: {:ok, String.t()} | {:error, PdfElixide.Error.t()}
Converts the page at the given zero-based index to Markdown.
See markdown_opts/0 for the available options.
@spec to_markdown!(t(), markdown_opts() | non_neg_integer()) :: String.t()
Converts the document to Markdown, raising an error if it fails.
@spec to_markdown!(t(), non_neg_integer(), markdown_opts()) :: String.t()
Converts the page at the given zero-based index to Markdown, raising an error if it fails.
@spec version(t()) :: {non_neg_integer(), non_neg_integer()}
Returns the PDF specification version of the given document as a {major, minor} tuple.
@spec words(t(), words_opts() | non_neg_integer()) :: {:ok, [PdfElixide.Document.Word.t()]} | {:error, PdfElixide.Error.t()}
Extracts words, each with its bounding box and font metadata as a
PdfElixide.Document.Word struct.
With a keyword list (or nothing) as the second argument, returns every page's words concatenated into a single flat list, in page order. With a zero-based integer, returns that single page's words instead.
Document.words(doc)
Document.words(doc, include_artifacts: false)
Document.words(doc, 0)
Document.words(doc, 0, region: heading.bbox)See words_opts/0 for the available options.
@spec words(t(), non_neg_integer(), words_opts()) :: {:ok, [PdfElixide.Document.Word.t()]} | {:error, PdfElixide.Error.t()}
Extracts the words of the page at the given zero-based index.
See words_opts/0 for the available options.
@spec words!(t(), words_opts() | non_neg_integer()) :: [PdfElixide.Document.Word.t()]
Extracts words, raising an error if it fails.
@spec words!(t(), non_neg_integer(), words_opts()) :: [PdfElixide.Document.Word.t()]
Extracts the words of the page at the given zero-based index, raising an error if it fails.
@spec xmp_metadata(t()) :: {:ok, PdfElixide.Document.XmpMetadata.t() | nil} | {:error, PdfElixide.Error.t()}
Reads the document's XMP (Extensible Metadata Platform) metadata.
Returns {:ok, %PdfElixide.Document.XmpMetadata{}} when the document carries
an XMP packet, or {:ok, nil} when it does not. For the classic Info
dictionary metadata, see metadata/1.
@spec xmp_metadata!(t()) :: PdfElixide.Document.XmpMetadata.t() | nil
Reads the document's XMP metadata, raising an error if it fails.