0

I built a quite large PDF using LaTeX with the lualatex compiler (I need that one because of specific fonts) and now want to shrink the PDF with ps2pdf, following this instruction (the answer with the second-most votes, since gs is not recognized as a command line tool on my computer). My command looks like this:

ps2pdf -dPDFSETTINGS=/ebook -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -q -sOutputFile=output.pdf input.pdf

I get this error message:

MiKTeX GPL Ghostscript 9.25: Device 'pdfwrite' requires an output file but no file was specified.
**** Unable to open the initial device, quitting.

I definitely made sure that the file exists, I tried it using as *.ps file as input, gave the full path, once with and without double-quotes (Windows system), yet nothing worked. Strangely enough, just running ps2pdf ouput.pdf input.ps works, but produces an even larger PDF. What am I missing?

s6hebern
  • 725
  • 9
  • 18

1 Answers1

1

The file that can't be opened is the output file, so if it exists, that would be a potential problem. If 'something else' has the output file open then it won't be possible to write to it.

You appear to be running a non-standard version of Ghostscript, judging by the startup banner, if I were you I would install and use a standard version of Ghostscript, even if you have to build it yourself.

It's odd that 'ps2pdf' which is just a script to run Ghostscript would work, whereas a simple 'gs' would not. I personally would not use the script. Try and find the Ghostscript executable and run that directly.

I'd drop the -q (quiet) switch as well, at least while trying to solve a problem, suppressing messages could be hiding something useful.

Oh I see, you are actually using Windows. Well, the executable on Windows isn't called 'gs', it's called gswin followed by either 32 or 64 for the word size and then c if it's the command line (as opposed to windowed) version. So you want one of gswin32, gswin32c, gswin64 or gswin64c. Note that the Ghostscript installer doesn't add the installation directory to the $PATH environment variable so if you just open a Windows command shell and type 'gswin32c' it won't be found. You need to either add the isntall directory to the $PATH or supply a full path to the executable.

I'd personally use the vanilla Windows binary rather than a modified version supplied under MingW or whatever Linux shell you are using. It's also conceivable that this is causing your problem writing to the output file, if the directory is unavailable, or read-only, to the shell.

halfer
  • 19,824
  • 17
  • 99
  • 186
KenS
  • 30,202
  • 3
  • 34
  • 51
  • Thanks, I was able to locate the executable and added it to the `$PATH` environment. When I now run it, it prompts me with `Page 1`, followed by `>>showpage, press to continue<<` for each single page. Finally, I end up with a corrupt, empty PDF and the GS console. – s6hebern Aug 12 '19 at 07:23
  • 1
    You need to enter 'quit' at the prompt. The PDF file isn't written completely until Ghostscript exits. You can avoid that by using "-o output.pdf" instead of "-sOutputFile=output.pdf" or by adding "-dBATCH -dNOPAUSE" to your existing command line. – KenS Aug 12 '19 at 07:40
  • Good point, worked! Now only one more thing: all my internal links are broken after the conversion. Any way I can keep them? – s6hebern Aug 12 '19 at 07:41
  • I can't really comment on the 'internal links' without seeig the PDF file, since that description can cover a lot of different PDF constructs. For the rest, see my comment. Note that Ghostscript does not 'compress', 'optimise' or 'reduce' PDF files. What it does is take an input (PostScript, PDF, XPS, PCL, PXL) and, when the pdfwrite device is selected, produce a PDF file from it. It **may** be that the file is smaller, especially if you use things like downsampling images, but that's not the intent. Every time you 'process' a PDF file like this you stand a chance of losing fidelity. – KenS Aug 12 '19 at 07:42
  • For "internal links", I'm speaking of references like "see Figure 1" or the table of contents. In the original pdf the work perfectly fine, in the output file they are just gone. – s6hebern Aug 12 '19 at 07:45
  • Yeah describing it doesn't help. – KenS Aug 12 '19 at 07:45
  • Also, you should use the latest version of Ghostscript, which is currently 9.27 – KenS Aug 12 '19 at 07:46
  • Cannot share the pdf for privacy reasons and do not have a minimum example at hand. My version is 9.27, so it's the latest one. I guess I need to use an external compression site for this at the moment. – s6hebern Aug 12 '19 at 08:01
  • If you can find a file which behaves the same I can look at it, but without seeing teh actual content of the PDF file, at the lowest level, its not possible to say why there's a problem. However the pdfwrite device does **not** preserve everything in a PDF file. This is discussed in teh documentation. – KenS Aug 12 '19 at 09:25