PdfInspector.Pipeline (pdf_inspector_ex v0.1.0)

Copy Markdown View Source

Declarative routing pipeline DSL on top of PdfInspector: classify once, dispatch to a per-pdf_type strategy, aggregate.

Example

defmodule MyApp.DocPipeline do
  use PdfInspector.Pipeline

  route :text_based, :markdown          # process/1 → full-doc markdown
  route :mixed,      :pages             # extract_pages/2 → per-page markdown
  route :scanned,    {:ocr, MyApp.Ocr}  # hand OCR pages to an Ocr behaviour impl
  route :image_based, :skip             # classification only, no content

  fallback :classify                    # optional; default :classify
end

MyApp.DocPipeline.run(binary)
#=> {:ok, %PdfInspector.Pipeline.Result{}} | {:error, %PdfInspector.Error{}}

Strategies

  • :markdownPdfInspector.process/1, full-document markdown.
  • :pagesPdfInspector.extract_pages/2 (all pages), per-page markdown; pages flagged needs_ocr stay as placeholders and are listed in result.ocr_pages.
  • :classify — classification only.
  • :skip — classification only, but marks the type as deliberately skipped (distinct from the fallback).
  • {:ocr, module}extract_pages/2 first, then pages needing OCR are handed to module.extract(binary, pages) (see PdfInspector.Pipeline.Ocr); returned texts are merged into the corresponding pages.

Page indexing (upstream convention, unchanged)

result.classification.pages_needing_ocr, per-page page numbers, result.ocr_pages and the pages argument of the OCR callback are all 0-indexed.

result.markdown for :pages / :ocr strategies is a convenience join of the per-page markdowns with "\n\n" — the authoritative content is result.pages (it is not guaranteed byte-identical to the :markdown strategy's full-document output).

Classification errors (e.g. :encrypted) are propagated as {:error, %PdfInspector.Error{}} without entering any strategy.

Summary

Functions

Strategy for pdf_types without an explicit route/2 (default :classify).

Route a pdf_type to a strategy. See the moduledoc for the strategy list.

Functions

fallback(strategy)

(macro)

Strategy for pdf_types without an explicit route/2 (default :classify).

route(pdf_type, strategy)

(macro)

Route a pdf_type to a strategy. See the moduledoc for the strategy list.