PHP code example of daniel-jorg-schuppelius / php-pdf-toolkit
1. Go to this page and download the library: Download daniel-jorg-schuppelius/php-pdf-toolkit library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
daniel-jorg-schuppelius / php-pdf-toolkit example snippets
use PDFToolkit\Registries\PDFReaderRegistry;
$registry = PDFReaderRegistry::getInstance();
$document = $registry->extractText('/path/to/file.pdf', [
'language' => 'deu+eng'
]);
if ($document->hasText()) {
echo $document->text;
echo "Reader: " . $document->reader;
echo "Scanned: " . ($document->isScanned ? 'Yes' : 'No');
}
// Ohne OCR-Fallback (schneller für Text-PDFs wie Kontoauszüge)
$document = $registry->extractTextOnly('/path/to/bankstatement.pdf', [
'layout' => false // Ohne Layout-Formatierung für bessere Regex-Extraktion
]);
use PDFToolkit\Registries\PDFWriterRegistry;
use PDFToolkit\Entities\PDFContent;
$registry = PDFWriterRegistry::getInstance();
// Simple: HTML to PDF
$registry->htmlToPdf('<h1>Hello World</h1><p>Content</p>', '/path/to/output.pdf');
// Simple: Text to PDF
$registry->textToPdf('Plain text content', '/path/to/output.pdf');
// Advanced: With metadata and options
$content = PDFContent::fromHtml($html, [
'title' => 'My Document',
'author' => 'John Doe',
'subject' => 'Example PDF'
]);
$registry->createPdf($content, '/path/to/output.pdf', [
'paper_size' => 'A4',
'orientation' => 'portrait',
'margins' => ['top' => 15, 'bottom' => 15, 'left' => 15, 'right' => 15]
]);
// Use specific writer
$registry->createPdf($content, '/path/to/output.pdf', [], 'dompdf');
// Get PDF as string (for download/streaming)
$pdfString = $registry->createPdfString($content);
header('Content-Type: application/pdf');
echo $pdfString;
// Readers
$readerRegistry = PDFReaderRegistry::getInstance();
foreach ($readerRegistry->getReaderInfo() as $info) {
echo "{$info['name']}: " . ($info['available'] ? '✓' : '✗') . "\n";
}
}
// Writers
$writerRegistry = PDFWriterRegistry::getInstance();
foreach ($writerRegistry->getWriterInfo() as $info) {
echo "{$info['name']}: " . ($info['available'] ? '✓' : '✗') . "\n";
}
bash
git clone --recurse-submodules https://github.com/Daniel-Jorg-Schuppelius/php-pdf-toolkit.git
text
PDFReaderRegistry → [Readers by Priority] → PDFDocument
↓
PDFToTextReader (10) # Fast, for text PDFs
PDFBoxReader (30) # Complex layouts
TesseractReader (50) # OCR for scans
OcrMyPDFReader (60) # Best OCR quality
PDFWriterRegistry → [Writers by Priority] → PDF File
↓
DompdfWriter (10) # HTML→PDF, pure PHP
TcpdfWriter (20) # Programmatic, pure PHP
WkhtmltopdfWriter (30) # Best HTML rendering