### Project Setup and Verification Source: https://github.com/yfedoseev/pdf_oxide/blob/main/docs/DEVELOPMENT_GUIDE.md Clones the repository, navigates into the project directory, and performs initial checks for setup verification using cargo commands. ```bash # Clone and setup git clone cd pdf_oxide # Verify setup cargo check --all-features cargo test cargo clippy --all-targets ``` -------------------------------- ### Simple Text Conversion Example Source: https://github.com/yfedoseev/pdf_oxide/blob/main/docs/MARKDOWN_CONVERTER_USAGE.md A basic Rust configuration using TextPipelineConfig::default() for simple text conversion. This setup preserves basic text formatting like bold and italics but does not enable advanced features like heading detection or table extraction. ```rust let config = TextPipelineConfig::default(); // Result: // Plain text with **bold** and *italic* preserved // but no heading detection or tables ``` -------------------------------- ### Install Development Tools (Bash) Source: https://github.com/yfedoseev/pdf_oxide/blob/main/LINTING.md Installs Python development dependencies and verifies installations of Rust formatting and linting tools. Requires `requirements-dev.txt`. ```bash # Install Python development dependencies pip install -r requirements-dev.txt # Verify installations cargo fmt --version cargo clippy --version ruff --version ``` -------------------------------- ### Development Setup and Tools Source: https://github.com/yfedoseev/pdf_oxide/blob/main/README.md Instructions for setting up the development environment for pdf_oxide, including cloning the repository, building the project, installing development tools, and running tests, formatting, and linting. ```bash # Clone and build git clone https://github.com/yfedoseev/pdf_oxide cd pdf_oxide cargo build # Install development tools cargo install cargo-watch cargo-tarpaulin # Run tests on file changes cargo watch -x test # Format code cargo fmt # Run linter cargo clippy -- -D warnings ``` -------------------------------- ### Install Rust and Development Tools Source: https://github.com/yfedoseev/pdf_oxide/blob/main/docs/DEVELOPMENT_GUIDE.md Installs the Rust programming language and essential development tools like cargo-tarpaulin, cargo-audit, cargo-deny, flamegraph, and criterion using curl and cargo. ```bash # Install Rust (stable 1.70+) curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh # Install development tools cargo install cargo-tarpaulin # Coverage cargo install cargo-audit # Security auditing cargo install cargo-deny # License checking cargo install flamegraph # Profiling cargo install criterion # Benchmarking ``` -------------------------------- ### Rust TDD Cycle Example Source: https://github.com/yfedoseev/pdf_oxide/blob/main/docs/DEVELOPMENT_GUIDE.md Illustrates the Test-Driven Development (TDD) cycle in Rust, showing the steps from defining an API and writing tests to implementing, refactoring, documenting, and benchmarking the code. ```rust // Step 1: Define API pub fn extract_text(page: &Page) -> Result { todo!() } // Step 2: Write test #[test] fn test_extract_text() { let page = create_test_page(); let text = extract_text(&page).unwrap(); assert_eq!(text, "expected content"); } // Step 3: Implement pub fn extract_text(page: &Page) -> Result { // Implementation Ok(String::new()) } // Step 4: Refactor as needed // Step 5: Document /// Extracts text from a PDF page... pub fn extract_text(page: &Page) -> Result { // ... } // Step 6: Benchmark (if needed) ``` -------------------------------- ### Rust Benchmark Example (criterion) Source: https://github.com/yfedoseev/pdf_oxide/blob/main/docs/DEVELOPMENT_GUIDE.md An example of how to write benchmarks in Rust using the `criterion` crate. This snippet shows how to benchmark a parsing function. ```rust fn bench_parsing(c: &mut Criterion) { c.bench_function("parse", |b| { b.iter(|| parse(black_box(&data))) }); } ``` -------------------------------- ### Install Development Dependencies (Bash) Source: https://github.com/yfedoseev/pdf_oxide/blob/main/LINTING.md Installs Python development dependencies from `requirements-dev.txt`, which is necessary to resolve the 'ruff: command not found' issue. ```bash pip install -r requirements-dev.txt ``` -------------------------------- ### Rust Integration Test Example Source: https://github.com/yfedoseev/pdf_oxide/blob/main/docs/DEVELOPMENT_GUIDE.md An example of a Rust integration test, typically located in the `tests/` directory, demonstrating how to open a PDF document and extract text as part of a workflow test. ```rust #[test] fn test_full_workflow() -> Result<(), Box> { let doc = PdfDocument::open("tests/fixtures/sample.pdf")?; let text = doc.extract_text(0)?; assert!(!text.is_empty()); Ok(()) } ``` -------------------------------- ### Form Extraction Example Source: https://github.com/yfedoseev/pdf_oxide/blob/main/docs/MARKDOWN_CONVERTER_USAGE.md This Rust example configures the TextPipelineConfig for form extraction. It prioritizes layout preservation and conservative bold marker behavior to maintain the structure of form-like text. ```rust let config = TextPipelineConfig { output: OutputConfig { preserve_layout: true, bold_marker_behavior: BoldMarkerBehavior::Conservative, ..Default::default() }, ..Default::default() }; // Result: // Name: ________________ Date: __________ // Address: ___________________________________ ``` -------------------------------- ### Installation Source: https://github.com/yfedoseev/pdf_oxide/blob/main/README.md Instructions for installing the pdf_oxide library for both Rust and Python projects. ```APIDOC ## Installation ### Rust Library Add the following to your `Cargo.toml` file: ```toml [dependencies] pdf_oxide = "0.2" ``` ### Python Package Install using pip: ```bash pip install pdf_oxide ``` ``` -------------------------------- ### Rust: Writing a Custom PDF Oxide Test Source: https://github.com/yfedoseev/pdf_oxide/blob/main/docs/MARKDOWN_CONVERTER_USAGE.md Example of a unit test in Rust for PDF Oxide, demonstrating how to create an `OrderedTextSpan`, configure `TextPipelineConfig` with `OutputConfig`, and use `MarkdownOutputConverter` to verify output. Includes necessary imports for layout and pipeline components. ```rust #[test] fn my_custom_test() { use pdf_oxide::layout::{Color, FontWeight, TextSpan}; use pdf_oxide::pipeline::OrderedTextSpan; let span = OrderedTextSpan::new( TextSpan { text: "My text".to_string(), bbox: Rect::new(0.0, 100.0, 100.0, 24.0), font_name: "Arial".to_string(), font_size: 24.0, font_weight: FontWeight::Bold, is_italic: false, color: Color::black(), mcid: None, sequence: 0, offset_semantic: false, split_boundary_before: false, char_spacing: 0.0, word_spacing: 0.0, horizontal_scaling: 100.0, }, 0, ); let converter = MarkdownOutputConverter::new(); let config = TextPipelineConfig { output: OutputConfig { detect_headings: true, ..Default::default() }, ..Default::default() }; let output = converter.convert(&vec![span], &config).unwrap(); assert!(output.contains("# My text")); } ``` -------------------------------- ### Rust Documentation Test Example Source: https://github.com/yfedoseev/pdf_oxide/blob/main/docs/DEVELOPMENT_GUIDE.md Provides an example of how to write documentation tests in Rust using code blocks within doc comments. These examples are automatically compiled and tested with `cargo test --doc`. ```rust /// # Examples /// /// ``` /// use pdf_oxide::PdfDocument; /// /// # fn main() -> Result<(), Box> { /// let doc = PdfDocument::open("sample.pdf")?; /// assert_eq!(doc.page_count(), 1); /// # Ok(()) /// # } /// ``` ``` -------------------------------- ### Setup Pre-commit Hooks Source: https://github.com/yfedoseev/pdf_oxide/blob/main/CONTRIBUTING.md Installs and configures pre-commit hooks for the project. These hooks automate code formatting, linting, and various checks before each commit, ensuring code quality and consistency. ```bash ./scripts/setup-hooks.sh ``` -------------------------------- ### Example Git Pull Request Description Source: https://github.com/yfedoseev/pdf_oxide/blob/main/docs/DEVELOPMENT_GUIDE.md Illustrates a template for writing clear and informative Git pull request descriptions. It includes sections for summarizing changes, explaining the rationale, detailing testing methods, and providing a checklist for review. ```markdown ## What Brief description ## Why Reason for changes ## Testing How tested ## Description Brief description of the feature or fix being implemented. ## Checklist - [x] Tests pass - [x] Documentation updated - [x] Self-reviewed ``` -------------------------------- ### Rust Unit Test Example Source: https://github.com/yfedoseev/pdf_oxide/blob/main/docs/DEVELOPMENT_GUIDE.md A basic example of a Rust unit test within a module, demonstrating the use of `#[test]` attribute and `assert_eq!` macro for verifying function behavior. ```rust #[test] fn test_parse_integer() { let input = b"42"; let result = parse_integer(input).unwrap(); assert_eq!(result, 42); } ``` -------------------------------- ### Rust Property-Based Test Example (proptest) Source: https://github.com/yfedoseev/pdf_oxide/blob/main/docs/DEVELOPMENT_GUIDE.md Demonstrates how to write property-based tests using the `proptest` crate in Rust. This example shows a test that ensures a function under test never panics with various generated inputs. ```rust proptest! { #[test] fn never_panics(input in any_input()) { let _ = function_under_test(input); } } ``` -------------------------------- ### Build pdf_oxide with OCR Support (Rust & Python) Source: https://github.com/yfedoseev/pdf_oxide/blob/main/docs/ML_INTEGRATION.md Installs the pdf_oxide library with OCR features enabled. This requires building with the `--features ocr` flag for Rust and the `--features ocr` argument for Python's pip install. ```bash # Build with OCR feature cargo build --release --features ocr # Python pip install . --features ocr ``` -------------------------------- ### Run All Project Checks (Bash) Source: https://github.com/yfedoseev/pdf_oxide/blob/main/LINTING.md Executes all configured code quality checks for both Rust and Python projects. Can be run individually for Rust or Python. Assumes `make` is installed. ```bash # Check everything (Rust + Python) make check-all # Or individually: make check # Rust only make check-py # Python only ``` -------------------------------- ### Academic Paper Conversion Example Source: https://github.com/yfedoseev/pdf_oxide/blob/main/docs/MARKDOWN_CONVERTER_USAGE.md A Rust code snippet demonstrating the configuration of TextPipelineConfig for converting academic papers. It enables heading detection, table extraction, and uses a conservative bold marker behavior. ```rust let config = TextPipelineConfig { output: OutputConfig { detect_headings: true, bold_marker_behavior: BoldMarkerBehavior::Conservative, extract_tables: true, preserve_layout: false, ..Default::default() }, ..Default::default() }; // Result: // # Introduction // // This paper discusses **important** concepts. // // | Metric | Value | // |--------|-------| // | Recall | 95% | // | F1 | 0.92 | ``` -------------------------------- ### Basic PDF Text Extraction Example (Rust) Source: https://github.com/yfedoseev/pdf_oxide/blob/main/CONTRIBUTING.md A simple Rust example demonstrating how to open a PDF file, extract text from the first page, and print it to the console. This serves as a basic usage example for the `pdf_oxide` library. It requires a PDF file named `paper.pdf` in the execution directory. ```rust // examples/basic.rs use pdf_oxide::PdfDocument; fn main() -> Result<(), Box> { let doc = PdfDocument::open("paper.pdf")?; let text = doc.extract_text(0)?; println!("{}", text); Ok(()) } ``` -------------------------------- ### Rust API - Basic OCR Extraction Source: https://github.com/yfedoseev/pdf_oxide/blob/main/docs/ML_INTEGRATION.md Demonstrates how to extract plain text from a PDF using the Rust API, with automatic OCR detection enabled. This example requires the OCR feature to be built. ```rust use pdf_oxide::PdfDocument; #[cfg(feature = "ocr")] fn main() -> Result<(), Box> { let mut doc = PdfDocument::open("scanned.pdf")?; // Extract with automatic OCR detection let text = doc.to_plain_text(0)?; println!("{}", text); Ok(()) } #[cfg(not(feature = "ocr"))] fn main() { println!("Build with --features ocr to enable OCR"); } ``` -------------------------------- ### Installation: Install pdf_oxide using pip Source: https://github.com/yfedoseev/pdf_oxide/blob/main/python/README.md Provides the command to install the pdf_oxide Python package using pip. This is the standard method for installing Python packages and requires pip to be installed and configured. ```bash pip install pdf_oxide ``` -------------------------------- ### GitHub Actions Workflow for Code Quality (YAML) Source: https://github.com/yfedoseev/pdf_oxide/blob/main/LINTING.md A GitHub Actions workflow configuration that runs Rust formatting and Clippy checks, installs Ruff, and then runs Python formatting and linting checks. Ensures code quality in CI. ```yaml - name: Check Rust formatting run: cargo fmt --check - name: Run Clippy run: cargo clippy -- -D warnings - name: Install Ruff run: pip install ruff - name: Check Python formatting run: ruff format --check . - name: Run Python linter run: ruff check . ``` -------------------------------- ### Python: PDF Document Operations Source: https://github.com/yfedoseev/pdf_oxide/blob/main/RELEASE_NOTES_v0.1.0.md Illustrates basic PDF document operations using the pdf_oxide Python bindings. This example shows how to open a PDF, extract its plain text content, and convert the document to HTML and Markdown formats. It requires the 'pdf_oxide' Python package to be installed and assumes a 'document.pdf' file is available. ```python from pdf_oxide import PdfDocument # Open a PDF doc = PdfDocument.open("document.pdf") # Extract text text = doc.extract_text_simple() print(text) # Convert to HTML html = doc.to_html_all() # Convert to Markdown markdown = doc.to_markdown_all() ``` -------------------------------- ### Install pdf_oxide Base and OCR Source: https://github.com/yfedoseev/pdf_oxide/blob/main/RELEASE_NOTES_v0.2.0.md Installs the pdf_oxide Rust library. The base installation includes core functionality, while the `--features ocr` flag adds optional OCR support, which requires a model download and increases the package size. ```bash # Base library (no OCR) cargo add pdf_oxide # With OCR support cargo add pdf_oxide --features ocr ``` -------------------------------- ### Rust Linting Commands Source: https://github.com/yfedoseev/pdf_oxide/blob/main/docs/DEVELOPMENT_GUIDE.md Demonstrates how to use `cargo clippy` for code linting, including running with warnings disabled and enabling a strict pedantic mode. ```bash cargo clippy --all-targets -- -D warnings cargo clippy -- -W clippy::pedantic # Strict mode ``` -------------------------------- ### Rust - PDF Creation Source: https://github.com/yfedoseev/pdf_oxide/blob/main/README.md Demonstrates how to programmatically create PDF documents using the Rust `PdfBuilder`. ```APIDOC ## Rust - PDF Creation ### Description Build PDFs programmatically using `PdfBuilder` with various input formats. ### Method ```rust // Build PDFs programmatically use pdf_oxide::builder::{PdfBuilder, PdfPage, PdfText}; // Create a basic PDF with text and markdown content let pdf = PdfBuilder::new() .add_page(PdfPage::new(8.5, 11.0)) // Add a page with standard letter size .add_text("Document Title", 24.0, 72.0, 750.0) // Add title text .add_markdown("# Introduction\n\nThis is a **markdown** document.") // Add markdown content .add_text("Page 1 content here", 12.0, 72.0, 650.0) // Add more text .build()? // Finalize the PDF structure .save("output.pdf")?; // Save the PDF to a file // Convert Markdown file content to PDF let markdown_content = std::fs::read_to_string("document.md")?; let pdf = PdfBuilder::from_markdown(&markdown_content)? .save("document.pdf")?; // Convert HTML string content to PDF let html_content = "

Title

HTML content

"; let pdf = PdfBuilder::from_html(html_content)? .save("output.pdf")?; // Use templates for consistent styling let pdf = PdfBuilder::with_template("business_letter") .add_content("This is the letter content") .save("letter.pdf")?; ``` ### Parameters #### Query Parameters (Not applicable for this code example, as it focuses on builder methods.) #### Request Body (Not applicable for this code example.) ### Request Example (Refer to the code example above for a complete Rust script.) ### Response #### Success Response (200) - **PdfBuilder** - Returns a `PdfBuilder` instance allowing further modifications or saving. - **Result<(), std::io::Error>** - Indicates success or failure during the build and save process. #### Response Example (The code examples demonstrate saving the generated PDF to a file, e.g., `output.pdf`.) ``` -------------------------------- ### Build Rust Core Library for pdf_oxide Source: https://github.com/yfedoseev/pdf_oxide/blob/main/README.md Instructions to clone the pdf_oxide repository, build the release version of the core Rust library, and run tests and benchmarks. Requires Rust 1.70+. ```bash # Clone repository git clone https://github.com/yfedoseev/pdf_oxide cd pdf_oxide # Build cargo build --release # Run tests cargo test # Run benchmarks cargo bench ``` -------------------------------- ### Use Templates for PDF Creation (Rust) Source: https://github.com/yfedoseev/pdf_oxide/blob/main/README.md Illustrates using predefined templates for generating PDFs with consistent styling in Rust. The `with_template` method initializes the builder with a specified template, and content can then be added. This is a feature for v0.3.0. Requires the 'pdf_oxide' Rust crate. ```rust // Use templates for consistent styling use pdf_oxide::builder::PdfBuilder; let pdf = PdfBuilder::with_template("business_letter") .add_content("This is the letter content") .save("letter.pdf")?; // Assuming .save() is part of the builder chain or returns a savable object ``` -------------------------------- ### Build pdf_oxide without OCR (Rust & Python) Source: https://github.com/yfedoseev/pdf_oxide/blob/main/docs/ML_INTEGRATION.md Installs the pdf_oxide library. For Rust, it compiles the default release version. For Python, it installs the package without OCR capabilities. ```bash # Rust cargo build --release # Python pip install . ``` -------------------------------- ### Quick Start: PDF Document Operations in Python Source: https://github.com/yfedoseev/pdf_oxide/blob/main/python/README.md Demonstrates basic usage of the PdfDocument class for opening PDFs and extracting text in various formats like plain text, Markdown, and HTML. It shows how to specify output options such as reading order detection and heading detection. No external dependencies are required beyond the pdf_oxide library itself. ```python from pdf_oxide import PdfDocument # Open a PDF doc = PdfDocument("document.pdf") # Extract as plain text (with automatic reading order) text = doc.to_plain_text(0) print(text) # Convert to Markdown markdown = doc.to_markdown(0, detect_headings=True) with open("output.md", "w") as f: f.write(markdown) # Convert to HTML html = doc.to_html(0, preserve_layout=False) with open("output.html", "w") as f: f.write(html) ``` -------------------------------- ### Rust - Basic PDF Operations Source: https://github.com/yfedoseev/pdf_oxide/blob/main/README.md Demonstrates fundamental PDF operations in Rust using the pdf_oxide library. This includes opening a PDF, getting the page count, extracting text and images from a specific page, converting content to Markdown, retrieving document outlines (bookmarks), and accessing annotations. It requires the pdf_oxide crate. ```rust use pdf_oxide::PdfDocument; fn main() -> Result<(), Box> { // Open a PDF let mut doc = PdfDocument::open("paper.pdf")?; // Get page count println!("Pages: {}", doc.page_count()); // Extract text from first page let text = doc.extract_text(0)?; println!("{}", text); // Convert to Markdown (uses intelligent processing automatically) let markdown = doc.to_markdown(0, Default::default())?; // Extract images let images = doc.extract_images(0)?; println!("Found {} images", images.len()); // Get bookmarks/outline if let Some(outline) = doc.get_outline()? { for item in outline { println!("Bookmark: {}", item.title); } } // Get annotations let annotations = doc.get_annotations(0)?; for annot in annotations { if let Some(contents) = annot.contents { println!("Annotation: {}", contents); } } Ok(()) } ``` -------------------------------- ### Generate and Open API Documentation Source: https://github.com/yfedoseev/pdf_oxide/blob/main/README.md Commands to generate API documentation for the pdf_oxide project and automatically open it in a web browser. Supports generating documentation with all features enabled. ```bash # Generate and open docs cargo doc --open # With all features cargo doc --all-features --open ``` -------------------------------- ### Rust API Documentation Standards Source: https://github.com/yfedoseev/pdf_oxide/blob/main/docs/DEVELOPMENT_GUIDE.md Illustrates the required structure and content for documenting public APIs in Rust. This includes summary descriptions, argument and return value details, error conditions, and illustrative examples. ```rust /// Extracts text from a PDF page. /// /// # Arguments /// /// * `page_num` - Zero-based page index /// /// # Returns /// /// Extracted text with preserved reading order. /// /// # Errors /// /// - `Error::InvalidPdf` if page doesn't exist /// /// # Examples /// /// ``` /// # use pdf_oxide::PdfDocument; /// # fn main() -> Result<(), Box> { /// let mut doc = PdfDocument::open("sample.pdf")?; /// let text = doc.extract_text(0)?; /// # Ok(()) /// # } /// ``` pub fn extract_text(&mut self, page_num: u32) -> Result { // ... } ``` -------------------------------- ### Makefile Commands for Rust and Python (Bash) Source: https://github.com/yfedoseev/pdf_oxide/blob/main/LINTING.md Provides Makefile targets for common code quality tasks in Rust (formatting, linting, testing) and Python (formatting, linting). Includes combined checks. ```bash make fmt # Format Rust code make fmt-check # Check Rust formatting make lint # Run Clippy linter make test-rust # Run Rust tests make check # Run all Rust checks make fmt-py # Format Python code make fmt-py-check # Check Python formatting make lint-py # Run Ruff linter make lint-py-fix # Auto-fix linting issues make check-py # Run all Python checks make check-all # Run all checks (Rust + Python) ``` -------------------------------- ### Run Tests with OCR Feature (Bash) Source: https://github.com/yfedoseev/pdf_oxide/blob/main/docs/ML_INTEGRATION.md Demonstrates how to execute project tests while specifically enabling the 'ocr' feature. This ensures that tests covering OCR functionality are properly run. It also shows how to target tests within the 'ocr' module. ```bash # Test with OCR feature cargo test --features ocr # Test OCR-specific module cargo test --features ocr ocr:: ``` -------------------------------- ### Release Build with OCR Support (Bash) Source: https://github.com/yfedoseev/pdf_oxide/blob/main/docs/ML_INTEGRATION.md Command to create a release build that includes OCR support by enabling the 'ocr' feature. This increases binary size and RAM usage due to the inclusion of OCR models and ONNX Runtime, but provides full OCR functionality. ```bash cargo build --release --features ocr # Binary size: ~8MB # RAM usage: ~200-300MB (OCR models loaded on demand) # ONNX Runtime required (included with feature) ``` -------------------------------- ### Rust API - Advanced OCR Configuration Source: https://github.com/yfedoseev/pdf_oxide/blob/main/docs/ML_INTEGRATION.md Provides an example of advanced OCR usage in Rust, allowing explicit control over checking if OCR is needed and applying it. This function checks if a page requires OCR and either extracts native text or runs the OCR pipeline. ```rust #[cfg(feature = "ocr")] use pdf_oxide::ocr::{OcrEngine, needs_ocr}; #[cfg(feature = "ocr")] fn extract_with_control(path: &str) -> Result> { let mut doc = PdfDocument::open(path)?; // Check if page needs OCR if needs_ocr(&mut doc, 0)? { // Page is scanned - apply OCR let engine = OcrEngine::new()?; let text = pdf_oxide::ocr::ocr_page(&mut doc, 0, &engine, &Default::default())?; Ok(text) } else { // Page has native text - extract directly Ok(doc.to_plain_text(0)?) } } ``` -------------------------------- ### Lightweight Release Build (Bash) Source: https://github.com/yfedoseev/pdf_oxide/blob/main/docs/ML_INTEGRATION.md Command to create a release build of the project without the OCR feature. This results in a smaller binary size, lower RAM usage, and no external dependencies, making it suitable for environments where OCR is not required. ```bash cargo build --release # Binary size: ~5MB # RAM usage: ~50MB # No external dependencies ``` -------------------------------- ### Build with OCR Feature Enabled (Bash) Source: https://github.com/yfedoseev/pdf_oxide/blob/main/docs/ML_INTEGRATION.md Instructs how to build the project with the 'ocr' feature enabled using Cargo. This is necessary to include OCR capabilities in the final binary. It is also recommended for testing and benchmarking OCR functionality. ```bash cargo build --release --features ocr ``` -------------------------------- ### Run Rust Tests and Benchmarks Source: https://github.com/yfedoseev/pdf_oxide/blob/main/README.md Commands to execute all tests, specific test suites, and benchmarks for the pdf_oxide project using Cargo. Includes options for running with features and generating coverage reports. ```bash # Run all tests cargo test # Run with features cargo test --features ml # Run integration tests cargo test --test '*' # Run quality-specific tests cargo test quality # Run benchmarks cargo bench # Run performance benchmarks cargo bench --bench pdf_extraction_performance # Generate coverage report cargo install cargo-tarpaulin cargo tarpaulin --out Html ``` -------------------------------- ### Install pdf_oxide Python Bindings Source: https://github.com/yfedoseev/pdf_oxide/blob/main/RELEASE_NOTES_v0.2.0.md Installs the pdf_oxide library for Python projects using pip. This command fetches and installs the pre-compiled Python bindings for the pdf_oxide library. ```bash # Python bindings pip install pdf_oxide ``` -------------------------------- ### Run Benchmarks with OCR Feature (Bash) Source: https://github.com/yfedoseev/pdf_oxide/blob/main/docs/ML_INTEGRATION.md Provides commands to run project benchmarks, including those that utilize the 'ocr' feature. This is essential for performance testing of OCR-related functionalities. It also shows how to specifically target OCR performance benchmarks. ```bash # Benchmark with OCR cargo bench --features ocr # Specific OCR benchmark cargo bench --features ocr ocr_performance ``` -------------------------------- ### Install Python Packaging Tool Source: https://github.com/yfedoseev/pdf_oxide/blob/main/CONTRIBUTING.md Installs the 'maturin' tool, which is used for building and publishing Python packages written in Rust. This is a prerequisite for developing Python bindings for the Rust library. ```bash pip install maturin ``` -------------------------------- ### Basic Markdown Conversion with pdf_oxide Source: https://github.com/yfedoseev/pdf_oxide/blob/main/docs/MARKDOWN_CONVERTER_USAGE.md Demonstrates the fundamental usage of the MarkdownOutputConverter to convert text spans into Markdown format. It requires importing necessary components from pdf_oxide and setting up a default configuration. ```rust use pdf_oxide::pipeline::{OrderedTextSpan, TextPipelineConfig}; use pdf_oxide::pipeline::converters::{MarkdownOutputConverter, OutputConverter}; let converter = MarkdownOutputConverter::new(); let config = TextPipelineConfig::default(); let markdown = converter.convert(&spans, &config)?; println!("{}", markdown); ``` -------------------------------- ### Install Optional Rust Tools Source: https://github.com/yfedoseev/pdf_oxide/blob/main/CONTRIBUTING.md Installs optional command-line tools for Rust development, including cargo-watch for auto-reloading and cargo-tarpaulin for code coverage. These tools enhance the development and testing experience. ```bash cargo install cargo-watch ``` ```bash cargo install cargo-tarpaulin ``` -------------------------------- ### Rust: Implementing a Custom PDF Oxide Output Converter Source: https://github.com/yfedoseev/pdf_oxide/blob/main/docs/MARKDOWN_CONVERTER_USAGE.md Demonstrates how to create a custom output converter for PDF Oxide by implementing the `OutputConverter` trait. This involves defining the `convert`, `name`, and `mime_type` methods to process text spans and produce a custom output format. ```rust use pdf_oxide::pipeline::converters::OutputConverter; struct MyCustomMarkdown; impl OutputConverter for MyCustomMarkdown { fn convert(&self, spans: &[OrderedTextSpan], config: &TextPipelineConfig) -> Result { // Your implementation Ok("...".to_string()) } fn name(&self) -> &'static str { "MyCustomMarkdown" } fn mime_type(&self) -> &'static str { "text/markdown" } } ``` -------------------------------- ### Performance Profiling Source: https://github.com/yfedoseev/pdf_oxide/blob/main/docs/DEVELOPMENT_GUIDE.md Executes the `flamegraph` tool to profile benchmark performance and generates an SVG file that can be opened to visualize the results. ```bash cargo flamegraph --bench benchmark_name # Open flamegraph.svg ``` -------------------------------- ### Security and License Compliance Checks Source: https://github.com/yfedoseev/pdf_oxide/blob/main/docs/DEVELOPMENT_GUIDE.md Commands for checking project security vulnerabilities with `cargo audit` and ensuring license compliance with `cargo deny`. ```bash cargo audit # Check for vulnerabilities cargo deny check # License compliance ```