DrawPostScript

Vector graphics

Description

Parses and renders a PostScript or Encapsulated PostScript (EPS) vector, text and image program onto the selected page within the specified target rectangle

Syntax

Delphi

Function TPDFlib.DrawPostScript(Left, Top, Width, Height: Double; Const PostScriptSource: WideString; Options: Integer= 0): Integer;

Parameters

LeftHorizontal coordinate of the target bounding box origin
TopVertical coordinate of the target bounding box origin
WidthTarget width used to scale the PostScript %%BoundingBox; zero uses its natural width
HeightTarget height used to scale the PostScript %%BoundingBox; zero uses its natural height
PostScriptSourcePostScript or EPS program source text
OptionsReserved option flags; pass 0

Return values

1The supported PostScript instructions were converted and drawn onto the selected page
0Conversion was rejected; no partial content was appended to the page

Remarks

The bounded vector subset supports numeric arithmetic, numeric and procedure definitions, bind, numeric arrays for matrices and dashes, path construction and painting, clipping, graphics state save/restore, coordinate transformations, RGB/CMYK/Gray colors, operand-stack operations and repeat

General dictionary execution, arbitrary PostScript control flow and other unknown executable operators are rejected rather than silently omitted; this is a bounded import profile

LastErrorCode distinguishes 124 (PDFLIB_ERROR_POSTSCRIPT_INVALID, malformed input, empty painting, invalid dimensions or nonzero options), 538 (PDFLIB_ERROR_POSTSCRIPT_UNSUPPORTED, unsupported executable operator or definition), and 539 (PDFLIB_ERROR_POSTSCRIPT_BUDGET, exhausted work or size budget); a configured logger also receives the parser detail

Limits are 4 MiB source, 100000 shared token/repetition operations, 64 MiB cumulative procedure scan bytes, 16 MiB converted output, 4096 stack entries and numeric-array values, 1024 definitions, 16 procedure levels, 64 composite levels and 256 graphics-state saves

Coordinates and computed numeric values must be finite and have absolute value at most 10^12; negative dimensions are invalid, zero dimensions use the source bounding box, and Options must be zero

Bounded data sources and typed operands

The interpreter supports currentfile, string, length, filter, readstring, readhexstring and flushfile against the supplied source or finite string-backed filters; it does not open external files or network resources

ASCIIHexDecode, ASCII85Decode, RunLengthDecode and FlateDecode filters require valid explicit termination or a complete checksummed zlib member; chains are limited to four stages, and decoded bytes remain available through independent file cursors

readhexstring follows the PostScript rule of ignoring nonhexadecimal characters, while ASCIIHexDecode accepts only its defined whitespace and hexadecimal digits before the end marker; an odd final readhexstring nibble at file EOF is outside the qualified read profile

Read operations update named mutable buffers and preserve returned prefix aliases; buffers backing active filters cannot be overwritten, and filtered EOF never consumes following executable source bytes

Arrays evaluate their elements and can contain computed values and variables; typed dictionary operands, booleans, byte strings and file handles can be retained in definitions, and ASCII85 string literals are supported without executing their contents

Data limits are 32 MiB per decoded filter stream, 64 MiB cumulative decoded bytes, 268435456 data-work units, 512 MiB allocation reservation, 512 file handles and 1 MiB for an allocated string buffer; aggregate storage is bounded to 4096 objects, 100000 items, 4096 array elements and 128 dictionary pairs

Bounded images and stencils

Supported imaging includes five-operand image and imagemask, interleaved or planar colorimage, and ImageType 1 dictionaries with Width, Height, BitsPerComponent, ImageMatrix, Decode and DataSource; MultipleDataSources and Interpolate are optional

Old-style image always uses DeviceGray, colorimage selects DeviceGray, DeviceRGB or DeviceCMYK from its component count, dictionary image uses the current supported device color space, and imagemask paints with the current color

Samples support 1, 2, 4, 8 and 12 bits, with byte-padded rows; image matrices preserve top-down, bottom-up, rotated and skewed placement without changing the current path or point

Direct string sources repeat their bytes as needed, procedures return byte strings, and files remain finite; planar procedures run round-robin with equal chunk lengths and distinct buffers, while planar files require independent input streams

Data procedures cannot change graphics state or perform imaging, and cannot overwrite another active component buffer; malformed or unterminated filters fail the whole conversion, while premature finite-source EOF paints only complete available rows

Twelve-bit samples expand to sixteen bits with compensating Decode ranges that preserve normalized values; this requires PDF 1.5 or later and is rejected for archival or print-conformance modes and output versions explicitly locked below 1.5

Images are limited to 64 per import, 8192 pixels per dimension, 4194304 pixels each and 32 MiB of source samples per image; sample processing and allocation share the existing data budgets, and ASCIIHex-encoded inline output must fit the 16 MiB converted-content limit

Converted drawing is flushed before successful return, so an immediate save retains imported vectors, text and images; arbitrary PostScript dictionaries, executable font programs, nondevice color spaces, image types other than 1 and unsupported dictionary keys remain explicit errors

DSC boundary metadata

BoundingBox and HiResBoundingBox values are read only from actual top-level DSC comment lines, including deferred values in a trailer; high-resolution values take precedence, and matching bytes inside literal strings, procedures or consumed data do not redefine placement

Bounded fonts and text

Text import resolves the exact Standard-14 PostScript font names: Courier, Helvetica and Times families with their standard style names, Symbol and ZapfDingbats; unknown font programs are rejected without environment-dependent substitution

Supported operators include findfont, scalefont, makefont, setfont, currentfont, selectfont, show, stringwidth, ashow, widthshow, awidthshow, xshow, yshow, xyshow and glyphshow for names available in the qualified font encoding

Literal strings decode escaped delimiters, octal bytes and line continuations, and hexadecimal strings support whitespace and odd final nibbles; typed string, array and font definitions retain their values without executing string contents

Font matrices affect glyph orientation, size, translation and natural advances; additional spacing uses current user coordinates, while xshow, yshow and xyshow numeric arrays replace natural advances, including the displacement after the final glyph

Roman fonts preserve PostScript StandardEncoding rather than assuming WinAnsi, and saved resources include matching widths and Unicode maps; Symbol and ZapfDingbats retain their own character mappings

Font resources are collected during private conversion and registered after successful interpretation, leaving the selected library font unchanged; text requiring unembedded Standard-14 resources is rejected in PDF/A, PDF/X, PDF/UA or always-embed mode

Glyph widths, lookups and positioning consume the shared operation budget; unknown encodings, unqualified glyph widths, unencoded named glyphs, encoded numeric displacement strings, arbitrary font dictionaries and executable font programs remain outside this bounded profile

Current path and graphics state

Current paths and points survive gsave/grestore, clip, eoclip, rectfill and rectstroke; rectclip instead begins an empty current path after updating the clipping region, and path coordinates retain their original placement when later coordinate transformations change the user coordinate system

currentpoint returns coordinates in the active user space, and relative path operators require a defined current point; singular or numerically unqualified transforms are rejected instead of returning stale coordinates

Path construction is bounded to 100000 cumulative nodes, and replaying saved paths consumes the shared operation and output budgets; bounded path storage does not reset the operation limit across graphics saves or repetition

See also

ImportEPSFromFile, NewPostScriptXObject, DrawPostScriptXObject