Decoder library for standard PDF stream filters.
💖 Part of the tc-lib-pdf / TCPDF ecosystem (100M+ installs). Sponsor its maintenance →
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 |
FlateDecode,LZWDecode,RunLengthDecodeASCIIHexDecode,ASCII85DecodeCCITTFaxDecode,DCTDecode,JPXDecode,JBIG2DecodeCrypt(IdentityandNone)
- 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
- 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.
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).
composer require tecnickcom/tc-lib-pdf-filter<?php
require_once __DIR__ . '/vendor/autoload.php';
$filter = new \Com\Tecnick\Pdf\Filter\Filter();
$decoded = $filter->decodeAll(['ASCIIHexDecode', 'FlateDecode'], $data);make deps
make help
make qamake rpm
make debFor system packages, bootstrap with:
require_once '/usr/share/php/Com/Tecnick/Pdf/Filter/autoload.php';Contributions are welcome. Please review CONTRIBUTING.md, CODE_OF_CONDUCT.md, and SECURITY.md.