//! This example generates a minimal PDF document and writes it to the path that was passed as the //! first command-line argument. The size of the generated document should be 2.0 KB. //! //! You may have to adapt the `FONT_DIRS` and `DEFAULT_FONT_NAME` constants for your system so that //! these files exist: //! - `{FONT_DIR}/{DEFAULT_FONT_NAME}-Regular.ttf` //! - `{FONT_DIR}/{DEFAULT_FONT_NAME}-Bold.ttf` //! - `{FONT_DIR}/{DEFAULT_FONT_NAME}-Italic.ttf` //! - `{FONT_DIR}/{DEFAULT_FONT_NAME}-BoldItalic.ttf` //! //! These fonts must be metrically identical to the built-in PDF sans-serif font (Helvetica/Arial). use std::env; use rckive_genpdf::{elements, fonts}; const FONT_DIRS: &[&str] = &[ "/usr/share/fonts/liberation", "/usr/share/fonts/truetype/liberation", ]; const DEFAULT_FONT_NAME: &str = "LiberationSans"; fn main() { let args: Vec<_> = env::args().skip(1).collect(); if args.len() != 1 { panic!("Missing argument: output file"); } let output_file = &args[0]; let font_dir = FONT_DIRS .iter() .find(|path| std::path::Path::new(path).exists()) .expect("Could not find font directory"); let default_font = fonts::from_files(font_dir, DEFAULT_FONT_NAME, Some(fonts::Builtin::Helvetica)) .expect("Failed to load the default font family"); let mut doc = rckive_genpdf::Document::new(default_font); doc.set_title("rckive_genpdf Demo Document"); doc.set_minimal_conformance(); doc.set_line_spacing(1.25); doc.push(elements::Text::new("Minimal PDF document")); doc.render_to_file(output_file) .expect("Failed to write output file"); }