NativeElixirPdfUtilities.Text (native_elixir_pdf_utilities v0.5.1)

View Source

Best-effort embedded text extraction for classic PDFs.

This module is native Elixir and does not perform OCR. It reads PDF content streams, decodes supported Flate-compressed streams, applies ToUnicode CMaps where present, and reconstructs approximate page layout from text matrix coordinates.

Summary

Functions

Extracts embedded text from a PDF binary.

Reads a PDF file and extracts embedded text from it.

Types

error_reason()

@type error_reason() ::
  :empty_pdf_text
  | :invalid_options
  | :invalid_pdf_input
  | :invalid_path
  | File.posix()

extract_option()

@type extract_option() :: {:layout, boolean()}

object_record()

@type object_record() :: %{
  obj: integer(),
  gen: integer(),
  tokens: [NativeElixirPdfUtilities.Tokenizer.token()]
}

text_chunk()

@type text_chunk() :: %{x: float(), y: float(), text: String.t()}

Functions

extract(pdf_binary, opts \\ [])

@spec extract(binary(), [extract_option()]) ::
  {:ok, String.t()}
  | {:error,
     {error_reason(), NativeElixirPdfUtilities.Diagnostics.diagnostic()}}

Extracts embedded text from a PDF binary.

Options:

  • :layout - when true, approximate visible text layout using spaces and line breaks. This is currently the only output mode and defaults to true.

extract_file(path, opts \\ [])

@spec extract_file(String.t(), [extract_option()]) ::
  {:ok, String.t()}
  | {:error,
     {error_reason(), NativeElixirPdfUtilities.Diagnostics.diagnostic()}}

Reads a PDF file and extracts embedded text from it.