Quick Start
Hello World (Level 2)
Section titled “Hello World (Level 2)”The simplest way to create a PDF. No PDF knowledge required:
use Phpdftk\Pdf\Writer\Pdf;
$pdf = new Pdf();$pdf->addHeading('Hello, World!', 1);$pdf->addText('This is my first PDF generated with phpdftk.');$pdf->save('hello.pdf');This gives you Letter-sized pages, 72pt margins, Helvetica 11pt, automatic word wrap, and auto-pagination.
Hello World (Level 1)
Section titled “Hello World (Level 1)”When you need precise control over coordinates and drawing:
use Phpdftk\Pdf\Writer\PdfWriter;use Phpdftk\Pdf\Core\Font\Type1Font;use Phpdftk\Pdf\Core\Font\StandardFont;
$writer = new PdfWriter();$page = $writer->addPage(612, 792);$font = $writer->addFont(new Type1Font(StandardFont::Helvetica));
$page->drawText('Hello, World!', 72, 720, $font, 24);
$writer->save('hello.pdf');Reading a PDF
Section titled “Reading a PDF”use Phpdftk\Pdf\Reader\PdfReader;
$pdf = PdfReader::fromFile('document.pdf');
echo "Pages: " . $pdf->getPageCount() . "\n";echo "Version: " . $pdf->getVersion() . "\n";
// Extract text$text = $pdf->extractText(0); // page index is 0-basedecho $text;Text search
Section titled “Text search”use Phpdftk\Pdf\Toolkit\TextExtractor;
$results = TextExtractor::open('contract.pdf')->search('indemnification');
echo $results->count() . " matches found\n";foreach ($results as $match) { echo "Page {$match->pageNumber}: {$match->text}\n";}Next steps
Section titled “Next steps”- API Levels — understand the three-level architecture
- Performance — benchmark comparisons
- Packages — the full package map