Graph PDF PDF command¶
The PDF component exports a single-page PDF 1.4 document directly, without Cairo, Ghostscript or another PDF library. It is available on graph, barchart, stripchart and polar widgets, independently of the screen renderer. Each widget has its own PDF settings, separate from SVG and PostScript settings.
Generating PDF¶
.g pdf output plot.pdf
.g pdf output plot.pdf -width 16c -height 12c -decorations yes
set bytes [.g pdf output]
set channel [open copy.pdf wb]
puts -nonewline $channel $bytes
close $channel
Without a filename, output returns a binary Tcl bytearray. File output uses binary translation. Prefix a
dash-leading filename with a directory, for example ./-plot.pdf. There is no -- separator. Rendering and
text validation finish before the destination is opened. An I/O failure can still leave a partial file.
PDF options¶
Option |
Default |
Description |
|---|---|---|
|
|
Non-negative width, in pixels or Tk screen-distance units. Zero uses the graph width. |
|
|
Non-negative height, in pixels or Tk screen-distance units. Zero uses the graph height. |
|
|
Include backgrounds and relief borders. False uses white backgrounds; labels, axes and symbols remain visible. |
|
|
Embed native fonts and Unicode mappings. False uses standard PDF fonts with Windows-1252 text. |
Dimensions are stored as integer pixels, like SVG options. The export lays out the graph at those dimensions and converts the resulting coordinates to PDF points using the display’s horizontal pixels-per-inch value (the scale used by Tk screen distances). One PDF point is 1/72 inch. Physical distances are therefore subject to Tk’s integer-pixel rounding. With zero dimensions, the current widget size is used, or its requested size before layout. The page fits the graph; there are no paper-size, printer-margin, landscape or multipage options in this version.
.g pdf configure -width 16c -height 12c
puts [.g pdf cget -width]
puts [.g pdf configure -decorations]
.g pdf configure -width 0 -height 0
Query descriptors contain {option name class default current}. PDF options do not use the Tk option
database. Invalid option/value lists leave settings unchanged. Validated output options remain configured
even if later rendering or file writing fails. Export restores screen geometry and does not resize the widget.
Supported content and limitations¶
Lines, error bars/bands, axes, grids, standard geometric symbols, arrows, polygon and arc markers, backgrounds, borders and legends use vector paths. Elliptical arcs use cubic Bezier approximations. Export uses full source geometry rather than screen-decimated traces. Solid fill opacity uses PDF transparency; stipples use vector tiling patterns. Image tiles and photo markers embed RGB images with soft masks for alpha. Resources are reused within each document. This first version writes uncompressed streams, so image-heavy PDFs can be large.
By default, text uses embedded fonts and Unicode mappings for searching and copying. Mathematical symbols,
Greek letters, superscripts and subscripts are supported when an installed font supplies their glyphs. Tk 9’s
per-character font actual query supplies the actual family, size and style, including fallback characters;
the standard Tk font command must be available. Character positions, advances, rotation and shadows retain
Tk’s layout. Font lookup uses GDI on Windows and Fontconfig on X11, independently of Cairo. Core-X11 legacy
fonts are matched to scalable equivalents; if needed, Fontconfig selects another outline font containing the
character. If a legacy X11 font measures a missing glyph as zero, PDF uses the fallback glyph advance to avoid
overlap. Such substitution, synthesized styles and platform font matching can differ from the exact screen
appearance.
TrueType outlines (including OpenType/TrueType and faces in collections) and ordinary name-keyed OpenType/CFF fonts are embedded. Complete font programs are stored once per document, without subsetting or compression, so PDFs can be larger than before. Font embedding permissions are respected. Variable fonts, CID-keyed CFF, CFF2 and color/bitmap-only fonts are not supported. A missing glyph or unsupported/restricted font reports an error before an output file is opened; unsupported characters are not silently replaced. PostScript font/color maps are not used. PDF remains version 1.4; Unicode page text does not require PDF 2.0.
To produce a smaller document without embedded font programs:
.g pdf output compact.pdf -embedfonts no
.g pdf configure -embedfonts yes
This mode substitutes standard Helvetica, Times or Courier faces, retaining bold/italic styles and Tk text
positions. The PDF viewer supplies the fonts, so appearance can differ. Text is limited to Windows-1252;
unsupported characters produce an error asking to enable -embedfonts, before opening the destination.
Superscript/subscript or mathematical characters outside that repertoire require embedding. This setting
is independent of SVG’s -embedfonts, which defaults to false.
Non-photo Tk images use the same black/white off-screen capture technique as SVG; custom image types with destination-dependent drawing may differ. Mapped window markers embed their current native pixels as raster images. Hidden or unmapped windows are omitted, and the exporter does not run the event loop. Process pending display work before exporting window markers. Native capture availability and visibility constraints apply.
Commands¶
cget¶
Queries a PDF option. Dimensions are returned as integer pixels.
cget option
Parameters
option:PDF configuration option.
Return value
Current option value.
configure¶
Queries or atomically updates PDF settings. See PDF options.
configure option configure option value ?option value ...?
Parameters
Return value
Option descriptors when querying, otherwise nothing.
output¶
Exports a single-page PDF. See Supported content and limitations.
output ?fileName? ?option value ...?
Parameters
fileName:Optional destination; prefix dash-leading names with ./.
option:Optional PDF configuration option.
value:New option value, retained after validation.
Return value
Binary PDF bytearray without a filename, otherwise nothing.
Copyright (c) George Yashin