How to inspect and decode PDF streams
By Anton Samper · Reviewed
A PDF stream stores data bytes after a dictionary of properties. Its /Filter entry names the encoding applied to those bytes, such as compression. Decoding reverses supported encodings so you can inspect the data. Positions within the decoded data differ from positions in the original file.
Know what the stream contains
A page’s /Contents stream holds drawing instructions, including text. Other streams can hold images, fonts or embedded files, so decoding does not always produce readable instructions.
An object stream, identified by /Type /ObjStm, is a container for other PDF objects. Open the Compressed objects sample and inspect First page to find its containing object stream and position within that stream’s decoded bytes.
Inspect a Flate-compressed content stream
The Fonts & resources sample stores object 4’s page instructions with /Filter /FlateDecode. Its decoded content includes:
BT
/F1 24 Tf
72 700 Td
(Resources and references) Tj
ET
q
120 0 0 120 72 500 cm
/Im1 Do
QExplore Fonts & resourcesDownload sample PDF
- Choose First page, then follow
/Contentsto object 4. - Inspect
/Filterin Properties. Select Raw stream to see the compressed bytes stored in the PDF. - Select Decoded to inspect the decoded bytes. Use Readable instructions for explanations and resource links.
- Find
/Im1 Do, which draws the image named /Im1 in this example. Images and reusable groups of drawing instructions are called XObjects in PDF. Use Page preview to compare the instructions with the rendered page.
Find visible text in a decoded stream
To search for a word you can see on the page, choose Decoded streams and enter the word, for example “lorem”. Search checks the PDF syntax. A word split across several strings may not match, so try a shorter fragment such as lor. Open the matching stream in Readable instructions to see how the text is drawn.
A PDF can split a word into pieces to control where it draws each letter. This allows it to adjust the gap between letters (kerning) or space a line to fit its width (justification). Decoding removes compression; it does not join these pieces into words.
Read the text instruction
For example, this instruction draws “at varius lorem ”, including the trailing space. It stores “lorem” as (lor) and (em ), with a spacing adjustment between them. This example is separate from the bundled sample above:
[(at) -41 ( ) -48 (varius) -7 ( ) -82 (lor) 17 (em )] TJ| Syntax | Meaning |
|---|---|
[ … ] | An array of strings and spacing adjustments, read in order. |
(lor), (em ) | Text strings. Parentheses mark where each string starts and ends; they do not appear on the page. The second string includes a trailing space. |
( ) | A string containing a space character. |
17, -82 | Move the text position without adding characters or marking word boundaries. |
TJ | Draw the strings, applying each adjustment before continuing. The related Tj operator draws a single string without an array of adjustments. |
For other instructions, see the PDF operator reference from the PDF Association (opens PDF in a new tab).
What do the positive and negative numbers mean?
Each number is measured in thousandths of a unit of text space. For ordinary horizontal text, a positive value pulls the next string back, tightening the gap; a negative value moves it forwards, opening the gap. The numbers adjust how far the text position normally advances after each letter or space. They do not specify absolute page coordinates.
Convert a spacing adjustment to a distance
At a 12-point font size with no additional scaling, 17 pulls the next string back by 17 / 1000 × 12 = 0.204 points. The final distance depends on the font size, horizontal scaling and transformation matrices set by the surrounding instructions.
Compare instructions with the page
In Readable instructions, each array and its TJ operator occupy one row. That row may draw an entire line containing the word you searched for. Line wrapping in the inspector fits the panel; it does not represent line breaks on the PDF page. Use Page preview to compare the instruction with the rendered text.
The hexadecimal label at the left of each row gives its byte offset within the decoded stream, measured from zero. It is separate from the page coordinates and the original file’s offsets.
When strings are not readable text
The selected font determines how to interpret the character codes in each string, so they may not look like readable letters. A TJ array can also contain hexadecimal strings such as <00120034>. If the text is unreadable, follow the font resource in the preceding Tf instruction and inspect its encoding and /ToUnicode mapping. The incorrect copied text example walks through this process.
Decoding limits
The inspector supports Flate, ASCIIHex, ASCII85, and supported chains of those filters. A filter chain applies several encodings in sequence. For other encodings, you can still inspect raw bytes where available. Page preview uses a separate renderer, so it may display content that the inspector cannot decode.
Displayed stream previews stop at 256 KiB. Decoded search only checks those previews. It reads bytes as characters; it does not extract the text shown on a rendered page. Decoding is limited to 32 MiB per stream. Read the complete limitations before drawing conclusions from partial results.
Example source: original sample generator, resourcesPdf and compressedPdf. Review objects and references.