Layers, annotations and printing
editRender for printing
Intent says what the image is for: PdfRenderIntent.View (the default) for a screen, PdfRenderIntent.Print for paper, and PdfRenderIntent.Export for another format. It selects:
- the annotations: for printing, only the annotations with the Print flag are drawn, NoView ones included; for the others, the annotations without the NoView flag. Hidden annotations are never drawn;
- the layers whose usage the document sets for the event (the
/ASentries of its configuration): a watermark layer shown only on paper, or a layer of comments hidden when printed.
var options = new PdfRenderOptions
{
// The annotations and the layers meant for printing
Intent = PdfRenderIntent.Print,
// A layer turned off, whatever the document says
OptionalContentGroupStates = new Dictionary<string, bool>(StringComparer.Ordinal) { ["Watermark"] = false },
Dpi = 300,
};
using var image = page.Render(options);Choose the layers
The layers of a document are its optional content groups. Which are visible is set by a configuration: the default one, or one of the alternate configurations the document lists, which OptionalContentConfiguration selects by its name (an unknown name keeps the default configuration). Then OptionalContentGroupStates turns groups on or off by their name, whatever the configuration says; every group of a name is changed.
The configuration also has intents: a group whose intent is not one of them (a group for design, in a configuration for viewing) hides nothing. A group with a zoom usage is visible at the magnifications it gives, 100% being 72 dpi.
Annotations
With RenderAnnotations, the normal appearance of each annotation is drawn over the page:
- the appearance is fitted to the rectangle of the annotation, and drawn as a transparency group when it is one, its blend modes and soft masks isolated from the page as the group says;
- the constant opacity of the annotation (
/CA) applies to the appearance as a whole; - an annotation with the NoZoom flag keeps the size it has at 72 dpi, and one with the NoRotate flag is not turned with the page: both keep the upper-left corner of their rectangle in place.
An annotation without appearance gets one, generated from its entries: squares, circles, lines, polygons, polylines, ink, highlights (multiplied with the page), underlines, strikeouts and squiggly underlines, and the widgets of text, choice and check box fields (their background and border, and their value with the font and color of their default appearance). When the interactive form asks for new appearances (/NeedAppearances), the text and choice fields get a generated appearance even if they have one.
- The lines and polylines get their line endings (
/LE): squares, circles, diamonds, open and closed arrows, reversed arrows, butts and slashes, the closed ones filled with the interior color. - The comb text fields show one character centered in each of their cells.
- The text fields with a rich text value (
/RV) show its paragraphs, with the bold, italic, size, color and family of their styles (b,i,spanandpelements, and theirstyleattributes), in the standard 14 fonts. - The generated appearances remain simple: the text is not wrapped to the width of the field, and its alignment is estimated without the metrics of the font.