Skip to main content

Crate wkhtmlapp

Crate wkhtmlapp 

Source
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 wkhtmltoimage binary (override the binary path with the WKHTMLTOIMG_CMD env var).
PdfApp
HTML-to-PDF converter backed by the wkhtmltopdf binary (override the binary path with the WKHTMLTOPDF_CMD env var).

Enums§

ImgFormat
Output image format (defaults to Jpg).
WkhtmlError
Library error type. ServiceErr covers setup/configuration problems, RenderingErr covers failures while running the wkhtmltox binary.
WkhtmlInput
Input source for a render: a local file path, a URL, or raw HTML (piped through stdin).