| 1 |
.TH PDFTOSRC 1 "16 January 2026" "Web2C 2026" |
| 2 |
.\"===================================================================== |
| 3 |
.if t .ds TX \fRT\\h'-0.10m'\\v'0.17v'E\\v'-0.17v'\\h'-0.06m'X\fP |
| 4 |
.if n .ds TX TeX |
| 5 |
.\"===================================================================== |
| 6 |
.SH NAME |
| 7 |
pdftosrc \- extract source file or stream from PDF file |
| 8 |
.SH SYNOPSIS |
| 9 |
.B pdftosrc |
| 10 |
.I PDF-file |
| 11 |
.RI [ stream-object-number ] |
| 12 |
.\"===================================================================== |
| 13 |
.SH DESCRIPTION |
| 14 |
If only |
| 15 |
.I PDF-file |
| 16 |
is given as argument, |
| 17 |
.B pdftosrc |
| 18 |
extracts the embedded source file |
| 19 |
from the first found stream object |
| 20 |
with /Type /SourceFile within the |
| 21 |
.I PDF-file |
| 22 |
and writes it to a file with the name /SourceName |
| 23 |
as defined in that PDF stream object |
| 24 |
(see application example below). |
| 25 |
.PP |
| 26 |
If both |
| 27 |
.I PDF-file |
| 28 |
and |
| 29 |
.I stream-object-number |
| 30 |
are given as arguments, and |
| 31 |
.I stream-object-number |
| 32 |
is positive, |
| 33 |
.B pdftosrc |
| 34 |
extracts and uncompresses the PDF stream of the object |
| 35 |
given by its |
| 36 |
.I stream-object-number |
| 37 |
from the |
| 38 |
.I PDF-file |
| 39 |
and writes it to a file named |
| 40 |
.IR PDF-file . stream-object-number |
| 41 |
with the ending |
| 42 |
.B .pdf |
| 43 |
or |
| 44 |
.B .PDF |
| 45 |
stripped from the original |
| 46 |
.I PDF-file |
| 47 |
name. |
| 48 |
.PP |
| 49 |
A special case is related to XRef object streams that are part |
| 50 |
of the PDF standard from PDF-1.5 onward: |
| 51 |
If |
| 52 |
.I stream-object-number |
| 53 |
equals -1, |
| 54 |
then |
| 55 |
.B pdftosrc |
| 56 |
decompresses the XRef stream from the PDF file and writes it |
| 57 |
in human-readable PDF cross-reference table format to a file named |
| 58 |
.IB PDF-file .xref |
| 59 |
(these XRef streams cannot be extracted just by giving their object number). |
| 60 |
.PP |
| 61 |
In any case, |
| 62 |
an existing file with the output file name will be overwritten. |
| 63 |
.PP |
| 64 |
.B Notes |
| 65 |
.PP |
| 66 |
An embedded source file is written unchanged, |
| 67 |
i.e., it will not be uncompressed. |
| 68 |
.PP |
| 69 |
Only the stream of the object will be written, |
| 70 |
i.e., not the dictionary of that object. |
| 71 |
.PP |
| 72 |
Knowing which |
| 73 |
.I stream-object-number |
| 74 |
to query requires information about the PDF file |
| 75 |
that has to be gained elsewhere, |
| 76 |
e.g., by looking into the PDF file with an editor or dumping it with a |
| 77 |
utility. |
| 78 |
.PP |
| 79 |
The stream extraction capabilities of |
| 80 |
.B pdftosrc |
| 81 |
(regarding known PDF versions and filter types, for instance) |
| 82 |
follow the capabilities of the underlying |
| 83 |
.B xpdf |
| 84 |
program version. |
| 85 |
.PP |
| 86 |
Currently the generation number of the stream object |
| 87 |
is not supported. |
| 88 |
The default value 0 (zero) is taken. |
| 89 |
.PP |
| 90 |
The wording |
| 91 |
.I stream-object-number |
| 92 |
has nothing to do with the `object streams' introduced |
| 93 |
by the \fIAdobe PDF Reference\fP, 5th edition, version 1.6. |
| 94 |
.SH EXAMPLES |
| 95 |
An external file, say \fImyfile.zip\fP, can be embedded into a file |
| 96 |
\fIfoo.pdf\fP by using pdf\*(TX primitives, as illustrated by the |
| 97 |
following example: |
| 98 |
.PP |
| 99 |
.RS |
| 100 |
\\immediate\\pdfobj |
| 101 |
stream attr {/Type /SourceFile /SourceName (myfile.zip)} |
| 102 |
file{myfile.zip} |
| 103 |
\\pdfcatalog{/SourceObject \\the\\pdflastobj\\space 0 R} |
| 104 |
.RE |
| 105 |
Then \fImyfile.zip\fP can be extracted from \fIfoo.pdf\fP |
| 106 |
by calling "pdftosrc foo.pdf". |
| 107 |
.\"===================================================================== |
| 108 |
.SH OPTIONS |
| 109 |
None. |
| 110 |
.SH ENVIRONMENT |
| 111 |
None. |
| 112 |
.\"===================================================================== |
| 113 |
.SH DIAGNOSTICS |
| 114 |
If success, the exit code of |
| 115 |
.B pdftosrc |
| 116 |
is 0, else 1. |
| 117 |
.PP |
| 118 |
All messages go to stderr. |
| 119 |
At program invocation, |
| 120 |
.B pdftosrc |
| 121 |
issues the current version number of the program |
| 122 |
.BR xpdf , |
| 123 |
on which |
| 124 |
.B pdftosrc |
| 125 |
is based, though it is maintained as part of pdf\*(TX. |
| 126 |
.PP |
| 127 |
When |
| 128 |
.B pdftosrc |
| 129 |
was successful with the output file writing, |
| 130 |
one of the following messages will be issued: |
| 131 |
.PP |
| 132 |
.RS |
| 133 |
Source file extracted to |
| 134 |
.I source-file-name |
| 135 |
.RE |
| 136 |
or |
| 137 |
.RS |
| 138 |
Stream object extracted to |
| 139 |
.IR PDF-file . stream-object-number |
| 140 |
.RE |
| 141 |
or |
| 142 |
.RS |
| 143 |
Cross-reference table extracted to |
| 144 |
.IR PDF-file .xref |
| 145 |
.RE |
| 146 |
.PP |
| 147 |
When the object given by the |
| 148 |
.I stream-object-number |
| 149 |
does not contain a stream, |
| 150 |
.B pdftosrc |
| 151 |
issues the following error message: |
| 152 |
.RS |
| 153 |
Not a Stream object |
| 154 |
.RE |
| 155 |
.PP |
| 156 |
When the |
| 157 |
.I PDF-file |
| 158 |
can't be opened, the error message is: |
| 159 |
.RS |
| 160 |
Error: Couldn't open file |
| 161 |
.RI ' PDF-file '. |
| 162 |
.RE |
| 163 |
.PP |
| 164 |
When |
| 165 |
.B pdftosrc |
| 166 |
encounters an invalid PDF file, |
| 167 |
the error message (several lines) is: |
| 168 |
.RS |
| 169 |
Error: May not be a PDF file (continuing anyway) |
| 170 |
.RE |
| 171 |
.RS |
| 172 |
(more lines) |
| 173 |
.RE |
| 174 |
.RS |
| 175 |
Invalid PDF file |
| 176 |
.RE |
| 177 |
.PP |
| 178 |
There are other error messages from |
| 179 |
.B pdftosrc |
| 180 |
for various kinds of broken PDF files. |
| 181 |
.\"===================================================================== |
| 182 |
.SH BUGS |
| 183 |
Not all embedded source files will be extracted, |
| 184 |
only the first one found. |
| 185 |
.\"===================================================================== |
| 186 |
.SH SEE ALSO |
| 187 |
.BR pdfimages (1), |
| 188 |
.BR pdftex (1), |
| 189 |
.BR pdftotext (1), |
| 190 |
.BR xpdf (1). |
| 191 |
.\"===================================================================== |
| 192 |
.SH AUTHORS |
| 193 |
.B pdftosrc |
| 194 |
is part of pdf\*(TX was written by H\[`a]n The Th\[`a]nh, using |
| 195 |
.B xpdf |
| 196 |
functionality from Derek Noonburg. Man page written by Hartmut Henkel. |
| 197 |
.PP |
| 198 |
Public discussion list for pdftosrc: |
| 199 |
https://lists.tug.org/pdftex |