| Crates.io | lopdf-table |
| lib.rs | lopdf-table |
| version | 0.2.1 |
| created_at | 2025-09-01 05:18:16.315845+00 |
| updated_at | 2025-09-01 14:11:02.230149+00 |
| description | A composable table drawing library for PDFs built on lopdf |
| homepage | |
| repository | https://github.com/fourbs-group/lopdf-table |
| max_upload_size | |
| id | 1819135 |
| size | 342,176 |
A composable table drawing library for PDFs built on lopdf.
Add to your Cargo.toml:
[dependencies]
lopdf-table = "0.1"
use lopdf::Document;
use lopdf_table::{Table, Row, Cell, TableDrawing};
// Create a document
let mut doc = Document::new();
// Create a table
let table = Table::new()
.add_row(Row::new(vec![
Cell::new("Name").bold(),
Cell::new("Age").bold(),
Cell::new("City").bold(),
]))
.add_row(Row::new(vec![
Cell::new("Alice"),
Cell::new("30"),
Cell::new("New York"),
]))
.add_row(Row::new(vec![
Cell::new("Bob"),
Cell::new("25"),
Cell::new("London"),
]))
.with_border(1.0);
// Draw the table on a page
doc.draw_table(page_id, table, (50.0, 750.0))?;
use lopdf_table::{Color, CellStyle, RowStyle, Alignment};
// Create header style
let header_style = RowStyle {
background_color: Some(Color::rgb(0.2, 0.3, 0.5)),
..Default::default()
};
let header_cell_style = CellStyle {
text_color: Color::white(),
bold: true,
alignment: Alignment::Center,
..Default::default()
};
// Apply styles
let table = Table::new()
.add_row(
Row::new(vec![
Cell::new("Product").with_style(header_cell_style.clone()),
Cell::new("Price").with_style(header_cell_style.clone()),
])
.with_style(header_style),
);
let table = Table::new()
.add_row(Row::new(vec![...]))
.with_column_widths(vec![100.0, 200.0, 150.0]);
See the examples/ directory for complete working examples:
basic_table.rs - Simple table with headers and datastyled_table.rs - Advanced styling with colors and formattingRun examples with:
cargo run --example basic_table
cargo run --example styled_table
MIT