0

I'm trying to crop a PDF that is purposely being output over sized since the program outputting it doesn't know the size of it's contents. On the FreeBSD system in question there is Ghostscript v7.07 installed. Based on the existing answer on another question (Cropping a PDF using Ghostscript 9.01) and adapting it to v7.07 documentation (http://ghostscript.com/doc/7.07/Readme.htm) I've tried the below replacing the -o with -sOutputFile= since it doens't recognize the -o.

gs                                  \
   -dNOPAUSE                        \
   -dBATCH                          \
   -sDEVICE=pdfwrite                \
   -c "[/CropBox [0 6785 433 7128]" \
   -c " /PAGES pdfmark"             \
   -sOutputFile=testout.pdf         \
   testin.pdf                       \

and i've also tried

gs                           \
  -dNOPAUSE                  \
  -dBATCH                    \
  -sDEVICE=pdfwrite          \
  -dDEVICEWIDTHPOINTS=433    \
  -dDEVICEHEIGHTPOINTS=343   \
  -dFIXEDMEDIA               \
  -c "0 6785 translate"      \
  -c "0 0 433 343 rectclip"  \
  -sOutputFile=testout.pdf   \
  testin.pdf                 \

My problem is that in both cases i just get the below message

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

When searching for that error it mostly seemed to be due to the output file location not having write privileges or something similar to that, but that doesn't appear to be the case because I've chmod my folder to 777. The thing that drove me here is that if i remove the postscript command lines (-c) like below it outputs the testout.pdf file just fine (but obviously not cropped or translated to the correct position).

gs                                  \
   -dNOPAUSE                        \
   -dBATCH                          \
   -sDEVICE=pdfwrite                \
   -sOutputFile=testout.pdf         \
   testin.pdf                       \

and

gs                           \
  -dNOPAUSE                  \
  -dBATCH                    \
  -sDEVICE=pdfwrite          \
  -dDEVICEWIDTHPOINTS=433    \
  -dDEVICEHEIGHTPOINTS=343   \
  -dFIXEDMEDIA               \
  -sOutputFile=testout.pdf   \
  testin.pdf                 \

I thought maybe 7.07 simply didn't support those commands since it doesn't seem to matter what i put within the -c it always ends up giving that error if the -c is there at all, but it is present in the 7.07 documentation (http://ghostscript.com/doc/7.07/Use.htm#General_switches) and it's not like it's giving me a -c is unknown error, so i'm at a loss. I figure I'm either doing something wrong, or there is something wrong with the ghostsciprt installation or it's dependencies. Any help anyone could give me would be greatly appreciated.

Community
  • 1
  • 1
Ben Moyer
  • 3
  • 1

1 Answers1

0

OK first off UPGRADE you are using a 13+ year old version of software.

Secondly, your command line is incorrect, you are using -c but you have not supplied the matching -f This means that everything after -c including the input and output filenames is being treated as PostScript.

Now a more recent version of Ghostscript would tell you that it needed an output filename, your incredibly ancient crufty version can only tell you that the device didn't open (because there was no output filename) which is why you get the misleading message.

Don't use -c twice, everything after -c (until -f) is treated as PostScript so you don't need to specify it twice.

I would expect this to work but since you are using so old a version I cannot be certain:

gs                           \
  -dNOPAUSE                  \
  -dBATCH                    \
  -sDEVICE=pdfwrite          \
  -dDEVICEWIDTHPOINTS=433    \
  -dDEVICEHEIGHTPOINTS=343   \
  -dFIXEDMEDIA               \
  -c "0 6785 translate      \
   0 0 433 343 rectclip" -f  \
  -sOutputFile=testout.pdf   \
  testin.pdf
KenS
  • 30,202
  • 3
  • 34
  • 51
  • Obviously if upgrading was an option i would have just done that first, but i assumed any/all answers would be just telling me to upgrade anyway. That aside, thank you, it was the missing -f that was messing it up. – Ben Moyer Feb 16 '16 at 02:35