### Initialize Color instances Source: https://docs.rs/genpdfi/latest/genpdfi/style/enum.Color.html?search= Examples of creating Color instances using the available variants. ```rust let red = genpdfi::style::Color::Rgb(255, 0, 0); let cyan = genpdfi::style::Color::Cmyk(255, 0, 0, 0); let grey = genpdfi::style::Color::Greyscale(127); ``` -------------------------------- ### OrderedList::with_start(start: usize) Source: https://docs.rs/genpdfi/latest/genpdfi/elements/struct.OrderedList.html Creates a new OrderedList instance starting at a specific number. ```APIDOC ## OrderedList::with_start(start: usize) ### Description Creates a new instance of an ordered list that begins numbering at the provided integer. ### Parameters - **start** (usize) - Required - The starting number for the list. ``` -------------------------------- ### Creating and Configuring an Image Source: https://docs.rs/genpdfi/latest/genpdfi/elements/struct.Image.html?search= Example showing how to load an image from a path and apply alignment and scaling transformations. ```rust use std::convert::TryFrom; use genpdfi::elements; let image = elements::Image::from_path("examples/images/test_image.jpg") .expect("Failed to load test image") .with_alignment(genpdfi::Alignment::Center) // Center the image on the page. .with_scale(genpdfi::Scale::new(0.5, 2.0)); // Squeeze and then stretch upwards. ``` -------------------------------- ### FramedElement Usage Examples Source: https://docs.rs/genpdfi/latest/genpdfi/elements/struct.FramedElement.html?search= Examples showing how to create a framed element directly or using the Element trait extension. ```rust use genpdfi::elements; let p = elements::FramedElement::new( elements::Paragraph::new("text"), ); ``` ```rust use genpdfi::{elements, style, Element as _}; let p = elements::Paragraph::new("text").framed(style::LineStyle::new()); ``` -------------------------------- ### Creating StyledString Instances Source: https://docs.rs/genpdfi/latest/genpdfi/style/struct.StyledString.html Examples of how to instantiate a new StyledString with different style effects or colors. ```rust use genpdfi::style; let ss1 = style::StyledString::new("bold".to_owned(), style::Effect::Bold, None); let ss2 = style::StyledString::new("red".to_owned(), style::Color::Rgb(255, 0, 0), None); ``` -------------------------------- ### OrderedList::with_start Source: https://docs.rs/genpdfi/latest/genpdfi/elements/struct.OrderedList.html?search=std%3A%3Avec Creates a new ordered list instance starting at a specified number. ```APIDOC ### pub fn with_start(start: usize) -> OrderedList Creates a new ordered list with the given start number. ``` -------------------------------- ### OrderedList::with_start Source: https://docs.rs/genpdfi/latest/genpdfi/elements/struct.OrderedList.html?search= Creates a new ordered list instance with a custom starting number. ```APIDOC ## pub fn with_start(start: usize) -> OrderedList ### Description Creates a new ordered list with the given start number. ### Parameters - **start** (usize) - The starting number for the list. ``` -------------------------------- ### OrderedList::with_start Source: https://docs.rs/genpdfi/latest/genpdfi/elements/struct.OrderedList.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new ordered list instance with a custom starting number. ```APIDOC ## pub fn with_start(start: usize) -> OrderedList ### Description Creates a new ordered list with the given start number. ``` -------------------------------- ### OrderedList::with_start Source: https://docs.rs/genpdfi/latest/genpdfi/elements/struct.OrderedList.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new OrderedList instance starting at a specific number. ```APIDOC ## OrderedList::with_start ### Description Creates a new instance of an OrderedList that begins numbering at the provided integer. ### Signature `pub fn with_start(start: usize) -> OrderedList` ### Example ```rust use genpdfi::elements; let list = elements::OrderedList::with_start(5); ``` ``` -------------------------------- ### Creating and Populating an OrderedList Source: https://docs.rs/genpdfi/latest/genpdfi/elements/struct.OrderedList.html?search=u32+-%3E+bool Examples demonstrating how to initialize an OrderedList and add elements using setters or chained methods. ```rust use genpdfi::elements; let mut list = elements::OrderedList::new(); list.push(elements::Paragraph::new("first")); list.push(elements::Paragraph::new("second")); list.push(elements::Paragraph::new("third")); ``` ```rust use genpdfi::elements; let mut list = elements::OrderedList::with_start(5); list.push(elements::Paragraph::new("first")); list.push(elements::Paragraph::new("second")); list.push(elements::Paragraph::new("third")); ``` ```rust use genpdfi::elements; let list = elements::OrderedList::new() .element(elements::Paragraph::new("first")) .element(elements::Paragraph::new("second")) .element(elements::Paragraph::new("third")); ``` -------------------------------- ### Apply styles to elements Source: https://docs.rs/genpdfi/latest/genpdfi/elements/struct.StyledElement.html Examples showing how to apply styles using the constructor or the trait method. ```rust use genpdfi::{elements, style}; let p = elements::StyledElement::new( elements::Paragraph::new("text"), style::Effect::Bold, ); ``` ```rust use genpdfi::{elements, style, Element as _}; let p = elements::Paragraph::new("text") .styled(style::Effect::Bold); ``` -------------------------------- ### Create and configure TableLayout Source: https://docs.rs/genpdfi/latest/genpdfi/elements/struct.TableLayout.html?search= Examples demonstrating how to initialize a table and add rows using either setter methods or a chained builder pattern. ```rust use genpdfi::elements; let mut table = elements::TableLayout::new(vec![1, 1]); table.set_cell_decorator(elements::FrameCellDecorator::new(true, true, false)); let mut row = table.row(); row.push_element(elements::Paragraph::new("Cell 1")); row.push_element(elements::Paragraph::new("Cell 2")); row.push().expect("Invalid table row"); ``` ```rust use genpdfi::elements; let table = elements::TableLayout::new(vec![1, 1]) .row() .element(elements::Paragraph::new("Cell 1")) .element(elements::Paragraph::new("Cell 2")) .push() .expect("Invalid table row"); ``` -------------------------------- ### Create a new StyledCow Source: https://docs.rs/genpdfi/latest/genpdfi/style/struct.StyledCow.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Examples of initializing a StyledCow instance using different string types and style effects. ```rust use genpdfi::style; let ss1 = style::StyledCow::new("bold", style::Effect::Bold, None); let ss2 = style::StyledCow::new("red".to_owned(), style::Color::Rgb(255, 0, 0), None); ``` -------------------------------- ### Create and populate a LinearLayout Source: https://docs.rs/genpdfi/latest/genpdfi/elements/struct.LinearLayout.html Examples demonstrating how to initialize a vertical layout and add elements using either mutable push operations or a chained builder pattern. ```rust use genpdfi::elements; let mut layout = elements::LinearLayout::vertical(); layout.push(elements::Paragraph::new("Test1")); layout.push(elements::Paragraph::new("Test2")); ``` ```rust use genpdfi::elements; let layout = elements::LinearLayout::vertical() .element(elements::Paragraph::new("Test1")) .element(elements::Paragraph::new("Test2")); ``` -------------------------------- ### Create OrderedList with custom start number Source: https://docs.rs/genpdfi/latest/genpdfi/elements/struct.OrderedList.html?search= Initialize an ordered list starting from a specific integer value. ```rust use genpdfi::elements; let mut list = elements::OrderedList::with_start(5); list.push(elements::Paragraph::new("first")); list.push(elements::Paragraph::new("second")); list.push(elements::Paragraph::new("third")); ``` -------------------------------- ### Construct and Configure Paragraph Source: https://docs.rs/genpdfi/latest/genpdfi/elements/struct.Paragraph.html?search= Examples demonstrating how to build a paragraph using either mutable setters or a chained builder pattern. ```rust use genpdfi::{elements, style}; let mut p = elements::Paragraph::default(); p.push("This is an "); p.push_styled("important", style::Color::Rgb(255, 0, 0)); p.push(" message!"); p.set_alignment(genpdfi::Alignment::Center); ``` ```rust use genpdfi::{elements, style}; let p = elements::Paragraph::default() .string("This is an ") .styled_string("important", style::Color::Rgb(255, 0, 0)) .string(" message!") .aligned(genpdfi::Alignment::Center); ``` -------------------------------- ### PaddedElement Usage Examples Source: https://docs.rs/genpdfi/latest/genpdfi/elements/struct.PaddedElement.html Demonstrates how to create a padded element using the constructor or the trait method. ```rust use genpdfi::elements; let p = elements::PaddedElement::new( elements::Paragraph::new("text"), genpdfi::Margins::trbl(5, 2, 5, 10), ); ``` ```rust use genpdfi::{elements, Element as _}; let p = elements::Paragraph::new("text") .padded(genpdfi::Margins::trbl(5, 2, 5, 10)); ``` -------------------------------- ### OrderedList::new Source: https://docs.rs/genpdfi/latest/genpdfi/elements/struct.OrderedList.html?search= Creates a new ordered list instance starting at 1. ```APIDOC ## pub fn new() -> OrderedList ### Description Creates a new ordered list starting at 1. ``` -------------------------------- ### OrderedList::new Source: https://docs.rs/genpdfi/latest/genpdfi/elements/struct.OrderedList.html?search=std%3A%3Avec Creates a new ordered list instance starting at 1. ```APIDOC ### pub fn new() -> OrderedList Creates a new ordered list starting at 1. ``` -------------------------------- ### Example Usage of subset_font Source: https://docs.rs/genpdfi/latest/genpdfi/subsetting/fn.subset_font.html?search= Demonstrates how to read a font file, define the text to include, and generate a subset font. ```rust use genpdfi::subsetting::subset_font; let font_data = std::fs::read("font.ttf").unwrap(); let text = "Hello World ăâîșț"; // Romanian characters let subset = subset_font(&font_data, text).unwrap(); // subset now contains a smaller font with only the used glyphs assert!(subset.len() < font_data.len()); ``` -------------------------------- ### Populating TableLayoutRow Source: https://docs.rs/genpdfi/latest/genpdfi/elements/struct.TableLayoutRow.html?search= Examples demonstrating how to add elements to a table row using either explicit setters or a chained builder pattern. ```rust use genpdfi::elements; let mut table = elements::TableLayout::new(vec![1, 1]); let mut row = table.row(); row.push_element(elements::Paragraph::new("Cell 1")); row.push_element(elements::Paragraph::new("Cell 2")); row.push().expect("Invalid table row"); ``` ```rust use genpdfi::elements; let table = elements::TableLayout::new(vec![1, 1]) .row() .element(elements::Paragraph::new("Cell 1")) .element(elements::Paragraph::new("Cell 2")) .push() .expect("Invalid table row"); ``` -------------------------------- ### Create a custom bullet point Source: https://docs.rs/genpdfi/latest/genpdfi/elements/struct.BulletPoint.html?search= Example showing how to instantiate a BulletPoint with a custom bullet symbol using the with_bullet method. ```rust use genpdfi::elements; let layout = elements::LinearLayout::vertical() .element(elements::BulletPoint::new(elements::Paragraph::new("first")) .with_bullet("a)")) .element(elements::BulletPoint::new(elements::Paragraph::new("second")) .with_bullet("b)")); ``` -------------------------------- ### Create and render a PDF document Source: https://docs.rs/genpdfi/latest/genpdfi/struct.Document.html?search= Initializes a document with a font family, adds a paragraph, and renders the output to a file. ```rust // Load a font from the file system let font_family = genpdfi::fonts::from_files("./fonts", "LiberationSans", None) .expect("Failed to load font family"); // Create a document and set the default font family let mut doc = genpdfi::Document::new(font_family); doc.push(genpdfi::elements::Paragraph::new("Document content")); doc.render_to_file("output.pdf").expect("Failed to render document"); ``` -------------------------------- ### Text Formatting Properties Source: https://docs.rs/genpdfi/latest/genpdfi/style/struct.Style.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Methods to get and set text effects and font attributes. ```APIDOC ## Style::color(&self) -> Option Returns the outline color for this style, if set. ## Style::is_bold(&self) -> bool Returns whether the bold text effect is set. ## Style::set_bold(&mut self) Sets the bold effect for this style. ## Style::bold(self) -> Style Sets the bold effect for this style and returns it. ## Style::font_size(&self) -> u8 Returns the font size for this style in points, or 12 if no font size is set. ## Style::set_font_size(&mut self, font_size: u8) Sets the font size in points for this style. ## Style::with_font_size(self, font_size: u8) -> Style Sets the font size in points for this style and returns it. ``` -------------------------------- ### Get font metrics Source: https://docs.rs/genpdfi/latest/genpdfi/fonts/struct.Font.html?search=u32+-%3E+bool Methods to retrieve vertical metrics for a specific font size. ```rust pub fn get_line_height(&self, font_size: u8) -> Mm ``` ```rust pub fn glyph_height(&self, font_size: u8) -> Mm ``` ```rust pub fn ascent(&self, font_size: u8) -> Mm ``` ```rust pub fn descent(&self, font_size: u8) -> Mm ``` ```rust pub fn metrics(&self, font_size: u8) -> Metrics ``` -------------------------------- ### Create styled strings with genpdfi Source: https://docs.rs/genpdfi/latest/genpdfi/style/index.html Demonstrates initializing a Style object and applying it to StyledStr instances with specific formatting or colors. ```rust use genpdfi::style; let style = style::Style::new().bold(); let ss1 = style::StyledStr::new("bold", style, None); let ss2 = style::StyledStr::new("red", style::Color::Rgb(255, 0, 0), None); ``` -------------------------------- ### StyledCow::new Source: https://docs.rs/genpdfi/latest/genpdfi/style/struct.StyledCow.html Creates a new StyledCow instance from a string, style, and optional link. ```APIDOC ## pub fn new(s: impl Into>, style: impl Into