Download the PHP package nadar/pdf-generator without Composer

On this page you can find all versions of the php package nadar/pdf-generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package pdf-generator

nadar/pdf-generator

Pixel-perfect template-overlay PDF generation on top of TCPDF and FPDI.

Why use this package?

Most projects re-implement the same TCPDF/FPDI glue for fixed-layout documents: stamp a designer's export, then place text, photos and codes at coordinates measured off the design. This package is that glue, typed and with strict defaults.

Requirements

Installation

Quick start

1. Describe your document once

2. Compile the fonts once

TCPDF cannot embed a .ttf directly, so every face is converted ahead of rendering. The cache must exist before the first render - commit it, or build it in CI.

If your settings class needs a booted framework, pass plain paths instead:

See docs/fonts.md for formats, .woff conversion and CI.

3. Render

A row's geometry - text, photo and code - is one Layout, so repeat() moves all of it and the loop carries no offset arithmetic:

Reproducing an existing design

The fastest way to a pixel-perfect overlay - whether the person doing it is new to the codebase or an AI agent - is to hand over two PDFs:

  1. The template, exactly as it will be stamped (page('template.pdf')).
  2. One filled example of the finished layout, with placeholder rows where content repeats.

The filled example is not decoration, it is a measurable spec: page box, font names and weights, sizes, x/y positions, row pitch and brand colours are all extractable from it, and your output can be diffed against it numerically until it matches. Add three lines of prose a PDF cannot express - the data shape you will pass in, what should happen on overflow, and where images come from - and the brief is complete.

Coordinates measured off a design are baselines, while TextBox::y is the top of the first line's cell. Say which you mean rather than correcting by hand:

...and read the result back without leaving PHP:

See docs/matching-a-template.md for the extraction commands and the calibration loop, and skills/pdf-template-calibration if you work with an AI agent.

Documentation

Guide
AGENTS.md The invariants, in 60 lines. Start here.
docs/matching-a-template.md Reproducing an existing design
docs/fonts.md Formats, conversion, the cache, multi-weight families, CI
docs/images-and-shapes.md Fit and clip modes, missing-image fallbacks
docs/codes-and-qr.md QR on artwork, error correction, barcodes
docs/repeated-slots-and-pagination.md Repeated rows and page breaks
docs/framework-integration.md Laravel, Symfony, serverless, custom TCPDF subclasses
docs/testing-generated-pdfs.md Metrics assertions, golden files, stream inspection

PdfGenerator API reference

Every method carries a full docblock; this is the inventory.

Document

Method Purpose
page(?string $template, string\|array\|null $format, ?string $orientation, int $templatePage, string $box) Add a page, optionally stamping a template and deriving its size/orientation.
stamp(string $template, int $sourcePage, string $box) Stamp a template onto the current page.
templateSize(string $template, int $page) Read a template's page size as a PageSize.
assertTemplateSize(string $template, float $w, float $h, float $tolerance) Fail loudly on a re-export at the wrong size (0.5 mm tolerance by default).
append(string $pdfBytes) / appendFile(string $path) Append every page of another PDF.
bytes() / save(string $path) Render the document. Both close it.

Text

Method Purpose
write(TextBox $box, string $text) Write into a typed slot, applying its overflow policy and anchor.
writeAll(iterable $boxes, array $data) Fill a Layout's text slots from keyed data; other slots are skipped.
writeText() / writeHtml() / writeRotated() Convenience writers without building a TextBox.
probe(TextBox $box, string $text) Resolve a box's geometry without drawing.
lastMetrics() The geometry of the most recent write().
measureText() / measureHtml() / lineCount() / fits() Measure text at a given width.
truncateToWidth(string $text, float $w, string $ellipsis) Cut at a word boundary to fit a width.

Graphics

Method Purpose
image(ImageBox $box, ?string $source, ?callable $onMissing) Place an image, scaled and clipped to its box.
fillShape(ImageBox $box, Color $color) Paint a slot's outline - the fill a placeholder: performs.
qr(QrBox $box, string $data) Draw a QR code; transparent, unpadded and reproducible by default.
qrAt(string $data, float $x, float $y, float $size, ...) The same, at explicit coordinates.
barcode1d(BarcodeBox $box, string $data) Draw a linear barcode.
barcode1dAt(string $data, Barcode1D $type, ...) The same, at explicit coordinates.
imageLoader() The image resolver, for inspecting or clearing its cache.

Metadata and diagnostics

Method Purpose
title() / subject() / keywords() / creator() / author() PDF metadata.
deterministic(int $timestamp, ?string $id) Pin timestamps and document id for byte-stable output.
debug(bool $enabled) Draw box outlines, baselines and resolved metrics.
debugGrid(float $step) Draw a measuring grid.
raw() The wrapped Fpdi, for anything not covered here.
__call() Proxy unknown methods to Fpdi; throws on a name it does not have.

Examples

Runnable with no assets - they generate their own templates and fall back to TCPDF's core fonts:

Licence notes

This package is MIT licensed. It depends on tecnickcom/tcpdf, which is LGPL-3.0-or-later, so consumers must comply with TCPDF's LGPL obligations.

One consequence is visible in the output: TCPDF writes its attribution ("Powered by TCPDF") at 1 pt into the bottom edge of the last page of every document. That line is TCPDF's, not this package's - it is not a defect, and the string is hex-obfuscated in TCPDF's source, which is why grepping for it finds nothing. See docs/framework-integration.md.

Security defaults

src/bootstrap.php sets K_TCPDF_CALLS_IN_HTML=false, which blocks TCPDF method calls embedded in HTML input - otherwise a code-execution path for user content - and K_TCPDF_THROW_EXCEPTION_ERROR=true, which turns TCPDF's internal die() into catchable exceptions. Both are guarded, so an application can define them differently beforehand.

Escape any user-supplied value going into an html: true box with Text::forHtmlCell().


All versions of pdf-generator with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
ext-mbstring Version *
ext-zlib Version *
tecnickcom/tcpdf Version 6.11.*
setasign/fpdi Version ^2.6
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package nadar/pdf-generator contains the following files

Loading the files please wait ...