Installation
Pop PDF installs as a single Composer package, with no separate binary or system library to set up and no config file to publish afterward.
Composer Require#
composer require popphp/pop-pdf
That resolves the current stable release, pulls in Pop PDF's four dependencies — pop-color,
pop-css, pop-dom and pop-utils — alongside it, and adds an entry to your project's
composer.json:
{
"require": {
"popphp/pop-pdf": "^6.0.11"
}
}
It should be noted that version 6 is a major upgrade from the previous versions. Most of the upgrades in v6 are new features, but any project using version 5 or older should take care to ensure there are no backwards compatibility breaks in your existing codebase. Please see the BC-BREAKS.md for more info.
PHP Version#
Pop PDF requires PHP 8.4.0 or later. There is nothing further to configure for the language runtime
itself — no php.ini setting Pop PDF depends on beyond having the extensions covered below.
Suggested Extensions#
ext-gd— for reading images before they go on a page.ext-imagick— for rasterizing existing PDF pages to image files.ext-iconv— converting text between character encodings.ext-mbstring— working with multi-byte strings.ext-zlib— compressing document output and decompressing streams read back in.
Quick Test#
One script that builds a one-page document and confirms the file landed on disk:
require __DIR__ . '/vendor/autoload.php';
use Pop\Pdf\Pdf;
use Pop\Pdf\Document;
use Pop\Pdf\Document\Font;
use Pop\Pdf\Document\Page;
$document = new Document();
$document->addFont(Font::ARIAL);
$page = $document->createPage(Page::LETTER);
$page->addText('It works.', Font::ARIAL, x: 50, y: 742);
Pdf::writeToFile($document, filename: __DIR__ . '/test.pdf');
echo file_exists(__DIR__ . '/test.pdf') ? "PDF written\n" : "missing\n";
See Also#
- Quickstart — five short scripts covering text, HTML, images, importing a file and extracting text back out