NativeElixirPdfUtilities.Validators.TextValidator (native_elixir_pdf_utilities v0.13.0)

View Source

Text-extraction validation and preparation for parsed PDF documents.

The validator consumes a shared PDF validation context, validates effective page geometry and content-stream references, decodes the streams once, and converts content syntax into operation instructions. The extractor consumes those prepared values instead of reopening page dictionaries or tokenizing content independently.

Summary

Types

A text-specific context prepared from the shared PDF context.

A validated content instruction with operands in source order.

One page prepared for strict text extraction.

A validated public text-extraction request.

Functions

Validates and tokenizes one decoded PDF content stream into instructions.

Converts one PDF numeric token into its semantic number.

Converts an exact-length list of PDF numeric tokens into floating-point values.

Prepares all resolved pages and their content streams for text extraction.

Validates a public file-extraction path before file access.

Validates and normalizes a public text-extraction request.

Validates balanced graphics-state and text-object scopes across instruction streams.

Types

context()

@type context() :: %{
  document: NativeElixirPdfUtilities.Validators.PdfValidator.document(),
  pages: [page_context()],
  preparation_stats: preparation_stats()
}

A text-specific context prepared from the shared PDF context.

instruction()

@type instruction() :: %{operator: binary(), operands: [term()]}

A validated content instruction with operands in source order.

page_context()

@type page_context() :: %{
  number: pos_integer(),
  ref: NativeElixirPdfUtilities.Validators.PdfValidator.ref(),
  media_box: [number()],
  rotation: integer(),
  contents: [[instruction()]]
}

One page prepared for strict text extraction.

request()

@type request() :: %{
  pdf: binary(),
  options: %{optional(:layout) => boolean(), optional(:order) => atom()}
}

A validated public text-extraction request.

Functions

instructions(content, page_number)

@spec instructions(binary(), pos_integer()) ::
  {:ok, [instruction()]}
  | {:error, {atom(), NativeElixirPdfUtilities.Diagnostics.diagnostic()}}

Validates and tokenizes one decoded PDF content stream into instructions.

number(value)

@spec number(term()) :: {:ok, number()} | :error

Converts one PDF numeric token into its semantic number.

numbers(values, count)

@spec numbers([term()], non_neg_integer()) :: {:ok, [float()]} | :error

Converts an exact-length list of PDF numeric tokens into floating-point values.

prepare(pdf_context)

Prepares all resolved pages and their content streams for text extraction.

validate_path(path, operation)

@spec validate_path(term(), atom()) ::
  {:ok, String.t()}
  | {:error, {atom(), NativeElixirPdfUtilities.Diagnostics.diagnostic()}}

Validates a public file-extraction path before file access.

validate_request(pdf, opts, operation)

@spec validate_request(term(), term(), :extract | :extract_spans) ::
  {:ok, request()}
  | {:error, {atom(), NativeElixirPdfUtilities.Diagnostics.diagnostic()}}

Validates and normalizes a public text-extraction request.

validate_scopes(contents, page_number)

@spec validate_scopes([[instruction()]], pos_integer()) ::
  :ok | {:error, {atom(), NativeElixirPdfUtilities.Diagnostics.diagnostic()}}

Validates balanced graphics-state and text-object scopes across instruction streams.

The instruction lists are treated as one logical sequence so page scopes may cross /Contents stream boundaries. Form XObjects should pass their single instruction list separately because their scopes are independent.