DrawSVG

Vector graphics, SVG, Page content

Description

Draws SVG geometry inside a rectangular page area as native PDF paths without creating a raster image XObject; text elements render with the Standard 14 faces resolved from the font-family, font-weight and font-style attributes (serif keywords map to Times, monospace to Courier, everything else to Helvetica), honouring font-size and text-anchor and falling back to the fill colour or black

Syntax

Delphi

Function TPDFlib.DrawSVG(Left, Top, Width, Height: Double; Const SVG, AltText: WideString): Integer;

ActiveX

Function PDFlib::DrawSVG(Left As Double, Top As Double, Width As Double, Height As Double, SVG As String, AltText As String) As Long

DLL

int DLDrawSVG(int InstanceID, double Left, double Top, double Width, double Height, const wchar_t* SVG, const wchar_t* AltText);
int DLDrawSVGA(int InstanceID, double Left, double Top, double Width, double Height, const char* SVG, const char* AltText);

Parameters

LeftHorizontal position of the destination rectangle
TopTop edge of the destination rectangle
WidthDestination width in the current measurement units
HeightDestination height in the current measurement units
SVGSVG source containing the vector geometry
AltTextAccessible description used when automatic tagging opens a Figure structure element

Return values

Returns 1 when at least one supported vector shape is drawn, or 0 for empty, invalid, oversized, or unsupported-only input

Remarks

This entry uses permissive filter import; inspect GetSVGFilterCapabilitiesJSON for limits and GetLastSVGImportDiagnostics for actual degradation

The supported vector subset includes svg, g, defs, use, clipPath (including clip-rule="evenodd"), marker (marker-start, marker-mid, marker-end, and marker with orient="auto", orient="auto-start-reverse", or fixed angles), image (inline data:image/...;base64,... URIs, and local file paths only when DrawSVGEx is called with PDF_SVG_IMPORT_ALLOW_FILTER_IMAGE_FILES), all standard path commands, basic geometry, transforms, view-box alignment, presentation attributes, simple tag, .class, and #id CSS rules, inline styles, fill, stroke, dash, opacity, and the full CSS Color Module Level 3 148 named palette plus #RGB/#RGBA/#RRGGBB/#RRGGBBAA, rgb()/rgba(), and hsl()/hsla() notations

Quoted CSS values preserve embedded comment markers and escaped quotes; braces and semicolons inside strings do not split stylesheet rules or declarations, including inline styles

The finite print-media profile selects complete print, all, only print, only all and not screen queries, including comma-separated alternatives; other media types and queries containing feature conditions are skipped

Input is limited to 16 MiB, 100000 elements, and 128 nesting levels and does not load remote network resources

Gradient paint servers (linearGradient and radialGradient) render as clipped multi-stop vector gradients with objectBoundingBox and userSpaceOnUse coordinates, gradientTransform, and spreadMethod support. A gradient whose stops are opaque and which pads at its ends is written as a smooth PDF shading; stop opacity and the repeat and reflect spread methods are drawn as fine colour bands. Pattern fills honour patternUnits, patternContentUnits, the tile position and patternTransform. A mask becomes a luminance soft mask, so its shades of grey and gradients let the masked content through in proportion; masks with maskContentUnits="objectBoundingBox", and all masks in PDF/A-1 output, which does not allow transparency, are still applied as clipping paths. An element with a filter is drawn as an image at twice the page resolution, its coverage kept as a soft mask: feGaussianBlur, feOffset, feFlood, feColorMatrix (all four types), feComposite (including arithmetic) and feMerge are applied, with named results, SourceGraphic and SourceAlpha as inputs and linear RGB unless color-interpolation-filters="sRGB"; component transfer, morphology, convolution, displacement, the five SVG 1.1 blend modes and tiling are also supported with bounded work; continuous primitive subregions clip inputs and output and are retained with named results; unsupported primitives and invalid or unqualified parameters produce findings in GetLastSVGImportDiagnostics, and DrawSVGEx can reject them before committing page output. Text may be filled, stroked or both, takes text-decoration underline, overline and line-through, and follows a path through textPath with startOffset; a nested svg element places, clips and scales its content by its x, y, width, height, viewBox and preserveAspectRatio; switch draws only its first child whose systemLanguage includes English and that names no requiredExtensions; image honours preserveAspectRatio; text and nested tspan elements inherit CSS and presentation typography and fall back to embedded document fonts when PDF/A or PDF/X compliance is active

The DLL DLDrawSVGA variant accepts text according to the configured ANSI mode

An inline image that occurs several times in one drawing is embedded once, but every call embeds its own copy, so a drawing placed on many pages stores its images once per call; call DeduplicateResources before saving to merge the identical copies

Bounded diffuse and specular lighting

feDiffuseLighting and feSpecularLighting use the input alpha as a height map and accept exactly one distant, point or spot light; positions, surface heights and sampling distances use the primitive coordinate system

Surface normals use the SVG boundary-aware Sobel kernels, including corners and edges; a single-pixel axis contributes zero slope, diffuse output is opaque and specular alpha is the maximum of its computed premultiplied RGB channels

lighting-color defaults to white without automatic inheritance, supports currentColor and explicit inherit, and is converted into the selected filter working colour space; a parsed colour alpha component does not scale illumination

Positive kernelUnitLength values establish a bounded implicit sampling grid; the input is bilinearly reconstructed on that grid, Sobel lighting is evaluated there and the result is reconstructed at the original resolution, with a partial final sampling cell retaining its rectangle coverage

Point lights use the local surface height without distance attenuation, and coincident point/surface samples contribute zero illumination; spot lights support direction, focus and a limiting cone with four-point coverage sampling, while undefined spot directions are diagnosed

Specular exponents range from 1 through 128, nonnegative lighting constants and spot exponents are bounded to 1000000, coordinates to 1073741824 and kernel spacing to at least 1e-12; the implicit grid remains limited to 2048 pixels per dimension and consumes the shared buffer and work budgets

Missing or multiple lights, unsupported children, animation, invalid colours, invalid sampling and exhausted budgets produce findings with strict page-output rollback; finite grid reconstruction and four-point cone coverage remain approximations, and fullFidelity stays false

Deterministic turbulence

feTurbulence supports turbulence and fractalNoise, one or two nonnegative baseFrequency values, truncated signed seeds, octave accumulation and stitch or noStitch tile behaviour in the primitive coordinate system

The seeded gradient sequence and interpolation follow the SVG 1.1 algorithm; four independent channels are generated in the selected filter working colour space, then RGB is premultiplied by the generated alpha before entering the pipeline

Stitching adjusts base frequencies using relative frequency change and applies the specified octave lattice wrapping against the original primitive subregion, including when the stored result is cropped; it does not redefine the function as a globally periodic sampler outside that subregion

The bounded profile accepts 0 through 12 octaves, baseFrequency values through 1000000 and seed magnitudes through 9007199254740991; scaled lattice coordinates at every octave are limited to 1073741824, with numeric underflow, nonfinite values and undefined zero-length seeded gradients diagnosed

Zero octaves or zero frequencies produce transparent turbulence and straight RGBA channels of 0.5 for fractalNoise; shared work is reserved before output allocation, so larger images or octave counts can reach the work limit before the maximum dimension limit

Viewport geometry

Nested svg elements with zero width or height suppress their whole subtree while visible siblings are preserved; percentage circle radii use the normalised viewport diagonal, sqrt((width squared + height squared) / 2)

Bounded filter image resources

feImage accepts local SVG graphic fragments and base64 PNG or JPEG data URIs; href takes precedence over xlink:href, and standalone raster images use preserveAspectRatio with xMidYMid meet by default, none for stretching and slice for clipped filling

Local graphic fragments use referenced graphic content without moving or changing the source DOM; symbol references require a qualified viewBox, use graphs are bounded and cycles, executable or animated fragments and unsupported target types are diagnosed

Local image files require the explicit DrawSVGEx option PDF_SVG_IMPORT_ALLOW_FILTER_IMAGE_FILES (2), independently of strict filter rejection (1); the option is reapplied on every call, including cached SVG documents, and network URLs, UNC paths, device paths and external SVG documents are unsupported

The file is read once with a byte limit, and the approved bytes are passed to the decoder without a second filename read; nested image nodes inside referenced graphics follow the same policy, while ordinary image nodes outside feImage retain their existing resource behaviour

PNG preflight checks chunk extents, CRC, dimensions, transparency layout and exact bounded scanline expansion, including Adam7 passes; JPEG preflight checks baseline or progressive 8-bit frame structure, quantization and Huffman tables, scan headers and exact container termination, with final rendering delegated to the native codec

Encoded data is limited to 16 MiB per resource and 64 MiB per conversion, decoded scanline or component data to 64 MiB per conversion, dimensions to 8192 and total pixels to 4194304; PNG ICC expansion is limited to 4 MiB, container segments to 10000 and JPEG scans to 64

Active image references are limited to 32 levels, use graphs to 64 levels and 100000 visited nodes; source decoding and temporary storage also consume the shared filter work and 512 MiB buffer reservation

The native private SVG rasterizer preserves source alpha and uses bilinear image sampling with edge extension to prevent a transparent border from reducing the opacity of a scaled image; vector fragments still use the native finite-resolution renderer, and fullFidelity remains false

Continuous filter domains and sampling

Each primitive result has a continuous domain and a bounded local raster grid; referenced inputs are resampled in premultiplied working colour space, and coincident domains and grids preserve exact samples

The final result is mapped to the filter output using rectangle overlap coverage and premultiplied bilinear sampling; repeated identity operations do not multiply the same fractional boundary coverage again

Named results retain both stored domains and original subregion bounds, so tiling preserves fractional origins and periods and leaves samples outside stored input transparent; offset and convolution distances use the same local-grid coordinate model

Blur remains a three-box approximation and morphology uses local integer radii; bilinear finite-grid resampling is a bounded reconstruction model rather than a claim of resolution-independent analytic equivalence, and fullFidelity remains false

Local filter inheritance

Filters may reference another filter in the same SVG fragment with href or xlink:href; nearer attributes override referenced attributes, and the nearest filter with its own filter primitives supplies the complete primitive list

Resolution uses a private attribute view and leaves the source DOM and primitive ownership unchanged; inherited raster settings and working colour space remain effective across repeated rendering

References are local fragments only and do not load files or network resources; missing or non-filter targets, cycles, more than 32 chain nodes, more than 128 children or attributes per chain node, attribute values above 65536 UTF-16 units and references above 4096 UTF-16 units are diagnosed, with strict mode rejecting the import atomically