oxidize-pdf 2.5.1

A pure Rust PDF generation and manipulation library with zero external dependencies
Documentation
use oxidize_pdf::parser::ParseOptions;
use oxidize_pdf::text::{ExtractionOptions, TextExtractor};
use oxidize_pdf::{PdfDocument, PdfReader};
use std::path::Path;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    println!("๐Ÿ”ง Testing PDF Error Fixes");
    println!("{}", "=".repeat(50));

    // Test specific PDFs that had the errors we fixed
    let problematic_pdfs = vec![
        ("000000125718410 (1).pdf", "Page tree node dictionary"),
        (
            "0184c79b-9922-4514-a9ed-3919070ca099.pdf",
            "FlateDecode strategies",
        ),
        ("04.ANNEX 2 PQQ rev.01.pdf", "Missing required key: Pages"),
        (
            "30_solo_w_pacb167_h7bjyoULAocc_yA4HCUM_g.pdf",
            "Invalid object reference",
        ),
        ("9952079-PRO-VK-LEA-ES.pdf", "Invalid object reference"),
        ("390 2023 3CO_compressed (1).pdf", "Unexpected character: :"),
    ];

    let parse_options = ParseOptions::lenient();
    let options = ExtractionOptions::default();
    let mut extractor = TextExtractor::with_options(options);

    let mut successful_fixes = 0;
    let mut total_tests = problematic_pdfs.len();

    for (pdf_name, error_type) in &problematic_pdfs {
        let pdf_path = format!("tests/fixtures/{}", pdf_name);

        if !Path::new(&pdf_path).exists() {
            println!("โญ๏ธ  {} - file not found, skipping", pdf_name);
            total_tests -= 1;
            continue;
        }

        print!("๐Ÿงช Testing {} ({})... ", pdf_name, error_type);

        match PdfReader::open_with_options(&pdf_path, parse_options.clone()) {
            Ok(reader) => {
                let document = PdfDocument::new(reader);

                match document.page_count() {
                    Ok(0) => {
                        println!("โœ… No crash (0 pages)");
                        successful_fixes += 1;
                    }
                    Ok(page_count) => {
                        // Try to extract from first page
                        match extractor.extract_from_page(&document, 0) {
                            Ok(extracted_text) => {
                                let content = extracted_text.text.trim();
                                if content.is_empty() {
                                    println!("โœ… No crash (empty content, {} pages)", page_count);
                                } else {
                                    println!(
                                        "โœ… Extracted {} chars ({} pages)",
                                        content.len(),
                                        page_count
                                    );
                                }
                                successful_fixes += 1;
                            }
                            Err(e) => {
                                println!("โš ๏ธ  Extraction error: {}", e);
                                // Still count as fixed if we didn't crash
                                successful_fixes += 1;
                            }
                        }
                    }
                    Err(e) => {
                        println!("โš ๏ธ  Page count error: {}", e);
                        // Still count as fixed if we didn't crash
                        successful_fixes += 1;
                    }
                }
            }
            Err(e) => {
                println!("โŒ Open failed: {}", e);
            }
        }
    }

    println!("\n{}", "=".repeat(50));
    println!("๐Ÿ“ˆ RESULTS SUMMARY");
    println!("{}", "=".repeat(50));
    println!(
        "โœ… Successfully handled: {}/{}",
        successful_fixes, total_tests
    );
    println!(
        "๐ŸŽฏ Success rate: {:.1}%",
        if total_tests > 0 {
            successful_fixes as f64 / total_tests as f64 * 100.0
        } else {
            0.0
        }
    );

    if successful_fixes == total_tests {
        println!("๐ŸŽ‰ All error fixes working correctly!");
    } else {
        println!("โš ๏ธ  Some issues remain");
    }

    Ok(())
}