How to decode PDF multi-filter

354 Views Asked by At

The PDF internal structure has been analyzed.

A stream with a single filter works fine.

But in the case of multiple filters as shown below, which one should be turned off first?

enter image description here

I don't know how to turn it off.

The header is broken due to an encoding (or decoding) problem, or it is not resolved as desired.

[/ASCIIHexDecode /FlateDecode]

1

There are 1 best solutions below

2
On

But in the case of multiple filters as shown below, which one should be turned off first?

According to the PDF specification ISO 32000-2:2020, the filters shall be applied in the order in which they occur in that array:

Key Type Value
Filter name or array (Optional) The name, or an array of zero, one or several names, of filter(s) that shall be applied in processing the stream data found between the keywords stream and endstream. Multiple filters shall be specified in the order in which they are to be applied.

(Table 5 — Entries common to all stream dictionaries)

In case of your example, therefore,

/ASCIIHexDecode /FlateDecode

you first have to ASCIIHexDecode the content - i.e. the hex digits in the stream shall be pairwise converted to bytes - and then FlateDecode those bytes.


In a comment you asked

Is there any way to find out how multiple filters are configured?

Filters can be configured by parameters in the DecodeParms value:

Key Type Value
DecodeParms dictionary or array (Optional) A parameter dictionary or an array of such dictionaries, used by the filters specified by Filter, respectively. If there is only one filter and that filter has parameters, DecodeParms shall be set to the filter’s parameter dictionary unless all the filter’s parameters have their default values, in which case the DecodeParms entry may be omitted. If there are multiple filters and any of the filters has parameters set to nondefault values, DecodeParms shall be an array with one entry for each filter in the same order as the Filter array: either the parameter dictionary for that filter, or the null object if that filter has no parameters (or if all of its parameters have their default values). If none of the filters have parameters, or if all their parameters have default values, the DecodeParms entry may be omitted.

(Table 5 — Entries common to all stream dictionaries)