Skip to main content

InvoiceExtractorBuilder

Struct InvoiceExtractorBuilder 

Source
pub struct InvoiceExtractorBuilder { /* private fields */ }
Expand description

Builder for configuring InvoiceExtractor

Provides a fluent API for configuring extraction behavior. All settings have sensible defaults for immediate use.

§Defaults

  • Language: None (uses default patterns)
  • Confidence Threshold: 0.7 (70%)
  • Use Kerning: true (stored but not yet functional - see use_kerning() docs)

§Examples

use oxidize_pdf::text::invoice::InvoiceExtractor;

// Minimal configuration
let extractor = InvoiceExtractor::builder()
    .with_language("es")
    .build();

// Full configuration
let extractor = InvoiceExtractor::builder()
    .with_language("de")
    .confidence_threshold(0.85)
    .use_kerning(false)
    .build();

Implementations§

Source§

impl InvoiceExtractorBuilder

Source

pub fn new() -> Self

Create a new builder with default settings

Defaults:

  • No language (uses English patterns)
  • Confidence threshold: 0.7
  • Kerning: enabled
Source

pub fn with_language(self, lang: &str) -> Self

Set the language for pattern matching

Accepts language codes: “es”, “en”, “de”, “it”

§Examples
use oxidize_pdf::text::invoice::InvoiceExtractor;

let extractor = InvoiceExtractor::builder()
    .with_language("es")  // Spanish patterns
    .build();
Source

pub fn confidence_threshold(self, threshold: f64) -> Self

Set the minimum confidence threshold (0.0 to 1.0)

Fields below this threshold are filtered out. Higher values reduce false positives but may miss valid fields.

Recommended values:

  • 0.5: Maximum recall (may include false positives)
  • 0.7: Balanced (default)
  • 0.9: Maximum precision (may miss valid fields)
§Examples
use oxidize_pdf::text::invoice::InvoiceExtractor;

// High precision mode
let extractor = InvoiceExtractor::builder()
    .confidence_threshold(0.9)
    .build();
§Validation

The threshold is automatically clamped to the valid range [0.0, 1.0]. Values outside this range are silently adjusted to the nearest valid value.

Source

pub fn use_kerning(self, enabled: bool) -> Self

Enable or disable kerning-aware text positioning (PLANNED for v2.0)

Current Behavior: This flag is stored but NOT yet used in extraction logic.

Planned Feature (v2.0): When enabled, text reconstruction will use actual font kerning pairs to calculate accurate character spacing, improving pattern matching for invoices with tight kerning (e.g., “AV”, “To”).

Why Not Implemented: Requires architectural changes to expose font metadata in TextFragment. See struct documentation for technical details.

§Examples
use oxidize_pdf::text::invoice::InvoiceExtractor;

// Enable for future use (no effect in v1.x)
let extractor = InvoiceExtractor::builder()
    .use_kerning(true)  // ⚠️ Stored but not yet functional
    .build();
Source

pub fn with_custom_patterns(self, patterns: PatternLibrary) -> Self

Use a custom pattern library instead of language-based defaults

Allows complete control over invoice pattern matching by providing a custom PatternLibrary. Useful for specialized invoice formats or combining default patterns with custom additions.

Note: When using custom patterns, the with_language() setting is ignored.

§Examples

Example 1: Use default patterns and add custom ones

use oxidize_pdf::text::invoice::{InvoiceExtractor, PatternLibrary, FieldPattern, InvoiceFieldType, Language};

// Start with Spanish defaults
let mut patterns = PatternLibrary::default_spanish();

// Add custom pattern for your specific invoice format
patterns.add_pattern(
    FieldPattern::new(
        InvoiceFieldType::InvoiceNumber,
        r"Ref:\s*([A-Z0-9\-]+)",  // Your custom format
        0.85,
        Some(Language::Spanish)
    ).unwrap()
);

let extractor = InvoiceExtractor::builder()
    .with_custom_patterns(patterns)
    .build();

Example 2: Build completely custom pattern library

use oxidize_pdf::text::invoice::{InvoiceExtractor, PatternLibrary, FieldPattern, InvoiceFieldType, Language};

let mut patterns = PatternLibrary::new();

// Add only the patterns you need
patterns.add_pattern(
    FieldPattern::new(
        InvoiceFieldType::InvoiceNumber,
        r"Order\s+#([0-9]+)",
        0.9,
        None  // Language-agnostic
    ).unwrap()
);

let extractor = InvoiceExtractor::builder()
    .with_custom_patterns(patterns)
    .confidence_threshold(0.8)
    .build();
Source

pub fn build(self) -> InvoiceExtractor

Build the InvoiceExtractor

Trait Implementations§

Source§

impl Default for InvoiceExtractorBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more