Crates.io | wkhtmltopdf |
lib.rs | wkhtmltopdf |
version | 0.4.0 |
source | src |
created_at | 2016-08-01 08:19:55.886924 |
updated_at | 2021-05-04 08:03:13.046263 |
description | High-level bindings to wkhtmltopdf |
homepage | |
repository | https://github.com/anowell/wkhtmltopdf-rs |
max_upload_size | |
id | 5853 |
size | 72,876 |
High-level Rust bindings for wkhtmltopdf. This is a wrapper around the low-level binding provided by libwkhtmltox-sys.
Resource | Link |
---|---|
Crate | |
Documentation | Cargo docs |
Upstream | wkhtmltopdf.org |
This crate aims to provide full configuration of wkhtmltopdf with safe, ergonomic Rust. Wkhtmltopdf has several non-obvious limitations (mostly caused by Qt). that make it very easy to cause undefined behavior with the C bindings. Two such limitations that greatly impact the API are:
This crate should make it impossible to break those rules in safe code. If you need parallel PDF generation, you will need to spawn/fork processes to do so. Such an abstraction would be a welcome addition to this crate.
Install wkhtmltopdf 0.12.3.
Note: This library using the libs
(shared objects) and includes
(headers)
for PDF generation instead of the wkhtmltopdf executable.
Basic usage looks like this:
let html = r#"<html><body><div>foo</div></body></html>"#;
let mut pdf_app = PdfApplication::new().expect("Failed to init PDF application");
let mut pdfout = pdf_app.builder()
.orientation(Orientation::Landscape)
.margin(Size::Inches(2))
.title("Awesome Foo")
.build_from_html(&html)
.expect("failed to build pdf");
pdfout.save("foo.pdf").expect("failed to save foo.pdf");
println!("generated PDF saved as: foo.pdf");
As long as the includes are installed (e.g. pdf.h
), then it's all cargo:
cargo build
cargo test
Note: tests have to be combined into a single test case because we can only init PdfApplication
once, and it is !Send
/!Sync
.
So the preference going forward will be to test with a variety of good examples.
Contributions welcome in the form of issue reports, feature requests, feedback, and/or pull request.