ExtractousEx (ExtractousEx v0.2.1)
View SourceExtractousEx provides text extraction from various document formats using the Extractous Rust library.
Supports PDF, Microsoft Office documents, HTML, plain text, CSV, JSON, and many other formats.
Extraction Methods
extract_from_file/2- Extract text from a file on diskextract_from_bytes/2- Extract text from binary data in memoryextract_from_url/2- Extract text from a URL
Each method has a corresponding bang version (e.g., extract_from_file!/2) that raises on error.
Options
All extraction methods accept a keyword list of options:
General options (top-level):
:xml- whentrue, returns structured XML output. Whenfalse(default), returns plain text.:max_length- maximum length of extracted text in characters. Default is 500,000.:encoding- encoding for text extraction. Supported values: "UTF-8" (default), "UTF-16BE", "US-ASCII".
PDF options (under :pdf key):
:ocr_strategy- "NO_OCR", "AUTO", "OCR_ONLY", or "OCR_AND_TEXT_EXTRACTION":extract_annotation_text- extract text from PDF annotations:extract_inline_images- extract inline images:extract_unique_inline_images_only- extract only unique inline images:extract_marked_content- extract marked content
Office options (under :office key):
:include_shape_based_content- include shape-based content:include_slide_notes- include slide notes:include_slide_master_content- include slide master content:concatenate_phonetic_runs- concatenate phonetic runs:include_headers_and_footers- include headers and footers:include_deleted_content- include deleted content:include_move_from_content- include move-from content:include_missing_rows- include missing rows:extract_macros- extract macros:extract_all_alternatives_from_msg- extract all alternatives from MSG files
OCR options (under :ocr key):
:language- Tesseract language (e.g., "eng", "deu", "eng+deu"):timeout_seconds- OCR timeout in seconds:density- image density for OCR:depth- image depth for OCR:apply_rotation- apply rotation during OCR:enable_image_preprocessing- enable image preprocessing for OCR
Examples
# Simple usage
ExtractousEx.extract_from_file("document.pdf")
{:ok, %{content: "Document text...", metadata: %{}}}
# With basic options
ExtractousEx.extract_from_file("document.pdf", xml: true, max_length: 100_000)
{:ok, %{content: "<xml>...</xml>", metadata: %{}}}
# With advanced options
ExtractousEx.extract_from_file("document.pdf",
max_length: 1_000_000,
xml: true,
pdf: [
ocr_strategy: "AUTO",
extract_annotation_text: true
],
ocr: [
language: "eng+deu",
timeout_seconds: 60
]
)
{:ok, %{content: "Document text...", metadata: %{}}}
Summary
Functions
Extracts text and metadata from binary data.
Extracts text from bytes, raising on error.
Extracts text and metadata from a file.
Extracts text from a file, raising on error.
Extracts text and metadata from a URL.
Extracts text from a URL, raising on error.
Functions
@spec extract_from_bytes( binary(), keyword() ) :: {:ok, %{content: String.t(), metadata: map()}} | {:error, String.t()}
Extracts text and metadata from binary data.
Options
Accepts a keyword list of options. See module documentation for full details.
Examples
# Extract from PDF bytes
{:ok, pdf_data} = File.read("document.pdf")
ExtractousEx.extract_from_bytes(pdf_data)
{:ok, %{content: "Document text...", metadata: %{}}}
# With options
ExtractousEx.extract_from_bytes(data,
xml: true,
max_length: 100_000
)
{:ok, %{content: "<xml>...</xml>", metadata: %{}}}Returns
Returns {:ok, result} on success where result is a map with:
:content- The extracted text content:metadata- Document metadata as a map
Returns {:error, reason} on failure.
Extracts text from bytes, raising on error.
Same as extract_from_bytes/2 but raises an exception on failure.
Examples
{:ok, data} = File.read("document.pdf")
ExtractousEx.extract_from_bytes!(data)
%{content: "Document text...", metadata: %{}}
@spec extract_from_file( String.t(), keyword() ) :: {:ok, %{content: String.t(), metadata: map()}} | {:error, String.t()}
Extracts text and metadata from a file.
Options
Accepts a keyword list of options. See module documentation for full details.
Examples
# Simple usage
ExtractousEx.extract_from_file("document.pdf")
{:ok, %{content: "Document text...", metadata: %{}}}
# With options
ExtractousEx.extract_from_file("document.pdf", xml: true)
{:ok, %{content: "<xml>...</xml>", metadata: %{}}}
# With nested options
ExtractousEx.extract_from_file("document.pdf",
xml: true,
pdf: [ocr_strategy: "NO_OCR"]
)
{:ok, %{content: "Document text...", metadata: %{}}}Returns
Returns {:ok, result} on success where result is a map with:
:content- The extracted text content:metadata- Document metadata as a map
Returns {:error, reason} on failure.
Extracts text from a file, raising on error.
Same as extract_from_file/2 but raises an exception on failure.
Examples
ExtractousEx.extract_from_file!("document.pdf")
%{content: "Document text...", metadata: %{}}
@spec extract_from_url( String.t(), keyword() ) :: {:ok, %{content: String.t(), metadata: map()}} | {:error, String.t()}
Extracts text and metadata from a URL.
Options
Accepts a keyword list of options. See module documentation for full details.
Examples
# Extract from a URL
ExtractousEx.extract_from_url("https://example.com/document.pdf")
{:ok, %{content: "Document text...", metadata: %{}}}
# With options
ExtractousEx.extract_from_url("https://example.com/doc.html",
xml: true,
office: [include_headers_and_footers: true]
)
{:ok, %{content: "<html>...</html>", metadata: %{}}}Returns
Returns {:ok, result} on success where result is a map with:
:content- The extracted text content:metadata- Document metadata as a map
Returns {:error, reason} on failure.
Extracts text from a URL, raising on error.
Same as extract_from_url/2 but raises an exception on failure.
Examples
ExtractousEx.extract_from_url!("https://example.com/document.pdf")
%{content: "Document text...", metadata: %{}}