use rdocx::Document;
fn main() {
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}"),
}
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}"),
}
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}"),
}
}