oxidize_pdf/advanced_tables/mod.rs
1//! Advanced Table System for PDF Generation
2//!
3//! This module provides a comprehensive table system with advanced styling capabilities,
4//! complex headers, cell spanning, and professional formatting options.
5//!
6//! # Features
7//! - CSS-style cell styling (padding, borders, colors)
8//! - Complex headers with colspan/rowspan support
9//! - Alternating row colors and zebra striping
10//! - Flexible column width management
11//! - Nested tables support
12//! - Professional border styles (solid, dashed, dotted, double)
13//!
14//! # Example
15//! ```rust
16//! use oxidize_pdf::advanced_tables::{AdvancedTableBuilder, CellStyle};
17//! use oxidize_pdf::graphics::Color;
18//!
19//! let table = AdvancedTableBuilder::new()
20//! .add_column("Name", 150.0)
21//! .add_column("Age", 80.0)
22//! .add_column("Department", 200.0)
23//! .header_style(CellStyle::new()
24//! .background_color(Color::rgb(0.2, 0.4, 0.8))
25//! .text_color(Color::white())
26//! .font_size(14.0))
27//! .add_row(vec!["John Doe", "32", "Engineering"])
28//! .add_row(vec!["Jane Smith", "28", "Marketing"])
29//! .zebra_striping(Color::rgb(0.95, 0.95, 0.95))
30//! .build();
31//! ```
32
33mod cell_style;
34mod error;
35mod header_builder;
36mod table_builder;
37mod table_renderer;
38
39pub use cell_style::{BorderStyle, CellAlignment, CellStyle, Padding};
40pub use error::TableError;
41pub use header_builder::{HeaderBuilder, HeaderCell};
42pub use table_builder::{AdvancedTable, AdvancedTableBuilder, Column};
43pub use table_renderer::TableRenderer;
44
45use crate::error::PdfError;
46use crate::page::Page;
47
48/// Extension trait to add advanced table capabilities to PDF pages
49pub trait AdvancedTableExt {
50 /// Add an advanced table to the page at the specified position
51 fn add_advanced_table(
52 &mut self,
53 table: &AdvancedTable,
54 x: f64,
55 y: f64,
56 ) -> Result<f64, PdfError>;
57
58 /// Add an advanced table with automatic positioning (below last content)
59 fn add_advanced_table_auto(&mut self, table: &AdvancedTable) -> Result<f64, PdfError>;
60}
61
62impl AdvancedTableExt for Page {
63 fn add_advanced_table(
64 &mut self,
65 table: &AdvancedTable,
66 x: f64,
67 y: f64,
68 ) -> Result<f64, PdfError> {
69 let renderer = TableRenderer::new();
70 renderer.render_table(self, table, x, y)
71 }
72
73 fn add_advanced_table_auto(&mut self, table: &AdvancedTable) -> Result<f64, PdfError> {
74 // Position table with default positioning (top of page with margin)
75 let y = 750.0; // Default Y position near top of page
76 self.add_advanced_table(table, 50.0, y)
77 }
78}