3

I am using gdal_translate to convert non-spatial PDFs to non-spatial TIFFs (intended for subsequent manual georeferencing).

This is my gdal_translate command:

gdal_translate -of GTiff -sds -co NBITS=1 --config GDAL_PDF_DPI 300 %input_pdf% %output_tif%

Here is what it looks like at ~8x magnification (note the "nibbling" around the edges of text and the complete loss of many "speckles"):

Input (rendered by Adobe Reader, disregard the slight blurring of edges):

Input

Output (rendered by ArcMap):

Output

If I do not specify the output bit depth (by omitting the NBITS option), I can tell that GDAL is re-rasterizing and resampling the input 1-bit image into a blurred grayscale image:

Resampled

Ideally it would just copy each pixel in the input straight to the output.

How can I retain the original resolution without information loss in the output? Should I use something else, like ImageMagick, Poppler or GhostScript?

All this re-rasterization GDAL is doing is painfully slow, I might add, so I think I will try one of the alternatives for that reason alone.

5
  • 1
    I've always used ghostscript for this sort of task though many will balk at using command line options, there was GSview (pages.cs.wisc.edu/~ghost/gsview) that went with ghostscript that offered a GUI to export with. May 2, 2014 at 0:52
  • 1
    I typically use Adobe products (Photoshop/Acrobat) directly for this sort of thing, but I gather you're looking for a free or at least less costly solution. At one point I had a problem trying to extract jpgs because every Adobe method I tried invariably altered the image (recompress, etc). It was suggested to me to try xpdf as that would allow me to 'extract the exact image, bit for bit, as it is in the pdf.' I have yet to get around to testing it though.
    – Chris W
    May 2, 2014 at 2:25
  • 1
    Just saw that our very own @mattwilkie had a very similar question over on StackOverflow: stackoverflow.com/q/2693820/386205 Seems this is a common GIS workflow :)
    – blah238
    May 2, 2014 at 18:16
  • 1
    Oh, veeeery common, at least in some fields. I do this a lot with plats and surveys. For some reason everyone wants everything as a pdf, even if all the pdf is doing is serving as a container for an image(s).
    – Chris W
    May 2, 2014 at 23:34
  • Yup. The nice things about PDF are just about everyone has a reader for it, and it is a multi-page format. The same cannot be said for many other formats. It's sad that ArcGIS cannot import PDF files directly. Well, it can, but only on the page layout, and with shoddy results to boot.
    – blah238
    May 2, 2014 at 23:56

1 Answer 1

2

I tried Xpdf, suggested by @ChrisW, but I couldn't get its pdfimages command to actually do anything.

However, MuPDF's mutool extract command worked great. It produces PNGs rather than TIFFs, but that should be fine. The resolution appears unchanged from the original.

I was also able to get GhostScript working for this purpose, although I had to specify the output resolution (300 dpi):

gswin32c -dSAFER -dBATCH -dNOPAUSE -sDEVICE=tifflzw -r300 -sOutput
File=%output_tif% %input_pdf%

I will probably go with GhostScript as I have more control over the output naming convention and the 1-bit TIFF files it produces with the above command are smaller than the 8-bit PNGs MuPDF produces.

4
  • 1
    I guess the crux of the matter is the distinction between converting a pdf to tif vs extracting an image from one. As you noted in gdal, and even when using Photoshop and some methods in Acrobat, conversion ends up re-rasterizing the data. As far as Xpdf, not sure if pdfimages was the command you would want to use as opposed to pdfdetach. It may depend on what image format went into the pdf, and I've yet to get around to testing it.
    – Chris W
    May 2, 2014 at 23:41
  • Yup, it's just one big scanned image per page in the PDF. The GhostScript command above works surprisingly quickly though. gdal_translate was orders of magnitude slower.
    – blah238
    May 2, 2014 at 23:54
  • pdfdetach -saveall doesn't seem to do anything either. pdfdetach -list says there are no embedded files. Strange.
    – blah238
    May 3, 2014 at 0:02
  • I determined pdfdetach is for a different purpose - think markups and acutal attachments like to an email. pdfimages is the correct command. I got it working (in fact all you need is that exe, nothing else). The command line was pdfimages c:\path\filename.pdf c:\path\outputfolder\nameprefix which generated a numbered series of images. Output path is required or it won't do anything. It only outputs three formats (ppm, pbm, or jpg) per the link above, so conversion/compression still required if not using -j (just like MuPDF and PNGs). I'll be checking those other two out myself.
    – Chris W
    May 3, 2014 at 4:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.