PeachBrackets

PeachBrackets

HtmlDocument Class

An HTML document, laid out into pages and painted onto any Canvas: a PDF page, a bitmap, or one you implement.

public sealed class HtmlDocument : System.IDisposable

Inheritance System.Object → HtmlDocument

Implements System.IDisposable

Remarks

A document goes through three steps. LoadAsync(string, RenderContext, HtmlDocumentOptions) parses the HTML and cascades its style sheets; LayoutAsync(Canvas) breaks the content into pages; PaintPageAsync(int, Canvas) draws one page - its @page background and border, the content, footnotes and margin boxes - onto a canvas you give it. What the pages contain besides pixels (links, outline entries, form controls) is available from Annotations, so a consumer that writes a format with those concepts can carry them over.

Everything is measured in points (1/72 inch) except the canvases: a canvas is in the layout units of the RenderContext the document was loaded with, LayoutUnitsPerPoint units to the point, with its origin at the top-left corner of the sheet and y growing downward. A document is not thread safe.

Properties  
Annotations What the pages hold besides pixels: the links, the outline and the form controls, positioned on their pages in points.
ClippedText The words that were painted but cut off by an ancestor’s overflow clip, with how much of each showed. Read it after painting the pages to find out whether content was silently lost.
ContentArea The size of the area the content flows into: the sheet less its margins, in points. Known as soon as the document is loaded.
ContentExtent The extent the laid-out content actually occupies, in points. Wider than ContentArea when something does not fit across, which is how a consumer that wants to shrink the content to fit finds out by how much.
Language The language the document declares (<html lang>) or was given as the default, or null if there is none.
Metadata What the document says about itself - its title and <meta> elements - or null if it says nothing.
Pages The pages of the laid-out document, in order.
StructureTagSink Receives the logical structure of the content as it is painted, or null (the default) to record none. Set it before PaintPageAsync(int, Canvas); a consumer that writes a tagged format implements IStructureTagSink to build its structure tree.
Methods  
CreateAsync(DeclarativePage, HtmlDocumentOptions, StyleSheet) Makes a document from a page built in code instead of parsed from HTML, ready to be laid out.
Dispose() Releases the document’s cached images and layout state.
GetElementBounds(string) The bounds of the element with the given id on its page, in points from the top-left of the content area, or null if there is no such element.
LayoutAsync(Canvas) Breaks the document into pages. Call it once, after LoadAsync(string, RenderContext, HtmlDocumentOptions) and before anything that needs the pages.
LoadAsync(string, RenderContext, HtmlDocumentOptions) Parses html and cascades its style sheets, ready to be laid out.
PaintLinks(int, Canvas) Puts the links of one page on canvas - AddLink(Rect, string, IReadOnlyList<PaintPoint>) for a link to an address, AddDestinationLink(Rect, string, IReadOnlyList<PaintPoint>) for a link to a place in the document - and names on it the places on this page that links lead to (AddDestination(string, double)), so a canvas for a format with hyperlinks writes them. Call it for each page <b>after every page has been painted</b>: where a link is, if a transform moved what it covers, is only known once its page has been painted, and a link can lead to a page that comes later. A canvas with no hyperlinks ignores it.
PaintPageAsync(int, Canvas) Paints one page onto canvas.