I am trying to find a command line example, a PDF source code example (see also How to create plain text PDF examples that work in viewing a document? ), But with an image attachment. This is how far I got - I have a hello.pdf
template:
%PDF-1.4 1 0 obj << /Type /Catalog /Outlines 2 0 R /Pages 3 0 R >> endobj 2 0 obj << /Type /Outlines /Count 0 >> endobj 3 0 obj << /Type /Pages /Kids [ 4 0 R ] /Count 1 >> endobj 4 0 obj << /Type /Page /Parent 3 0 R /MediaBox [ 0 0 612 792 ] /Contents 5 0 R /Resources << /ProcSet 6 0 R /Font << /F1 7 0 R >> /ProcSet [ /PDF /Text /ImageC ] /XObject << /Im1 8 0 R >> >> >> endobj 5 0 obj << /Length 173 >> stream BT /F1 24 Tf 100 100 Td ( Hello World ) Tj 200 200 Td ( Hello Again ) Tj % width skew-right-up skew-top-right height xy 150 0 0 150 340 130 cm % 150 150 Td - irrelevant for image /Im1 Do ET endstream endobj 6 0 obj [ /PDF /Text ] endobj 7 0 obj << /Type /Font /Subtype /Type1 /Name /F1 /BaseFont /Helvetica /Encoding /MacRomanEncoding >> endobj 8 0 obj << /BitsPerComponent 8 /ColorSpace /DeviceRGB /DecodeParms << /BitsPerComponent 8 /Colors 3 /Columns 150 /Predictor 10 >> /Filter [ /FlateDecode ] /Height 150 /Length 1418 /Subtype /Image /Type /XObject /Width 150 >> stream
Then I generate the image data using convert
, and apply the flate compression with zlib
:
convert -size 150x150 gradient:\#4b4-\#bfb test.ppm du -b test.ppm # 135017 bytes python -c "import zlib,sys;sys.stdout.write(zlib.compress(sys.stdin.read()))" < test.ppm > test.flate du -b test.flate # 1418 bytes
Then I replace /Length 1418
in the file and finally replace the ###
token using:
perl -ne 's/^###/`cat test.flate`/e;print' hello.pdf > hello2.pdf
This file obviously has the wrong xref table, but opening in evince
just fine:
... however, it is obvious that the bitmap is not in the correct format.
I also tried to generate, say,
convert -size 150x150 gradient:\#4b4-\#bfb -endian LSB rgb:test.raw
... but they are not green at all (as the original image should be).
Does anyone know the correct image format - and the convert
command line - to create a raw image that you can "go down" and include in pdf?
Thanks a lot in advance for any answers,
Hurrah!