Expand description
Bindings to the wkhtmltopdf and wkhtmltoimage CLI tools.
Convert HTML (raw code, local file, or URL) to PDF or image. Each render
spawns the external binary, writes the output to a work dir with a unique
(UUID-prefixed) name, and returns the resulting std::path::PathBuf.
use wkhtmlapp::{PdfApp, WkhtmlInput};
let mut pdf_app = PdfApp::new()?;
pdf_app.set_arg("page-size", "A4")?;
let report = pdf_app.run(WkhtmlInput::Html("<h1>Demo</h1>"), "demo")?;
println!("PDF at {:?}", report);Environment variables: WKHTMLTOPDF_CMD / WKHTMLTOIMG_CMD (binary
paths) and WKHTMLAPP_WORK_DIR (output directory, defaults to the OS
temp dir). Output files are never deleted automatically — see
clear_work_dir().
Structs§
- App
- Convenience wrapper exposing both converters at once.
- Core
- Shared engine that spawns the wkhtmltox binary and manages the work dir.
- ImgApp
- HTML-to-image converter backed by the
wkhtmltoimagebinary (override the binary path with theWKHTMLTOIMG_CMDenv var). - PdfApp
- HTML-to-PDF converter backed by the
wkhtmltopdfbinary (override the binary path with theWKHTMLTOPDF_CMDenv var).
Enums§
- ImgFormat
- Output image format (defaults to
Jpg). - Wkhtml
Error - Library error type.
ServiceErrcovers setup/configuration problems,RenderingErrcovers failures while running the wkhtmltox binary. - Wkhtml
Input - Input source for a render: a local file path, a URL, or raw HTML (piped through stdin).