PdfElixide.Document.Page (pdf_elixide v0.9.0)

Copy Markdown View Source

Representation of a page of a PDF document.

Summary

Functions

Reads the annotations on the page.

Same as annotations/1 but raises an error if it fails.

Extracts the characters of the page, each with its bounding box, font metadata, and typographic placement.

Same as chars/2 but raises an error if it fails.

Extracts the fonts referenced by the page.

Same as fonts/1 but raises an error if it fails.

Returns the page's height in points.

Same as height/1 but raises an error if it fails.

Extracts the raster images of the page — photos, logos, and scanned pictures.

Same as images/1 but raises an error if it fails.

Returns the page's logical page label (e.g. "i", "1", "A-1").

Same as label/1 but raises an error if it fails.

Extracts the vector paths of the page — lines, curves, rectangles, and shapes.

Same as paths/1 but raises an error if it fails.

Extracts the spans of the page, each a run of text sharing one text state.

Same as spans/2 but raises an error if it fails.

Detects the tables of the page.

Same as tables/2 but raises an error if it fails.

Extracts the text content of the page.

Same as text/2 but raises an error if it fails.

Extracts the text lines of the page, each with its bounding box and words.

Same as text_lines/2 but raises an error if it fails.

Converts the page to an HTML fragment.

Same as to_html/2 but raises an error if it fails.

Converts the page to Markdown.

Same as to_markdown/2 but raises an error if it fails.

Returns the page's width in points.

Same as width/1 but raises an error if it fails.

Extracts the words of the page, each with its bounding box and font metadata.

Same as words/2 but raises an error if it fails.

Types

t()

@type t() :: %PdfElixide.Document.Page{
  doc: PdfElixide.Document.t(),
  index: non_neg_integer()
}

Functions

annotations(page)

@spec annotations(t()) ::
  {:ok, [PdfElixide.Document.Annotation.t()]} | {:error, PdfElixide.Error.t()}

Reads the annotations on the page.

Returns {:ok, []} when the page has no annotations.

annotations!(page)

@spec annotations!(t()) :: [PdfElixide.Document.Annotation.t()]

Same as annotations/1 but raises an error if it fails.

chars(page, opts \\ [])

@spec chars(t(), PdfElixide.Document.chars_opts()) ::
  {:ok, [PdfElixide.Document.Char.t()]} | {:error, PdfElixide.Error.t()}

Extracts the characters of the page, each with its bounding box, font metadata, and typographic placement.

See PdfElixide.Document.chars_opts/0 for the available options.

chars!(page, opts \\ [])

Same as chars/2 but raises an error if it fails.

fonts(page)

@spec fonts(t()) ::
  {:ok, [PdfElixide.Document.Font.t()]} | {:error, PdfElixide.Error.t()}

Extracts the fonts referenced by the page.

Returns {:ok, []} when the page references no fonts — and also when the page or its /Resources could not be read, which PdfElixide.Document.fonts/2 explains.

fonts!(page)

@spec fonts!(t()) :: [PdfElixide.Document.Font.t()]

Same as fonts/1 but raises an error if it fails.

height(page)

@spec height(t()) :: {:ok, float()} | {:error, PdfElixide.Error.t()}

Returns the page's height in points.

height!(page)

@spec height!(t()) :: float()

Same as height/1 but raises an error if it fails.

images(page)

@spec images(t()) ::
  {:ok, [PdfElixide.Document.Image.t()]} | {:error, PdfElixide.Error.t()}

Extracts the raster images of the page — photos, logos, and scanned pictures.

Returns {:ok, []} when the page has no images.

images!(page)

@spec images!(t()) :: [PdfElixide.Document.Image.t()]

Same as images/1 but raises an error if it fails.

label(page)

@spec label(t()) :: {:ok, String.t()} | {:error, PdfElixide.Error.t()}

Returns the page's logical page label (e.g. "i", "1", "A-1").

This is the human-facing page number the PDF may define, independent of the zero-based physical index. Pages outside any declared label range fall back to their decimal page number.

A page whose :index is not a page of the document — only reachable from a hand-built or stale %Page{} — yields %PdfElixide.Error{reason: :out_of_range}.

