sghtmltopdf
An HTML-to-PDF renderer like wkhtmltopdf, written in Rust, that does not depend on Chromium, WebKit or Gecko.
It is aimed at documents that flow top to bottom with explicit breaks (invoices, receipts, reports) rather than at rendering arbitrary web pages.
- No browser process. One binary, or a library inside your own process.
- Fonts, including
@font-facewebfonts, are resolved during rendering, so there is nothing to wait for. - Streaming. HTML is read in chunks and each page is written out as soon as its layout is final.
- Page breaks are first class. CSS Fragmentation (
break-before,break-inside,orphans,widows) and@pageare implemented directly.
Command line
Most flags keep the name and meaning they have in wkhtmltopdf.
sghtmltopdf server starts an HTTP server that takes the same options as a query string.
See the option reference.
Library
Converter takes the same options as the command, which is the simplest way to embed it:
use ;
let converter = from_args?;
let html = open?;
let pdf = with_render_stack?;
write?;
# Ok::
Engine is the lower-level API: build EngineOptions, feed it HTML in chunks and finish it, with the PDF written to any Sink as each page is completed.
Rendering recurses as deep as the document, so run it on a thread with a large enough stack; with_render_stack does that for you.
Features
| Feature | Default | |
|---|---|---|
cli |
yes | The sghtmltopdf binary and Converter (clap) |
server |
yes | sghtmltopdf server (tiny_http) |
svg |
yes | SVG images embedded as vectors (svg2pdf) |
svg-text |
no | <text> inside SVG images |
For library use, default-features = false drops the command line and the HTTP server.
License
MIT