Repository navigation
tkPdf
Paul Squires edited this page Nov 24, 2026
·
1 revision
Home › All Categories › tkControls › tkPdf
Writes a print document as a PDF file.
Every page becomes a PDF page as it was recorded: shapes as vector paths, text as real text in the embedded font (searchable and copyable), images, gradients, clips and links. No PDF library is linked; the writer, its compression and its font reader are part of the module.
#import "vendor/tkControls/tkPdf"
using tkPdf
using tkPrint
using tkHost
using tkPaintIt imports tkPrint publicly.
dim as TK_PRINTDOC ptr doc = tkPrintDoc_Create( "Quarterly report" )
tkPrintDoc_SetPrintPageCallback( doc, @MyPage )
tkPrintDoc_Generate( doc )
if tkPrintDoc_ExportPdf( doc, "report.pdf" ) = false then print "could not write report.pdf"
print tkPrintDoc_Warnings( doc ) ' anything drawn as an image instead of text
tkPrintDoc_Destroy( doc )The toolchain's examples/tkControls/tkPrint/demo --pdf report.pdf writes a page with a tkChart, text and a table.
-
Text. Each font is embedded whole as a Type 0 font, with a
ToUnicodemap so text can be searched and copied. A run sits at the baseline and width it had on the page; the width is fitted with horizontal scaling (95–105%), so the PDF matches the preview. Synthetic bold and italic (a font file without that face) become stroked and slanted text. - Icons. Characters in the Private Use Area (icon fonts such as Fluent UI System Icons) are drawn as filled outlines from the font's glyphs. The icon font itself is not embedded.
-
Text drawn as an image (a warning says so):
- scripts that need shaping (Arabic, Hebrew, Indic, Thai and others) are drawn at 300 dpi as SDL_ttf renders them;
- so is text in a font that cannot be embedded: a CFF (
.otf) font, a face of a.ttccollection, or a font whose licence restricts embedding.
-
Shapes.
- Fills, strokes, dashes and rects are vector paths, as tkPaint drew them.
- Gradients are axial shadings; their colours' alpha is not kept.
- Transparency uses graphics states.
- Images are RGB with a soft mask when any pixel is not opaque.
-
Links are link annotations: a page destination (
tkPage_LinkToPage) or a URI (tkPage_Link). - Every stream is compressed (deflate) unless
bCompressis FALSE. The document's title, and the options' author and subject, go into the file's information.
type TKPDF_OPTIONS
bCompress as boolean = true ' FlateDecode every stream
author as ustring
subject as ustring
end type
type PDF_BUF ' a growing byte buffer: b(0 .. n - 1)
b(any) as ubyte
n as integer
end typefunction tkPrintDoc_ExportPdf( byval doc as TK_PRINTDOC ptr, byref path as ustring, byval pOpts as TKPDF_OPTIONS ptr = 0 ) as boolean
function tkPdf_Write( byval doc as TK_PRINTDOC ptr, byref outBuf as PDF_BUF, byval pOpts as TKPDF_OPTIONS ptr = 0 ) as boolean
sub tkPdf_Deflate( byval p as const ubyte ptr, byval n as integer, byref outBuf as PDF_BUF )tkPdf_Write builds the file in memory. tkPdf_Deflate appends a zlib stream of n bytes to a buffer.
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Home
- What Is tiko-lang
- Quick Start
- Installing on macOS
- Debugging
- Feature Index
- Compatibility
- FAQ
- AI Cheatsheet
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Match
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Array Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Time Zones
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- tiko test
- tiko doc
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing