THotPDF.BuildLoadedPageSVG Method
Builds a standalone SVG document from the selected loaded PDF page
Declaration
function BuildLoadedPageSVG(PageIndex: Integer): AnsiString; overload;
function BuildLoadedPageSVG(PageIndex: Integer;
EmbedFonts: boolean): AnsiString; overload;
Unit
HPDFDoc
Parameters
| Name | Purpose |
|---|---|
PageIndex | Zero-based index of the loaded page |
EmbedFonts | True writes the glyphs of embedded fonts into the SVG as outlines, so the page looks the same where those fonts are not installed. False, and the overload without this parameter, leaves text to the viewer's installed fonts |
Return value
Returns the complete SVG document, or an empty string when the page cannot be exported
Usage notes
- Paths, decoded text, image XObjects, inline images, and recursive Form XObjects are emitted through the shared content-device interpreter; a Form XObject starts with the colors in effect where it is painted
- The canvas covers the visible part of the page, its
/CropBoxclipped to its/MediaBox(seeGetLoadedPageVisibleBox), turned by/Rotate; the lower-left corner of the box maps to the corner of the canvas even when the box does not start at the origin - Text is written as UTF-8 with one
xposition per character andxml:space="preserve", so spaces are kept; ligature glyphs expand to all the characters they stand for, and codes that XML 1.0 does not allow become U+FFFD - Text placement follows the full text matrix, including character and word spacing, horizontal scaling, rise, and
TJadjustments; render modes 0 to 2 fill, stroke or do both, mode 3 draws nothing, and the glyphs of text shown in modes 4 to 7 also become a clipping path from the end of the text object (ET) to the end of the graphics state - By default text uses installed fonts: the standard 14 families and their TrueType counterparts map to Helvetica or Arial, Times New Roman and Courier New, and other fonts are named by their family, also with spaces between its words (
MyriadPro, Myriad Pro), followed by a generic family taken from the font descriptor flags or the name. Bold and italic text getsfont-weightandfont-stylefrom the style part of the font name (Arial-BoldMT,Helvetica-Oblique,MinionPro-It) and from the font descriptor's weight, flags and italic angle - With
EmbedFontsset toTrue, text in a font whose TrueType or CFF program is embedded in the PDF is drawn from the program's glyph outlines. Each glyph is defined once as a<path>in<defs>and placed with<use>wherever it occurs, so repeated characters do not repeat their outlines; fill and stroke modes, line widths and text clipping follow the text as they do for SVG text. The text itself is kept as transparent SVG text on top of the outlines, so it can still be selected, searched and read by assistive technology - Fonts that are not embedded, Type 1 font programs (
/FontFile), vertical CJK writing, and runs with a code that has no glyph in the embedded program stay SVG text even withEmbedFontsset. The outlines make the file larger, often two to three times for text-heavy pages - Fill and stroke colors set in any color space (
DeviceGray,DeviceRGB,DeviceCMYK, ICCBased, calibrated, Lab, Indexed, Separation and DeviceN) are converted to sRGB as the page renderer converts them - Paths filled with a tiling pattern are filled with an SVG
<pattern>that repeats the pattern cell everyXStepandYStep, clipped to its/BBox; uncolored patterns paint the cell in the color given with the pattern. Paths filled with a shading pattern get the gradient or mesh of its shading, clipped to the path. The pattern matrix is applied in the space of the page, or of the form that uses the pattern. Strokes with a pattern use its color, black for colored patterns - Type 2 axial and Type 3 radial shadings use SVG gradients with bounded sampled stops; an end that
Extenddoes not extend stays unpainted, as in PDF - Type 4 through Type 7 mesh shadings use a bounded transparent PNG data URI with a maximum of 16 million pixels
- Inline images are decoded through the same loaded-document image path and embedded as PNG data URIs
- Image masks, inline ones included, become PNG images in the current fill color that are transparent where nothing is painted;
/SMaskand/Maskstencils give the image an alpha channel, at the mask's resolution when it is finer than the image. Color-key/Maskarrays make the matching pixels transparent for Flate, LZW and unfiltered images WandW*clipping paths become SVG<clipPath>elements that end with the graphics state they were set in; Form XObjects are clipped to their/BBox, and axial and radial shadings to theirs- Text in Type 3 fonts is drawn with the font's glyph procedures, placed through its
/FontMatrix, instead of as SVG text; glyphs that start withd1paint in the current fill color. Type 3 glyphs do not add to the clipping path of render modes 4 to 7 - The
Backgroundcolor of a shading fills the area of a shading pattern before the shading, so it shows wherever the shading does not paint; as in PDF, it is ignored when the shading is painted withsh - Type 1 function-based shadings are sampled over their
Domaininto a PNG data URI of up to 256 by 256 samples, placed through the shading'sMatrix; the viewer smooths it when it is scaled