wkhtmltopdf-rs
wkhtmltopdf-rs copied to clipboard
Add more safe builder methods for setting global and object settings
and figure out or report upstream other flags that don't seem to work (like outlineDepth
)
How would you pass other arguments to builder for wkhtmltopdf? Specifically I would like to pass --user-style-sheet
@anowell could you please confirm the desired way to add command line arguments that don't have a safe rust function.
Is using fn global_setting() the way to go about this?
let html = r##"<!DOCTYPE html><html><head><meta charset="utf-8"></head><body>Hello World</body></html>"##
unsafe {
let pdf_app = PdfApplication::new().expect("Failed to init PDF application");
let mut pdfout = pdf_app
.builder()
.global_setting("encoding","UTF-8")
.build_from_html(&html)
.expect("failed to build pdf");
}
I think global_settings
would only work for the fields defined on the PdfGlobal
object in the upstream project (also documented as Pdf Global Settings which includes the load.*
settings).
The web settings (e.g. encoding and stylesheet) appear to be on the PdfObject
. So while I haven't tested it, I'd expect to use: .object_setting("web.defaultEncoding", "UTF-8")
and .object_setting("web.userStyleSheet")
to accomplish the questions in this issue.
And if those are correct, it should be pretty trivial to add the safe builder methods:
pub fn default_encoding(&mut self, encoding: &str) -> &mut PdfBuilder {
self.os.insert("web.defaultEncoding", encoding.to_string().into());
self
}
pub fn user_style_sheet<P: AsRef<Path>>(&mut self, style_sheet: P) -> &mut PdfBuilder {
self.os.insert("web.userStyleSheet", style_sheet.as_ref().to_string().into());
self
}