Class HtmlConverter
- Namespace
- SoftZenPdf.Html
- Assembly
- SoftZenPdf.dll
Converts HTML and CSS documents to PDF, rendering them with SoftZenPdf's own layout engine (FlowDocument).
public sealed class HtmlConverter
- Inheritance
-
HtmlConverter
- Inherited Members
Examples
var converter = new HtmlConverter(new HtmlConverterOptions { BaseDirectory = "site" });
converter.Convert(File.ReadAllText("site/report.html")).Save("report.pdf");
Remarks
Supported: HTML5 documents (parsed forgivingly, as browsers do); CSS from style elements, linked style sheets,
@import and style attributes, with the cascade, inheritance, specificity, !important, print media
queries, @page size and margins, and @font-face with local TrueType fonts. Layout covers block and inline
flow, margins, padding, borders and backgrounds, fonts and text styles, text alignment and indentation, line height,
white space, lists with every common marker style, tables (column and row spans, header rows repeated on each page,
cell padding, borders and backgrounds), images (files and data: URIs), links, right-to-left text, page breaks and
bookmarks for headings.
Not supported: JavaScript, flexbox and grid (laid out as blocks), floats and positioning (laid out in normal flow), transforms, gradients, box shadows, rounded corners, SVG images, form controls and web fonts in WOFF formats. Such content is converted as well as possible and reported in Warnings.
Constructors
- HtmlConverter(HtmlConverterOptions?)
Creates a converter.
Properties
- Options
The options.
- Warnings
What the last conversion could not render exactly: unsupported CSS, missing images, characters without a font.
Methods
- Convert(string)
Converts HTML to a new PDF document.
- ConvertFile(string)
Converts an HTML file; relative paths in it are read from its folder unless BaseDirectory is set.
- RenderTo(PdfDocument, string)
Converts HTML and appends the pages to an existing document.
- ToFlowDocument(string)
Converts HTML to a FlowDocument, which can be adjusted before it is rendered.
- ToPdf(string)
Converts HTML to a new PDF document.