Ghostscript wipes the PDF metadata like author, title, subject etc. How can I tell ghostscript not to touch the metadata? I invoke it as follows:

gs \
  -dBATCH                    \
  -dNOPAUSE                  \
  -sOutputFile=<output_file> \
  -sDEVICE=pdfwrite          \
  -dPDFSETTINGS=/ebook       \
  • Why are you using Ghostscript? There's probably another way to do whatever you're doing. It's uncommon to use Ghostscript when the input isn't a Postscript file. – Gilles 'SO- stop being evil' Oct 10 '12 at 23:14
  • 4
    @Gilles To down-sample the images in the PDF and thus reducing the size. I don't think it's uncommon to use PDF as input. The tool pdf2ps e.g. uses ghostscript for the conversion and is shipped together with gs. – Marco Oct 11 '12 at 7:08
  • Ok, Ghostscript does seem to be the usual way to downsample images in a PDF file, the open source native PDF manipulation tools seem to be lacking in that regard. That or ImageMagick, which only looks at the images and won't care about PDF metadata. – Gilles 'SO- stop being evil' Oct 11 '12 at 9:51
  • 3
    ImageMagick uses ghostscript for processing PDFs. – Marco Oct 11 '12 at 9:56
  • @Gilles: "It's uncommon to use Ghostscript when the input isn't a Postscript file." -- Not at all, Gilles! I use it all the time, every day to do PDF->PDF processing. – Kurt Pfeifle Jan 28 '15 at 20:13

Apparently it's not possible to keep the PDF metadata when using ghostscript. Here is a workaround which first saves the metadata to a file using pdftk, then compresses the file with ghostscript and finally writes back the metadata also using pdftk.


# save metadata
pdftk "$INPUTPDF" dump_data_utf8 > "$METADATA"

# compress
gs                       \
  -q                     \
  -sOutputFile="$TMPPDF" \
  -sDEVICE=pdfwrite      \
  -dNOPAUSE              \
  -dBATCH                \
  -dPDFSETTINGS=/ebook   \

# restore metadata
pdftk "$TMPPDF" update_info_utf8 "$METADATA" output "$OUTPUTPDF"

# clean up

Edit: This is a bug in ghostscript, see Bug report and the confirmation that this is not supposed to happen.

  • pdftks dump_data(_utf8) literally outputs Chinese labels. I couldn't find a forum for pdftk either :( – Stefan K. Apr 17 '13 at 10:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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