Every example below is a standalone PHP script from the tc-lib-pdf repository, shipped with the PDF it produces. Each page embeds both, and links to the raw .pdf and the .phps source so they can be downloaded or read directly.
The scripts live in examples/ in the repository and run in place, because local file reads are restricted to an allowlist covering the package tree. Fonts must be generated first: see /docs/fonts/.
Table of contents
Start Here
- E006 minimal : the shortest script that produces a PDF, from font insertion to output.
- E076 absolute position : placing content at explicit coordinates alongside flowed content.
- E049 output targets integration : streaming to the browser, saving to a file, attaching to a message, all from the same raw bytes.
- E000 overview : a visual showcase of barcodes, QR codes, SVG, images, transparency, and gradients on a few pages.
Pages and Layout
- E004 page formats : named page formats, orientation, and arbitrary custom sizes.
- E005 header footer : page header, footer, and default page content.
- E019 page regions : text regions computed as equal columns from the content area.
- E048 page boxes prepress : MediaBox, CropBox, BleedBox, TrimBox, ArtBox, and their guides.
- E054 page groups numbering : page groups with Roman and Arabic numbering in one document.
- E055 page reorder booklet : page stack reordering and booklet imposition.
- E080 no write regions : rectangles that text and HTML flow route around.
Text and Typography
- E021 font stretch spacing : horizontal font stretching and character spacing.
- E022 cell borders : cell border styles and background fills.
- E023 cell alignment : horizontal and vertical alignment inside a text cell.
- E026 text rendering modes : fill, stroke, invisible, and the text clipping modes.
- E028 text hyphenation : soft hyphens and pattern hyphenation in HTML content.
- E039 text methods : text placement, spacing, and internal links.
- E064 custom hyphenation dictionary : loading a TeX hyphenation pattern file of your own.
- E071 gettextcell bbox metrics :
getTextCell()returning the operators plus the bounding box and metrics. - E074 text cell fit modes : truncating, stretching, or shrinking text that overflows its cell.
- E079 font stretch spacing matrix : stretch and spacing combined, driven from HTML and CSS.
- E083 text line wrap : line wrapping with offsets, indents, and hyphens.
Multilingual Text
- E003 rtl languages : Persian and Arabic right-to-left text with Joining_Type shaping.
- E046 pangrams : pangrams across scripts, useful for checking glyph coverage.
- E062 bidi mixed rtl ltr : Hebrew, Arabic, and Latin runs in one paragraph under UAX #9.
Fonts
- E002 font dump : dumping metrics and glyph coverage for the bundled font families.
- E052 custom fonts fallback : custom fonts with a fallback chain for missing glyphs.
- E068 font subset : subsetting an embedded font and what it does to file size.
- E072 import new font : converting a TTF or OTF file and using it in a document.
Full guide: /docs/fonts/.
HTML and CSS
- E018 html page span : an HTML block that flows across page breaks.
- E031 html features : selectors, pseudo-elements, floats, positioning, and the tag coverage.
- E032 html lists : ordered, unordered, and nested lists with their CSS list styles.
- E042 html form : form controls written as markup and mapped to AcroForm widgets.
- E043 html tables : structure tags, spanning cells, repeated headers, and border models.
- E069 html line height : CSS
line-heightin rendered HTML. - E073 css supported categories : the supported CSS categories, enumerated and rendered by the engine itself.
- E077 html table header px unit : repeated table headers sized in pixels across page breaks.
- E078 htmlcell page margins :
addHTMLCell()placed against and inside the page margins.
Full guide: /docs/html-css/.
Vector Graphics
- E025 transparency : constant alpha and the 16 PDF blend modes through
ExtGState. - E029 xobject template : reusable Form XObject templates.
- E030 svg : SVG paths, markers, text anchoring, and style inheritance.
- E033 geometric transformations : rotation, scaling, translation, skewing, and mirroring on a transformation stack.
- E034 color gradient mesh : axial and radial shadings, per-stop opacity, and Coons patch meshes.
- E035 registration marks : crop marks, registration marks, and colour bars for prepress.
- E036 graphic methods : lines, curves, arcs, polygons, star polygons, rounded rectangles, and arrows.
- E041 layers visibility : optional content groups with viewer-controlled visibility.
Colour
- E024 colors : CMYK, RGB, and grayscale colour output.
- E053 spot overprint proof : spot colours, tint ramps, overprint, and a proofing workflow.
Images
- E037 image methods : JPEG, PNG, and SVG placement, scaling, and aspect ratio handling.
- E038 image clipping : clipping paths and soft masks applied to images.
Barcodes
- E020 barcodes : every supported symbology drawn into a single document.
- E050 shipping label barcodes : a shipping label carrying Code 128 and QR Code.
Each of the 73 formats has its own page, giving the accepted input, worked examples and the rendered symbol: Linear, 2D, Postal. The shared settings are on Rendering Options and Output Formats.
Interactive Documents
- E027 annotations : every supported annotation subtype.
- E040 annotation form : AcroForm field widgets with appearance streams and default appearance resources.
- E044 toc index : bookmarks, table of contents, and index generation.
- E051 viewer preferences navigation : viewer preferences, page layout, named destinations, and links.
- E058 embedded files portfolio : file attachments with a typed
/AFRelationship, and portfolio documents. - E059 document javascript : document-level JavaScript actions on open, close, print, and save.
- E061 user rights reader extensions : Reader extension rights through a UR signature.
Standards and Conformance
- E001 invoice : a Factur-X 1.07 and ZUGFeRD 2.3 hybrid invoice embedded in PDF/A-3.
- E010 pdfx : the PDF/X conformance mode and what it changes in the output.
- E011 pdfx1a : PDF/X-1a, with forced CMYK and no transparency.
- E012 pdfx3 : PDF/X-3, which allows device-independent colour with an output intent.
- E013 pdfx4 : PDF/X-4, which allows live transparency and optional content.
- E014 pdfx5 : PDF/X-5, with external graphical content references.
- E015 pdfua : PDF/UA output auto-tagged from HTML.
- E016 pdfua1 : PDF/UA-1 (ISO 14289-1) auto-tagged from HTML.
- E017 pdfua2 : PDF/UA-2 (ISO 14289-2, PDF 2.0) auto-tagged from HTML.
- E063 manual tag tree : building the structure element tree by hand instead of from markup.
- E060 custom xmp metadata : custom XMP fragments at the five insertion points.
- E082 pdfa core fonts : PDF/A core font substitutes, glyph names, and
WinAnsiEncoding.
Full guide: /docs/standards/.
Encryption and Permissions
- E045 encryption and permissions : user and owner passwords, and the permission flags.
- E056 encryption cert recipients : public-key encryption for several certificate recipients.
Digital Signatures
- E007 signature basic : a PAdES B-B detached CMS signature.
- E008 signature timestamp : PAdES B-T, adding an RFC 3161 timestamp from a TSA.
- E009 signature ltv : PAdES B-LT, writing OCSP and CRL material into the
/DSSand/VRI. - E081 signature pades lta : PAdES B-LTA, adding an archive timestamp through
upgradeToLta(). - E057 multisignature incremental : several signatures applied across incremental revisions.
- E075 external signature injection :
prepare()andapply()for a key this process cannot reach. - E084 signature two phase cms : two-phase signing, where the key service sees only the DER signed attributes.
Full guide: /docs/digital-signatures/.
Importing Existing PDFs
- E065 import single page : importing one page of a source PDF as a Form XObject.
- E066 import document append : appending a whole document, or a selected page list.
- E067 import page region nup : box selection, alignment, clipping, and N-up composition.
- E070 default page content import : an imported page reused as the default content of every page.
Full guide: /docs/pdf-import/.
Remote and Local Resources
- E047 remote resources security :
fileOptionshost and path allowlists, TLS verification, and timeouts.
Full guide: /docs/remote-resources/.
- Example E000 : overview
- Example E001 : invoice
- Example E002 : font dump
- Example E003 : rtl languages
- Example E004 : page formats
- Example E005 : header footer
- Example E006 : minimal
- Example E007 : signature basic
- Example E008 : signature timestamp
- Example E009 : signature ltv
- Example E010 : pdfx
- Example E011 : pdfx1a
- Example E012 : pdfx3
- Example E013 : pdfx4
- Example E014 : pdfx5
- Example E015 : pdfua
- Example E016 : pdfua1
- Example E017 : pdfua2
- Example E018 : html page span
- Example E019 : page regions
- Example E020 : barcodes
- Example E021 : font stretch spacing
- Example E022 : cell borders
- Example E023 : cell alignment
- Example E024 : colors
- Example E025 : transparency
- Example E026 : text rendering modes
- Example E027 : annotations
- Example E028 : text hyphenation
- Example E029 : xobject template
- Example E030 : svg
- Example E031 : html features
- Example E032 : html lists
- Example E033 : geometric transformations
- Example E034 : color gradient mesh
- Example E035 : registration marks
- Example E036 : graphic methods
- Example E037 : image methods
- Example E038 : image clipping
- Example E039 : text methods
- Example E040 : annotation form
- Example E041 : layers visibility
- Example E042 : html form
- Example E043 : html tables
- Example E044 : toc index
- Example E045 : encryption and permissions
- Example E046 : pangrams
- Example E047 : remote resources security
- Example E048 : page boxes prepress
- Example E049 : output targets integration
- Example E050 : shipping label barcodes
- Example E051 : viewer preferences navigation
- Example E052 : custom fonts fallback
- Example E053 : spot overprint proof
- Example E054 : page groups numbering
- Example E055 : page reorder booklet
- Example E056 : encryption cert recipients
- Example E057 : multisignature incremental
- Example E058 : embedded files portfolio
- Example E059 : document javascript
- Example E060 : custom xmp metadata
- Example E061 : user rights reader extensions
- Example E062 : bidi mixed rtl ltr
- Example E063 : manual tag tree
- Example E064 : custom hyphenation dictionary
- Example E065 : import single page
- Example E066 : import document append
- Example E067 : import page region nup
- Example E068 : font subset
- Example E069 : html line height
- Example E070 : default page content import
- Example E071 : gettextcell bbox metrics
- Example E072 : import new font
- Example E073 : css supported categories
- Example E074 : text cell fit modes
- Example E075 : external signature injection
- Example E076 : absolute position
- Example E077 : html table header px unit
- Example E078 : htmlcell page margins
- Example E079 : font stretch spacing matrix
- Example E080 : no write regions
- Example E081 : signature pades lta
- Example E082 : pdfa core fonts
- Example E083 : text line wrap
- Example E084 : signature two phase cms