rdocx 0.1.2

High-level API for reading, writing, and converting DOCX documents
Documentation
//! Generate a PDF from a simple document and from the feature showcase sample.
//!
//! Run with: cargo run --example generate_pdf

use rdocx::Document;

fn main() {
    // Test 1: Simple document
    let doc = Document::new();
    match doc.to_pdf() {
        Ok(bytes) => {
            std::fs::write("/tmp/rdocx_simple.pdf", &bytes).unwrap();
            println!("Simple PDF: {} bytes -> /tmp/rdocx_simple.pdf", bytes.len());
        }
        Err(e) => println!("Simple PDF failed: {e}"),
    }

    // Test 2: Document with content
    let mut doc = Document::new();
    doc.set_title("Test PDF Document");
    doc.set_author("rdocx-pdf");
    doc.add_paragraph("Chapter 1: Introduction")
        .style("Heading1");
    doc.add_paragraph(
        "This is a test document generated by rdocx and rendered to PDF. \
         It demonstrates text rendering with proper font shaping and pagination.",
    );
    doc.add_paragraph("Section 1.1").style("Heading2");
    doc.add_paragraph("More content in a sub-section.");

    {
        let mut table = doc.add_table(2, 3);
        for r in 0..2 {
            for c in 0..3 {
                if let Some(mut cell) = table.cell(r, c) {
                    cell.set_text(&format!("R{}C{}", r + 1, c + 1));
                }
            }
        }
    }

    doc.add_paragraph("After the table.");

    match doc.to_pdf() {
        Ok(bytes) => {
            std::fs::write("/tmp/rdocx_content.pdf", &bytes).unwrap();
            println!(
                "Content PDF: {} bytes -> /tmp/rdocx_content.pdf",
                bytes.len()
            );
        }
        Err(e) => println!("Content PDF failed: {e}"),
    }

    // Test 3: From feature_showcase.docx
    let showcase_path = concat!(
        env!("CARGO_MANIFEST_DIR"),
        "/../../samples/feature_showcase.docx"
    );
    match Document::open(showcase_path) {
        Ok(doc) => match doc.to_pdf() {
            Ok(bytes) => {
                std::fs::write("/tmp/rdocx_showcase.pdf", &bytes).unwrap();
                println!(
                    "Showcase PDF: {} bytes -> /tmp/rdocx_showcase.pdf",
                    bytes.len()
                );
            }
            Err(e) => println!("Showcase PDF failed: {e}"),
        },
        Err(e) => println!("Failed to open showcase: {e}"),
    }
}