PHPackages                             imal-h/pdf-box - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. imal-h/pdf-box

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

imal-h/pdf-box
==============

The most advanced, driver-based PDF manipulation library for PHP v3.0. Supports Ghostscript, Chrome Headless (HTML to PDF), OpenSSL/FPDI (Signing), and PDFtk (Forms).

v3.2.0(5mo ago)60415.9k↓45.2%38[8 PRs](https://github.com/imalhasaranga/PDFLib/pulls)MITPHPPHP &gt;=8.1CI failing

Since Sep 5Pushed 2mo ago7 watchersCompare

[ Source](https://github.com/imalhasaranga/PDFLib)[ Packagist](https://packagist.org/packages/imal-h/pdf-box)[ Docs](https://github.com/imalhasaranga/PDFLib.git)[ RSS](/packages/imal-h-pdf-box/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (3)Dependencies (7)Versions (27)Used By (0)

[![Banner](readme_banner.jpg)](readme_banner.jpg)

Try out before you actually use it

```
docker run --pull always -p 9090:80 treineticprojects/demo_opensource:latest
```

PDFLib v3.1
===========

[](#pdflib-v31)

[![Issues](https://camo.githubusercontent.com/ce6cd301011d92852b65ddffbd01af67f024f04812a037189d0781a2b52b301f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f696d616c6861736172616e67612f5044464c69622e737667)](https://camo.githubusercontent.com/ce6cd301011d92852b65ddffbd01af67f024f04812a037189d0781a2b52b301f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f696d616c6861736172616e67612f5044464c69622e737667)[![Software License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE.md)[![Forks](https://camo.githubusercontent.com/1449a5dc15ac5b452333c69424657e1c4d7c87a6635c65371667039fad763b15/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f696d616c6861736172616e67612f5044464c69622e737667)](https://camo.githubusercontent.com/1449a5dc15ac5b452333c69424657e1c4d7c87a6635c65371667039fad763b15/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f696d616c6861736172616e67612f5044464c69622e737667)

**The most advanced, driver-based PDF manipulation library for PHP.**

PDFLib v3.1 is the mature, stable release of the new driver-based architecture. It allows you to switch between powerful backends like Ghostscript, PDFtk, OpenSSL, and Tesseract for different tasks, all under a single, beautiful fluent API.

👉 **[Try the Interactive Demo](demo/README.md)** | 📚 **[Read the Documentation](docs/index.md)**

---

🛡️ Stability Guarantee (v4.0 Ready)
-----------------------------------

[](#️-stability-guarantee-v40-ready)

**We take backward compatibility seriously.**

The v3.1 architecture introduces a strict separation between the API (Facade) and the Execution Logic (Drivers).

- **Zero Breaking Changes Promise**: This structure allows us to upgrade the underlying engine (e.g., adding Cloud/Async support in v4.0) **without** changing a single line of your application code.
- **Pipeline Pattern**: Operations like `rotate()` or `ocr()` are queued, decoupling your intent from immediate execution. Use PDFLib with confidence knowing the API is frozen and stable.

🚀 What's New in v3.1?
---------------------

[](#-whats-new-in-v31)

- **OCR Support**: Extract text from images and PDFs using Tesseract.
- **Redaction**: Securely blackout sensitive text.
- **Metadata**: Read/Write PDF metadata.
- **Laravel Wrapper**: First-party ServiceProvider and Facade.
- **Stateful Chaining**: Queue multiple operations (`->rotate()->watermark()->save()`).

📦 Requirements
--------------

[](#-requirements)

- **PHP** &gt;= 8.1
- **Ghostscript** &gt;= 9.16 (for GhostscriptDriver)
- **Google Chrome** or **Chromium** (for HTML to PDF)
- **pdftk** (PDF Toolkit) (for Form Filling)

> **Quick Start**: Run `./bin/install-dependencies` to automatically install these tools.

👉 **[See Installation Guide](docs/installation.md)** for detailed setup instructions on macOS, Ubuntu, and Windows.

🔧 Installation
--------------

[](#-installation)

```
composer require imal-h/pdf-box
```

✨ Features
----------

[](#-features)

FeatureDescriptionDriver**HTML to PDF**Generate PDF from HTML/CSS[Chrome](docs/drivers/chrome.md)**Digital Sign**Sign PDFs with X.509 Certs[OpenSSL](docs/drivers/openssl.md)**OCR**Extract text from PDF/Images[Tesseract](docs/drivers/tesseract.md)**Redact**Blackout sensitive text[Ghostscript](docs/drivers/ghostscript.md)**Fill Forms**Fill AcroForms (FDF)[PDFtk](docs/drivers/pdftk.md)**Inspect Forms**Get Field Names[PDFtk](docs/drivers/pdftk.md)**Convert**PDF to Images (PNG/JPG)[Ghostscript](docs/drivers/ghostscript.md)**Merge**Combine multiple PDFs[Ghostscript](docs/drivers/ghostscript.md)**Split**Extract pages or ranges[Ghostscript](docs/drivers/ghostscript.md)**Compress**Optimize PDF file size[Ghostscript](docs/drivers/ghostscript.md)**Encrypt**Password protection and permissions[Ghostscript](docs/drivers/ghostscript.md)**Watermark**Overlay text on pages[Ghostscript](docs/drivers/ghostscript.md)**Rotation**Rotate pages 90/180/270°[Ghostscript](docs/drivers/ghostscript.md)**Metadata**Edit Title, Author, Keywords[Ghostscript](docs/drivers/ghostscript.md)**Flatten**Burn forms into contentGhostscript📖 Usage
-------

[](#-usage)

### HTML to PDF (New in v3.0)

[](#html-to-pdf-new-in-v30)

Generate PDFs from HTML content or URLs using Chrome Headless.

```
use ImalH\PDFLib\PDF;

// From HTML String
PDF::init()
    ->driver(PDF::DRIVER_CHROME)
    ->convertFromHtml('Hello World', 'output.pdf');

// From URL (Coming Soon)
// PDF::init()->driver(PDF::DRIVER_CHROME)->fromUrl('https://google.com')->save('output.pdf');
```

### Digital Signatures (New in v3.0)

[](#digital-signatures-new-in-v30)

Digitally sign PDFs using OpenSSL (requires `tecnickcom/tcpdf`).

```
use ImalH\PDFLib\PDF;

PDF::init()
    ->driver(PDF::DRIVER_OPENSSL)
    ->from('contract.pdf')
    ->sign('certificate.crt', 'private_key.pem', 'signed_contract.pdf', [
        'info' => [
            'Name' => 'John Doe',
            'Location' => 'Colombo, LK',
            'Reason' => 'Digital Contract Signature'
        ],
        // New in v3.2: Visual Signature with Relative Positioning
        'image' => 'signature.png',
        'page' => 1,
        'x' => ($pdf->getPageDimensions(1)['w'] - 60) / 2, // Center X
        'y' => 250,
        'w' => 60,
        'h' => 30
    ]);
```

> **Note:** If you use a self-signed certificate (like in testing), PDF viewers will show "Signature Validity Unknown". For a green "Trusted" checkmark, use a certificate issued by a recognized Certificate Authority (CA) or explicitly trust your self-signed certificate in the viewer's settings.

### Laravel Integration

[](#laravel-integration)

Publish the config file:

```
php artisan vendor:publish --tag=pdflib-config
```

Use the Facade in your controllers:

```
use ImalH\PDFLib\Laravel\Facades\PDF;

// The driver is automatically configured from config/pdflib.php
PDF::from('upload.pdf')->ocr('output.txt');
```

### OCR (New in v3.1)

[](#ocr-new-in-v31)

Extract text from scanned PDFs or images.

```
PDF::init()
    ->driver(PDF::DRIVER_TESSERACT)
    ->from('scanned_doc.pdf') // Automatically converts PDF to Image internally
    ->ocr('extracted_text');
```

### Redaction (New in v3.1)

[](#redaction-new-in-v31)

Permanently remove sensitive text.

```
PDF::init()
    ->driver(PDF::DRIVER_GHOSTSCRIPT)
    ->from('invoice.pdf')
    ->redact('Confidential', 'clean_invoice.pdf');
```

### Interactive Forms

[](#interactive-forms)

Fill PDF forms programmatically using `pdftk`.

```
use ImalH\PDFLib\PDF;

// 1. Inspect Fields (Optional)
$fields = PDF::init()->driver(PDF::DRIVER_PDFTK)->getFormFields('form_template.pdf');
// returns ['full_name', 'date', ...]

// 2. Fill Form
PDF::init()
    ->driver(PDF::DRIVER_PDFTK)
    ->from('form_template.pdf')
    ->fillForm([
        'full_name' => 'Imal Perera',
        'date' => '2025-01-01'
    ], 'filled_form.pdf');
```

### The Modern Way (Fluent API)

[](#the-modern-way-fluent-api)

```
use ImalH\PDFLib\PDF;

// Convert PDF Page 1 to JPEG
PDF::init()
    ->driver(PDF::DRIVER_GHOSTSCRIPT)
    ->from('document.pdf')
    ->to('output_folder')
    ->convert();
```

### The Legacy Way (v2.x Facade)

[](#the-legacy-way-v2x-facade)

Existing code continues to work without changes, but is marked as deprecated.

```
use ImalH\PDFLib\PDFLib; // Legacy Class

$pdfLib = new PDFLib();
$pdfLib->setPdfPath("document.pdf")
       ->setOutputPath("output_folder")
       ->convert();
```

### Example: Advanced Chain

[](#example-advanced-chain)

```
PDF::init()
    ->from('source.pdf')
    ->from('source.pdf')
    ->encrypt('userPass', 'ownerPass', 'processed.pdf');
```

(Note: Current driver operations like `encrypt`, `rotate`, and `watermark` are immediate and require a destination path. Fully stateful chaining for these methods is planned for v3.1)

🔮 Roadmap
---------

[](#-roadmap)

Want to see what's coming next (v3.1+)? Check out our [Roadmap](ROADMAP.md).

🤝 Contributing
--------------

[](#-contributing)

We welcome contributions! Please see [CONTRIBUTING](CONTRIBUTING.md) for details on our new coding standards (Pint, PHPStan) and architecture.

📄 License
---------

[](#-license)

The MIT License (MIT). Please see [License File](LICENSE.md).

---

*Initiative of [Treinetic (Pvt) Ltd](http://www.treinetic.com).*

###  Health Score

63

—

FairBetter than 99% of packages

Maintenance79

Regular maintenance activity

Popularity51

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 94% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~156 days

Recently: every ~4 days

Total

23

Last Release

152d ago

Major Versions

1.5.0 → 2.0.02025-12-23

2.0.1 → v3.0.0-alpha2025-12-31

PHP version history (2 changes)1.0.0PHP &gt;=5.5.0

v3.0.0-alphaPHP &gt;=8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1076374?v=4)[Imal Hasaranga Perera](/maintainers/imalhasaranga)[@imalhasaranga](https://github.com/imalhasaranga)

---

Top Contributors

[![imalhasaranga](https://avatars.githubusercontent.com/u/1076374?v=4)](https://github.com/imalhasaranga "imalhasaranga (94 commits)")[![joshbmarshall](https://avatars.githubusercontent.com/u/4043827?v=4)](https://github.com/joshbmarshall "joshbmarshall (3 commits)")[![ahfeel](https://avatars.githubusercontent.com/u/43286?v=4)](https://github.com/ahfeel "ahfeel (1 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![mablae](https://avatars.githubusercontent.com/u/389360?v=4)](https://github.com/mablae "mablae (1 commits)")

---

Tags

encrypt-pdfghostscript-pdf-manipulationmerge-pdfpdfpdf-optimizpdf-to-imagesplit-pdfthumbnail-generatorwatermarkphppdfmanipulationghostscriptpdftkdigital-signaturehtml-to-pdfdriver-basedform-fillingchrome-headless

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/imal-h-pdf-box/health.svg)

```
[![Health](https://phpackages.com/badges/imal-h-pdf-box/health.svg)](https://phpackages.com/packages/imal-h-pdf-box)
```

###  Alternatives

[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k38.9k](/packages/matomo-matomo)[mpdf/mpdf

PHP library generating PDF files from UTF-8 encoded HTML

4.7k83.4M565](/packages/mpdf-mpdf)[pontedilana/php-weasyprint

PHP library allowing PDF generation from an url or a html page. Wrapper for Kozea/WeasyPrint.

781.2M17](/packages/pontedilana-php-weasyprint)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k43](/packages/civicrm-civicrm-core)[mostafaznv/pdf-optimizer

PDF optimization tool for PHP and Laravel applications

172166.2k](/packages/mostafaznv-pdf-optimizer)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.6M574](/packages/shopware-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
