tecnickcom / tc-lib-pdf-filter
PHP library to decode PDF compression and encryption filters
Fund package maintenance!
Requires
- php: ^8.2
- ext-pcre: *
- ext-zlib: *
Requires (Dev)
- carthage-software/mago: 1.47.6
- pdepend/pdepend: ^2.16
- phpunit/phpunit: ^11.5 || ^12.5 || ^13.3
Suggests
- ext-imagick: Required for the JPXDecode (JPEG 2000) and CCITTFaxDecode filters
- jbig2dec: CLI tool required for the JBIG2Decode filter
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-05 07:33:34 UTC
README
Decoder library for standard PDF stream filters.
๐ Part of the tc-lib-pdf / TCPDF ecosystem (100M+ installs). Sponsor its maintenance โ
Overview
tc-lib-pdf-filter decodes the stream filters defined by the PDF specification (PDF 32000-1:2008 ยง7.4), one at a time or as a chain, with the DecodeParms of each filter.
| Namespace | \Com\Tecnick\Pdf\Filter |
| Author | Nicola Asuni info@tecnick.com |
| License | GNU LGPL v3 - see LICENSE |
| API docs | https://tcpdf.org/docs/srcdoc/tc-lib-pdf-filter |
| Packagist | https://packagist.org/packages/tecnickcom/tc-lib-pdf-filter |
Features
PDF Filters
FlateDecode,LZWDecode,RunLengthDecodeASCIIHexDecode,ASCII85DecodeCCITTFaxDecode,DCTDecode,JPXDecode,JBIG2DecodeCrypt(IdentityandNone)
API
- Decode one filter, or a chain of filters applied in order
DecodeParmsas a single dictionary or as an array parallel toFilterPredictor(TIFF and PNG) forFlateDecodeandLZWDecode- Filter names as the full name, the inline-image abbreviation, or a
FilterTypeenum case - A single exception class for unknown filters and malformed streams
Requirements
- PHP 8.2 or later
- Extensions:
zlib,pcre - Composer
Optional:
- Extension
imagick: required byCCITTFaxDecodeandJPXDecode - CLI tool
jbig2dec: required byJBIG2Decode
Without them those three filters throw; the others are unaffected.
Decode parameters
DecodeParms entries are passed to decode() and decodeAll() as an array.
Beyond the parameters defined by the PDF specification, three filters accept
one more:
| Parameter | Filters | Meaning |
|---|---|---|
MaxOutputSize |
FlateDecode, LZWDecode, RunLengthDecode |
Decoded-size cap in bytes; 0 (default) = unlimited |
FlateDecode reaches compression ratios above 1000:1, so callers decoding
untrusted documents should set MaxOutputSize to bound decompression bombs.
CCITTFaxDecode derives the image height from Rows. When Rows is absent the
height is estimated from the encoded length, which under-estimates it and
truncates the image, so pass Rows (the image dictionary /Height).
Installation
composer require tecnickcom/tc-lib-pdf-filter
Quick Start
<?php require_once __DIR__ . '/vendor/autoload.php'; $filter = new \Com\Tecnick\Pdf\Filter\Filter(); $decoded = $filter->decodeAll(['ASCIIHexDecode', 'FlateDecode'], $data);
Development
make deps
make help
make qa
Packaging
make rpm make deb
For system packages, bootstrap with:
require_once '/usr/share/php/Com/Tecnick/Pdf/Filter/autoload.php';
Contributing
Contributions are welcome. Please review CONTRIBUTING.md, CODE_OF_CONDUCT.md, and SECURITY.md.