NativeElixirPdfUtilities.Text (native_elixir_pdf_utilities v0.3.0)

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

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, atom()}

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, atom() | File.posix()}

Reads a PDF file and extracts embedded text from it.