Extract to String

How to extract content from a file to a string.

The extract_file_to_string method provides a straightforward way to extract text content from documents into a String.

Basic Usage

use extractous::Extractor;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let extractor = Extractor::new();
    let content = extractor.extract_file_to_string("path/to/document.pdf")?;
    println!("{}", content);
    Ok(())
}

Configuration Options

Customize the extraction process using the builder pattern:

use extractous::Extractor;
use extractous::PdfParserConfig;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let extractor = Extractor::new()
        .set_extract_string_max_length(1000)
        .set_pdf_config(
            PdfParserConfig::new()
                .set_extract_annotation_text(false)
        );
    
    let content = extractor.extract_file_to_string("path/to/document.pdf")?;
    Ok(())
}

Error Handling

The method returns a Result type, handle potential errors appropriately:

use extractous::Extractor;

fn main() {
    let extractor = Extractor::new();
    match extractor.extract_file_to_string("path/to/document.pdf") {
        Ok(content) => println!("Content: {}", content),
        Err(e) => eprintln!("Error extracting content: {}", e),
    }
}