import_streams
Import and apply modified content streams
Usage
pdftl
<input>import_streams[normalize=true]<stream_file>output<output>
Details
The import_streams operation reads a text file containing PDF content
streams and applies them directly into the target PDF document.
It is designed to perfectly round-trip the output from dump_streams.
The primary workflow is to dump a document’s streams to text, use standard
Unix text tools (like sed, awk, or manual text editing) to modify the
PDF operators, and then pipe the resulting text file back into pdftl
using import_streams.
Addressing Mechanism
The operation strictly targets semantic paths described in the headers,
ignoring any internal Object IDs ((4:0)).
=== Page 1 / Contentsoverwrites the main content stream of Page 1.=== Page 2 / XObject /Fm1overwrites the stream of the XObject mapped as/Fm1within Page 2’s resources.=== Page 1 / XObject /Fm1 / XObject /Fm0overwrites the nested XObject/Fm0.
Because it relies on semantic paths, you can easily use text tools to
migrate streams across entirely different PDF documents by simply swapping
the header paths (e.g. using sed to rename the target XObject).
Options
normalize=true(default) — Before writing the stream into the PDF,pdftlusespikepdf’s internal engine to parse and normalize the syntax. This automatically strips any%comments (such as those generated bydump_streams annotate), cleans up whitespace, and validates the PDF syntax. Passnormalize=falseif you want to force raw text byte injection.
Examples
Dump, patch, and re-import Page 1’s content stream using a Unix pipe
pdftl in.pdf dump_streams 1 | sed -e 's/Apple/Banana/' | pdftl in.pdf import_streams - output out.pdf
Apply modifications from a saved text file back into the document
pdftl in.pdf import_streams patched_streams.txt output out.pdf
Inject stream text verbatim, without parsing or stripping comments
pdftl in.pdf import_streams normalize=false streams.txt output out.pdf
Tags: in_place, content_stream, dangerous
Source: pdftl.operations.import_streams
Read online: https://pdftl.readthedocs.io/en/latest/operations/import_streams.html
Type: Operation