Every call re-reads the document's label ranges, so use PdfElixide.Document.page_labels/1 to label a whole document.

label!(page)

@spec label!(t()) :: String.t()

Same as label/1 but raises an error if it fails.

paths(page)

@spec paths(t()) ::
  {:ok, [PdfElixide.Document.Path.t()]} | {:error, PdfElixide.Error.t()}

Extracts the vector paths of the page — lines, curves, rectangles, and shapes.

Returns {:ok, []} when the page has no vector graphics.

paths!(page)

@spec paths!(t()) :: [PdfElixide.Document.Path.t()]

Same as paths/1 but raises an error if it fails.

spans(page, opts \\ [])

@spec spans(t(), PdfElixide.Document.spans_opts()) ::
  {:ok, [PdfElixide.Document.Span.t()]} | {:error, PdfElixide.Error.t()}

Extracts the spans of the page, each a run of text sharing one text state.

See PdfElixide.Document.spans_opts/0 for the available options.

spans!(page, opts \\ [])

Same as spans/2 but raises an error if it fails.

tables(page, opts \\ [])

@spec tables(t(), PdfElixide.Document.tables_opts()) ::
  {:ok, [PdfElixide.Document.Table.t()]} | {:error, PdfElixide.Error.t()}

Detects the tables of the page.

Returns {:ok, []} when the page has no detectable table. See PdfElixide.Document.tables_opts/0 for the available options.

tables!(page, opts \\ [])

Same as tables/2 but raises an error if it fails.

text(page, opts \\ [])

@spec text(t(), PdfElixide.Document.text_opts()) ::
  {:ok, String.t()} | {:error, PdfElixide.Error.t()}

Extracts the text content of the page.

A page that cannot be extracted is an error here, where PdfElixide.Document.text/1 skips it by default — :on_page_error is a whole-document option and does nothing on this path.

See PdfElixide.Document.text_opts/0 for the available options.

text!(page, opts \\ [])

@spec text!(t(), PdfElixide.Document.text_opts()) :: String.t()

Same as text/2 but raises an error if it fails.

text_lines(page, opts \\ [])

@spec text_lines(t(), PdfElixide.Document.text_lines_opts()) ::
  {:ok, [PdfElixide.Document.TextLine.t()]} | {:error, PdfElixide.Error.t()}

Extracts the text lines of the page, each with its bounding box and words.

See PdfElixide.Document.text_lines_opts/0 for the available options.

text_lines!(page, opts \\ [])

Same as text_lines/2 but raises an error if it fails.

to_html(page, opts \\ [])

@spec to_html(t(), PdfElixide.Document.html_opts()) ::
  {:ok, String.t()} | {:error, PdfElixide.Error.t()}

Converts the page to an HTML fragment.

See PdfElixide.Document.html_opts/0 for the available options.

to_html!(page, opts \\ [])

@spec to_html!(t(), PdfElixide.Document.html_opts()) :: String.t()

Same as to_html/2 but raises an error if it fails.

to_markdown(page, opts \\ [])

@spec to_markdown(t(), PdfElixide.Document.markdown_opts()) ::
  {:ok, String.t()} | {:error, PdfElixide.Error.t()}

Converts the page to Markdown.

See PdfElixide.Document.markdown_opts/0 for the available options.

to_markdown!(page, opts \\ [])

@spec to_markdown!(t(), PdfElixide.Document.markdown_opts()) :: String.t()

Same as to_markdown/2 but raises an error if it fails.

width(page)

@spec width(t()) :: {:ok, float()} | {:error, PdfElixide.Error.t()}

Returns the page's width in points.

width!(page)

@spec width!(t()) :: float()

Same as width/1 but raises an error if it fails.

words(page, opts \\ [])

@spec words(t(), PdfElixide.Document.words_opts()) ::
  {:ok, [PdfElixide.Document.Word.t()]} | {:error, PdfElixide.Error.t()}

Extracts the words of the page, each with its bounding box and font metadata.

See PdfElixide.Document.words_opts/0 for the available options.

words!(page, opts \\ [])

Same as words/2 but raises an error if it fails.