### Document Initialization and Usage Example Source: https://docs.rs/genpdfi/0.2.7/genpdfi/struct.Document.html Example demonstrating how to create a new PDF document, add a paragraph, and render it to a file. ```APIDOC ## §Example ```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"); ``` ``` -------------------------------- ### Example: Analyze Text Coverage and Missing Characters Source: https://docs.rs/genpdfi/0.2.7/src/genpdfi/fonts.rs.html Shows how to use `check_coverage` to get font support statistics for a string and how to check if all characters are supported or list the missing ones. ```rust # use genpdfi::fonts::FontData # let font_data = FontData::load("font.ttf", None).unwrap(); let coverage = font_data.check_coverage("Hello ăâîșț!"); println!("Coverage: {:.1}%", coverage.coverage_percent()); if !coverage.is_complete() { println!("Missing characters: {:?}", coverage.missing_chars()); } ``` -------------------------------- ### UnorderedList Examples Source: https://docs.rs/genpdfi/0.2.7/genpdfi/elements/struct.UnorderedList.html Illustrative examples of using the UnorderedList struct. ```APIDOC ## Examples ### Basic Usage ```rust use genpdfi::elements; let mut list = elements::UnorderedList::new(); list.push(elements::Paragraph::new("first")); list.push(elements::Paragraph::new("second")); list.push(elements::Paragraph::new("third")); ``` ### Custom Bullet Symbol ```rust use genpdfi::elements; let mut list = elements::UnorderedList::with_bullet("*"); list.push(elements::Paragraph::new("first")); list.push(elements::Paragraph::new("second")); list.push(elements::Paragraph::new("third")); ``` ### Chained Method Calls ```rust use genpdfi::elements; let list = elements::UnorderedList::new() .element(elements::Paragraph::new("first")) .element(elements::Paragraph::new("second")) .element(elements::Paragraph::new("third")); ``` ### Nested Lists ```rust use genpdfi::elements; let list = elements::UnorderedList::new() .element( elements::OrderedList::new() .element(elements::Paragraph::new("Sublist with bullet point")) ) .element( elements::LinearLayout::vertical() .element(elements::Paragraph::new("Sublist without bullet point:")) .element( elements::OrderedList::new() .element(elements::Paragraph::new("first")) .element(elements::Paragraph::new("second")) ) ); ``` ``` -------------------------------- ### Create StyledStr instances Source: https://docs.rs/genpdfi/0.2.7/genpdfi/style/struct.StyledStr.html Examples showing how to instantiate StyledStr with different style effects and colors. ```rust use genpdfi::style; let ss1 = style::StyledStr::new("bold", style::Effect::Bold, None); let ss2 = style::StyledStr::new("red", style::Color::Rgb(255, 0, 0), None); ``` -------------------------------- ### Create Example Bullet List Source: https://docs.rs/genpdfi/0.2.7/genpdfi/elements/struct.BulletPoint.html This example demonstrates how to create a vertical layout with two bullet points, each with a custom bullet symbol. It requires importing elements from the genpdfi crate. ```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)")); ``` -------------------------------- ### Initialize Color Instances Source: https://docs.rs/genpdfi/0.2.7/genpdfi/style/enum.Color.html Examples of creating Color instances using RGB, CMYK, and Greyscale 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); ``` -------------------------------- ### Create New OrderedList Source: https://docs.rs/genpdfi/0.2.7/src/genpdfi/elements.rs.html Initializes a new ordered list starting with the number 1. Use `with_start` for a different starting number. ```rust pub fn new() -> OrderedList { OrderedList::with_start(1) } ``` -------------------------------- ### Create OrderedList with Custom Start Source: https://docs.rs/genpdfi/0.2.7/src/genpdfi/elements.rs.html Creates a new ordered list that begins numbering from a specified `start` value. This is useful for continuing a list or starting with a non-default number. ```rust pub fn with_start(start: usize) -> OrderedList { OrderedList { layout: LinearLayout::vertical(), number: start, } } ``` -------------------------------- ### Create a new Paragraph with initial text Source: https://docs.rs/genpdfi/0.2.7/src/genpdfi/elements.rs.html Initialize a Paragraph with a single styled string. This is a convenient way to start a paragraph with some content. ```rust pub fn new(text: impl Into) -> Paragraph { Paragraph { text: vec![text.into()], ..Default::default() } } ``` -------------------------------- ### Create and populate a TableLayout Source: https://docs.rs/genpdfi/0.2.7/src/genpdfi/elements.rs.html Examples showing 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"); ``` -------------------------------- ### Populate TableLayoutRow Source: https://docs.rs/genpdfi/0.2.7/src/genpdfi/elements.rs.html Examples showing how to add elements to a table row using either setter methods 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 an OrderedList with a custom start number Source: https://docs.rs/genpdfi/0.2.7/genpdfi/elements/struct.OrderedList.html Use the `with_start()` constructor to create a new ordered list beginning with a specified number. Elements are added using `push()`. ```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")); ``` -------------------------------- ### Create an OrderedList with elements Source: https://docs.rs/genpdfi/0.2.7/genpdfi/elements/struct.OrderedList.html Use the `new()` constructor to create a new ordered list starting at 1. Elements can be added using the `push()` method. ```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")); ``` -------------------------------- ### Manage LineStyle Properties Source: https://docs.rs/genpdfi/0.2.7/src/genpdfi/style.rs.html Provides methods to get and set thickness and color for LineStyle instances. ```rust impl LineStyle { /// Creates a new line style with default values. pub fn new() -> LineStyle { LineStyle::default() } /// Sets the line thickness. /// /// Setting this to 0.0 will not hide the line, rather it’s a special value that tells PDF /// viewers to render the line as 1px regardless of the display size and zoom. pub fn set_thickness(&mut self, thickness: impl Into) { self.thickness = thickness.into(); } /// Sets the line thickness and returns the line style. /// /// Setting this to 0.0 will not hide the line, rather it’s a special value that tells PDF /// viewers to render the line as 1px regardless of the display size and zoom. pub fn with_thickness(mut self, thickness: impl Into) -> Self { self.set_thickness(thickness); self } /// Returns the line thickness. pub fn thickness(&self) -> Mm { self.thickness } /// Sets the line color. pub fn set_color(&mut self, color: Color) { self.color = color; } /// Sets the line color and returns the line style. pub fn with_color(mut self, color: Color) -> Self { self.set_color(color); self } /// Returns the line color. pub fn color(&self) -> Color { self.color } } ``` -------------------------------- ### FramedElement Usage Examples Source: https://docs.rs/genpdfi/0.2.7/genpdfi/elements/struct.FramedElement.html Demonstrates creating a framed element either by direct instantiation or by using the Element trait extension method. ```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()); ``` -------------------------------- ### Create a new Document with Default Font Family Source: https://docs.rs/genpdfi/0.2.7/src/genpdfi/lib.rs.html Initializes a new `Document` instance with a specified default font family. This is the starting point for building a PDF. ```rust let font_cache = fonts::FontCache::new(default_font_family); Document { root: elements::LinearLayout::vertical(), title: String::new(), context: Context::new(font_cache), style: style::Style::new(), paper_size: PaperSize::A4.into(), decorator: None, conformance: None, creation_date: None, modification_date: None, } ``` -------------------------------- ### Get First Layer Source: https://docs.rs/genpdfi/0.2.7/genpdfi/render/struct.Page.html Returns the first layer of the page. This method assumes at least one layer exists. ```rust pub fn first_layer(&self) -> Layer<'_> ``` -------------------------------- ### Example: Check for Romanian Character Support Source: https://docs.rs/genpdfi/0.2.7/src/genpdfi/fonts.rs.html Demonstrates how to use the `has_glyph` method to check if a font supports specific characters, like Romanian diacritics. ```rust # use genpdfi::fonts::FontData # let font_data = FontData::load("font.ttf", None).unwrap(); if font_data.has_glyph('ă') { println!("Font supports Romanian characters!"); } ``` -------------------------------- ### Example of Text Segmentation Source: https://docs.rs/genpdfi/0.2.7/src/genpdfi/fonts.rs.html Demonstrates how to use `segment_text` to break down a string into segments, each associated with a font from the fallback chain. Note that the actual font references in the output will depend on the loaded fonts. ```rust # use genpdfi::fonts::{FontData, FontFallbackChain}; # let primary = FontData::load("font.ttf", None).unwrap(); # let fallback = FontData::load("fallback.ttf", None).unwrap(); let chain = FontFallbackChain::new(primary).with_fallback(fallback); let segments = chain.segment_text("Hello мир!"); // Returns: [("Hello ", &primary_font), ("мир", &fallback_font), ("!", &primary_font)] ``` -------------------------------- ### Create an Unordered List with Custom Bullet Source: https://docs.rs/genpdfi/0.2.7/src/genpdfi/elements.rs.html This example demonstrates creating an unordered list with a custom bullet symbol. The specific code for setting the custom bullet is not shown but implied by the description. ```rust use genpdfi::elements; ``` -------------------------------- ### Get First Layer of Page Source: https://docs.rs/genpdfi/0.2.7/src/genpdfi/render.rs.html Returns an immutable reference to the first layer of the page. Assumes the page has at least one layer. ```rust pub fn first_layer(&self) -> Layer<'_> { Layer::new(self, self.layers.first()) } ``` -------------------------------- ### Example Usage of BulletPoint and Paragraph Source: https://docs.rs/genpdfi/0.2.7/src/genpdfi/elements.rs.html Demonstrates creating a vertical `LinearLayout` and adding two `BulletPoint` elements. Each `BulletPoint` contains a `Paragraph` and has a custom bullet symbol specified using `with_bullet`. ```rust 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)")); ``` -------------------------------- ### Get Next Layer or Add New Source: https://docs.rs/genpdfi/0.2.7/src/genpdfi/render.rs.html Returns the next layer in sequence. If the current layer is the last one, a new layer is created and returned. ```rust fn next_layer(&self, layer: &printpdf::PdfLayerReference) -> Layer<'_> { let layer = self.layers.next(layer).unwrap_or_else(|| { let layer = self .page .add_layer(format!("Layer {}", self.layers.len() + 1)); self.layers.push(layer) }); Layer::new(self, layer) } ``` -------------------------------- ### Create a new PageBreak element Source: https://docs.rs/genpdfi/0.2.7/genpdfi/elements/struct.PageBreak.html Use this to create a new page break element. No setup or imports are required beyond having the genpdfi crate available. ```rust let pb = genpdfi::elements::PageBreak::new(); ``` -------------------------------- ### Get First Page of PDF Document Source: https://docs.rs/genpdfi/0.2.7/src/genpdfi/render.rs.html Returns an immutable reference to the first page of the PDF document. Assumes the document has at least one page. ```rust pub fn first_page(&self) -> &Page { &self.pages[0] } ``` -------------------------------- ### Create and Render a PDF Document Source: https://docs.rs/genpdfi/0.2.7/genpdfi/struct.Document.html Load a font, create a new document, add a paragraph, and render to a file. Ensure fonts are loaded correctly and rendering is handled. ```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"); ``` -------------------------------- ### Create a new FontFallbackChain Source: https://docs.rs/genpdfi/0.2.7/src/genpdfi/fonts.rs.html Initializes a font fallback chain with a primary font. This is the starting point for managing multiple fonts to ensure character coverage in documents. ```rust pub fn new(primary: FontData) -> Self { Self { primary, fallbacks: Vec::new(), } } ``` -------------------------------- ### Get Document Font Cache Source: https://docs.rs/genpdfi/0.2.7/src/genpdfi/lib.rs.html Retrieves a reference to the font cache used by the document. This can be used to get the default font or query glyph metrics. ```rust &self.context.font_cache ``` -------------------------------- ### Create and populate a LinearLayout Source: https://docs.rs/genpdfi/0.2.7/genpdfi/elements/struct.LinearLayout.html Demonstrates how to initialize a vertical layout and add elements using either mutable push calls or method chaining. ```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 StyledString Instances Source: https://docs.rs/genpdfi/0.2.7/genpdfi/style/struct.StyledString.html Demonstrates how to create new StyledString instances with different styles (bold and color). Requires the `style` module to be in scope. ```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); ``` -------------------------------- ### TypeId Function Source: https://docs.rs/genpdfi/0.2.7/genpdfi/fonts/struct.FontData.html Gets the TypeId of an object. ```APIDOC ## `type_id(&self) -> TypeId` ### Description Gets the `TypeId` of `self`. ``` -------------------------------- ### Get Type ID Source: https://docs.rs/genpdfi/0.2.7/genpdfi/enum.PaperSize.html Retrieves the TypeId of a type. This is part of the Any trait implementation. ```rust impl Any for T where T: 'static + ?Sized { fn type_id(&self) -> TypeId } ``` -------------------------------- ### Style Manipulation and Properties Source: https://docs.rs/genpdfi/0.2.7/src/genpdfi/style.rs.html This section details methods for combining styles, setting and getting various style properties such as bold, italic, underline, strikethrough, font size, line spacing, and color. ```APIDOC ## Style API ### Description Provides methods to manage and query text styles. ### Methods #### Combining Styles - `pub fn and(mut self, style: impl Into