3

I am trying to change the dpi of a .pdf image (myPic.pdf) using gs in Linux/Ubuntu 11.10

Here's how I am going about it but I get errors:

 gs -q -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -dPDFSETTINGS=/printer \
    -sOutputFile=fileout.pdf \
     myPic.pdf`

Here, I am attempting to change the dpi to 300 as per this

The error that I receive when I try the above command is:

**** Unable to open the initial device, quitting.

What gives?

Possible solution:

Check this out.

2 Answers 2

2

Your initial Ghostscript command should work.

However, if you are in a directory which is not writeable for the user running the command, you'll get a message like that!

mbp:/$ pwd
 /

mbp:/$ ls -ld .
 drwxr-xr-x  38 root  wheel  1360 Mar 10 16:20 .

mbp:/$ whoami
 pipitas

mbp:/$ gs -o a.pdf -sDEVICE=pdfwrite -c showpage
 GPL Ghostscript 9.05 (2012-02-08)
 Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.
 This software comes with NO WARRANTY: see the file PUBLIC for details.
 GPL Ghostscript 9.05: **** Could not open the file a.pdf .
 **** Unable to open the initial device, quitting.

mbp:/$ cd ~

mbp:/$ pwd
 /Users/pipitas

mbp:~$ ls -ld .
 drwxr-xr-x+ 3010 pipitas  staff  102340 Mar 13 22:01 .

mbp:~$ gs -o a.pdf -sDEVICE=pdfwrite -c showpage
 GPL Ghostscript 9.05 (2012-02-08)
 Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.
 This software comes with NO WARRANTY: see the file PUBLIC for details.
3
  • I was in a read/writable directory. So it is rather strange that it didn't work. I will check again though. Thanks!
    – dearN
    Mar 14, 2012 at 23:14
  • What came out of this check?! Aug 9, 2012 at 8:16
  • Unfortunately I don't quite remember. Sorry.
    – dearN
    Aug 9, 2012 at 11:55
0

This worked!

convert -units PixelsPerInch myPic.pdf -density 300 fileout.pdf

4
  • 1
    Ummm... this however gives a very grainy looking image file.
    – dearN
    Aug 7, 2012 at 18:18
  • 2
    convert is from ImageMagick. It doesn't process PDFs natively, preserving their possible vector graphics content. It only processes pixel images natively. To 'read' PDFs, it uses Ghostscript as a delegate, which converts the (vector) PDF's pages to (pixel) images. Once it's a pixel image there is no way for ImageMagick in hell to return to a vector based PDF. (Its like you can't reverse the process of steak->mincemeat. You can't go back from burger to schnitzel, can you?). That's why the PDF which ImageMagick produces is just an all-page image embedded into a thin PDF structure... Aug 9, 2012 at 8:13
  • 4
    -- Lastly, PDFs per se don't have a 'resolution'. Only pixel images which are embedded in PDF pages do have a 'resolution'. So your command convert -units PixelsPerInch myPic.pdf -density 300 fileout.pdf tells ImageMagick: 'Take my PDF file and convert everything contained in there (be it pixel images or be it vector objects) into one single 300dpi image and put that one image back into a PDF page!' Aug 9, 2012 at 8:16
  • You need to put -density 200 before the input file name. Oct 15, 2016 at 19:16

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.