I\'m trying to come up with a command-line, source code example of a PDF (see also How to generate plain-text source-code PDF examples that work in a document viewer?
Ok, fixed it; the problem was that one had to specify 8-bit depth in the convert
command line; thus the correct invocation is:
convert -depth 8 -size 150x150 gradient:\#4b4-\#bfb rgb:test.raw
Then we have:
du -b test.raw # 67500 bytes
python -c "import zlib,sys;sys.stdout.write(zlib.compress(sys.stdin.read()))" < test.raw > test.flate
du -b test.flate # 664 bytes
# replace /Length 664, and then:
perl -ne 's/^###/`cat test.flate`/e;print' hello.pdf > hello2.pdf
Finally, the hello2.pdf
opens in evince
and displays the bitmap correctly:
Btw, I found this because I'm actually trying to debug an image in another document; so I basically did the following:
# extract and save the stream of this image object
qpdf --show-object=23 --raw-stream-data mybadfile.pdf > myraw.file
# get raw binary data - deflate the saved object stream
python -c "import zlib,sys;sys.stdout.write(zlib.decompress(sys.stdin.read()))" < myraw.file > myraw.deflate
identify myraw.deflate
# identify: no decode delegate for this image format `myraw.deflate' @ constitute.c/ReadImage/530.
identify rgb:myraw.deflate
# identify: Must specify image size `myraw.deflate' @ rgb.c/ReadRGBImage/155.
identify -size 588x508 rgb:myraw.deflate
# rgb:myraw.deflate=>myraw.deflate RGB 588x508 588x508+0+0 16-bit TrueColor DirectClass 875KiB 0.020u 0:00.030
# identify: Unexpected end-of-file `myraw.deflate': No such file or directory @ rgb.c/ReadRGBImage/261.
display -size 588x508 rgb:myraw.deflate
# display: Unexpected end-of-file `myraw.deflate': No such file or directory @ rgb.c/ReadRGBImage/261. ### but it shows correctly, except for size?
identify -depth 8 -size 588x508 rgb:myraw.deflate
# rgb:myraw.deflate=>myraw.deflate RGB 588x508 588x508+0+0 8-bit TrueColor DirectClass 875KiB 0.020u 0:00 ## OK
display -depth 8 -size 588x508 rgb:myraw.deflate
# OK; choosing rgba: is already bad - so confirmed 8-bit rgb
Hope this helps someone,
Cheers!