pub struct FlowLayout { /* private fields */ }Expand description
Automatic flow layout engine with page break support.
Manages a vertical cursor and a list of elements. When an element would overflow the current page’s bottom margin, a new page is created automatically.
§Example
use oxidize_pdf::{Document, Font};
use oxidize_pdf::layout::{FlowLayout, PageConfig};
let config = PageConfig::a4_with_margins(50.0, 50.0, 50.0, 50.0);
let mut layout = FlowLayout::new(config);
layout.add_text("Hello World", Font::Helvetica, 12.0);
layout.add_spacer(20.0);
layout.add_text("Second paragraph", Font::Helvetica, 12.0);
let mut doc = Document::new();
layout.build_into(&mut doc).unwrap();Implementations§
Source§impl FlowLayout
impl FlowLayout
Sourcepub fn new(config: PageConfig) -> Self
pub fn new(config: PageConfig) -> Self
Create a new FlowLayout with the given page configuration.
Sourcepub fn add_text(&mut self, text: &str, font: Font, font_size: f64) -> &mut Self
pub fn add_text(&mut self, text: &str, font: Font, font_size: f64) -> &mut Self
Add a text block. Uses default line_height of 1.2.
Sourcepub fn add_text_with_line_height(
&mut self,
text: &str,
font: Font,
font_size: f64,
line_height: f64,
) -> &mut Self
pub fn add_text_with_line_height( &mut self, text: &str, font: Font, font_size: f64, line_height: f64, ) -> &mut Self
Add a text block with custom line height.
Sourcepub fn add_spacer(&mut self, points: f64) -> &mut Self
pub fn add_spacer(&mut self, points: f64) -> &mut Self
Add vertical spacing in points.
Sourcepub fn add_image(
&mut self,
name: &str,
image: Arc<Image>,
max_width: f64,
max_height: f64,
) -> &mut Self
pub fn add_image( &mut self, name: &str, image: Arc<Image>, max_width: f64, max_height: f64, ) -> &mut Self
Add an image scaled to fit within max dimensions, left-aligned.
Wraps the image in Arc internally to avoid expensive buffer clones.
Sourcepub fn add_image_centered(
&mut self,
name: &str,
image: Arc<Image>,
max_width: f64,
max_height: f64,
) -> &mut Self
pub fn add_image_centered( &mut self, name: &str, image: Arc<Image>, max_width: f64, max_height: f64, ) -> &mut Self
Add an image scaled to fit within max dimensions, centered horizontally.
Wraps the image in Arc internally to avoid expensive buffer clones.
Sourcepub fn add_rich_text(&mut self, rich: RichText) -> &mut Self
pub fn add_rich_text(&mut self, rich: RichText) -> &mut Self
Add a single line of mixed-style text.
Sourcepub fn build_into(&self, doc: &mut Document) -> Result<()>
pub fn build_into(&self, doc: &mut Document) -> Result<()>
Build all elements into the document, creating pages as needed.
Limitation: Elements taller than PageConfig::usable_height() (e.g., a very
large table) will overflow past the bottom margin on a single page. They are not
split across pages.