Expand description
A lightweight HTML to PDF renderer that does not depend on Chromium, WebKit or Gecko.
Feed HTML to an Engine in chunks and it writes the PDF bytes into a Sink.
use sghtmltopdf::{Engine, EngineOptions, MemorySink};
let mut engine = Engine::new(EngineOptions::default(), MemorySink::default());
engine.feed(b"<!DOCTYPE html><p>Hello</p>").unwrap();
let pdf: Vec<u8> = engine.finish().unwrap();With the cli feature (on by default), Converter runs a conversion configured by the
same options as the sghtmltopdf command, which is the simplest entry point for language
bindings.
Rendering recurses as deep as the document, so run it on a thread with enough stack,
for example through with_render_stack.
§Stability
The items re-exported at the crate root are the public API and follow semver. The modules are reachable only so that the CLI, the tests and the Ruby binding can use the internals; they are hidden from the documentation and may change in any release.
Structs§
- Buffered
Sink - A Sink that calls
on_partevery timethresholdbytes have accumulated. - Content
Options - Options changing the behaviour of what is rendered.
- Converter
- A conversion configured by the same options as the
sghtmltopdfcommand. - Document
Metadata - The document metadata written to the PDF Info dictionary.
- Edge
Sizes - A length for each of the four sides, such as a margin, in CSS px.
- Engine
- The rendering engine: feed it HTML and it writes the PDF into a
Sink. - Engine
Options - The initialisation options for
Engine. - File
Sink - A Sink that writes the PDF to a file.
- Font
Spec - An explicit font specification, the equivalent of
--font. - Header
Footer Html - The
--header-html/--footer-htmltemplates. - Header
Footer Placeholders - The text that stands for a page number in
HeaderFooterHtmltemplates. - Local
Access - The permission settings for local file references.
- Memory
Sink - A Sink that collects the PDF in memory.
Sink::finishreturns the bytes. - Page
Settings - The page size and margins. The default is A4 with a 1in (96px) margin on every side.
- Page
Size - A page size in CSS px (1px = 1/96in), as
@page { size }gives it. - PdfOutput
Options - PDF output options.
- Stdout
Sink - A Sink that writes the PDF to standard output.
- TocHeading
- One heading listed in the table of contents.
- TocSettings
- The table-of-contents (
--toc) settings.
Enums§
- Convert
Error - Errors from the command and from
Converter, classified by cause. - Engine
Error - The errors
Enginereturns.Eis the error type of theSink. - Generic
Family - The CSS generic family names whose concrete font can be given explicitly.
cursive/fantasyare not covered. - Mode
- Selects batch or streaming processing.
Constants§
- DEFAULT_
SCALE - The default factor converting CSS px to PDF pt (at 96dpi,
72 / 96). - MULTIPART_
MIN_ PART_ SIZE - Minimum part size for a multipart upload (all but the last part).
- STACK_
SIZE - Stack size allocated for the thread that runs rendering.
Traits§
Functions§
- with_
render_ stack - Run
fon a thread with aSTACK_SIZEstack and return its result.
Type Aliases§
- TocHtml
Builder - The function building the table-of-contents HTML from the list of headings.