Discussion:
Ghostscript pdfwrite
(too old to reply)
s***@adeptivesw.com
2006-08-30 16:04:12 UTC
Permalink
I am trying to use Ghostscript in Windows to merge multiple PDFs into a
single PDF. The command line I am running is:

gswin32 -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=C:\Temp\tmp323.pdf
-dBATCH C:\Temp\pdf1.pdf C:\Temp\pdf2.pdf

When ghostscript opens, I get the error:

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

If I remove the device name and use the default device, ghostscript
runs successfully and I can see the PDF being generated. My path has
the bin and lib dirs. Running ghostscript reports pdfwrite as one of
the devices that can be used. I have tried setting other environment
variables, such as gs_lib and making sure the temp is to a writable
location.

I've seen others with this issue, but they appear to be using gs,
showing they are using unix instead. I'm not sure why there would be
any difference, but trying to make the changes suggested in those
threads has not helped.
Lee Sau Dan
2006-08-31 00:00:49 UTC
Permalink
smithsj> I am trying to use Ghostscript in Windows to merge
smithsj> multiple PDFs into a single PDF.

See if 'pdftk' (another program separate from Ghostscript) would help
you.
--
Lee Sau Dan +Z05biGVm- +AH4-{@nJX6X+AH4-}

E-mail: ***@informatik.uni-freiburg.de
Home page: http://www.informatik.uni-freiburg.de/+AH4-danlee
Kevin Ashley
2006-08-31 15:03:40 UTC
Permalink
Post by s***@adeptivesw.com
I am trying to use Ghostscript in Windows to merge multiple PDFs into a
gswin32 -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=C:\Temp\tmp323.pdf
-dBATCH C:\Temp\pdf1.pdf C:\Temp\pdf2.pdf
**** Unable to open the initial device, quitting.
If I remove the device name and use the default device, ghostscript
runs successfully and I can see the PDF being generated. My path has
the bin and lib dirs. Running ghostscript reports pdfwrite as one of
the devices that can be used. I have tried setting other environment
variables, such as gs_lib and making sure the temp is to a writable
location.
When you remove the device name, you aren't seeing a "PDF" being
generated. You are seeing something else - a screen visualisation of
the result of merging two PDFs. Are you able to use the pdfwrite
device at all (can you use it to turn one postscript file into
PDF, for instance ?) The error message is saying that the pdfwrite
device cannot be initialised. Does gs_lib point to a directory
which contains things like pdfwrite.ps ?

What version of ghostscript are you using ? I believe some earlier
versions had known problems with pdf writing for which there were
workrounds.

Other thoughts: have you tried setting the device using the GS_DEVICE
environment variable ? If you have, did it make any difference ? (It
shouldn't, but it's worth trying.)

It's a long time since I used gs under windows, but I vaguely recall
having problems when using filenames that required directories
to be specified. Have you tried either quoting the filenames, or
letting things go in the default directory?
Post by s***@adeptivesw.com
I've seen others with this issue, but they appear to be using gs,
showing they are using unix instead. I'm not sure why there would be
any difference, but trying to make the changes suggested in those
threads has not helped.
What changes did those threads suggest?
s***@adeptivesw.com
2006-08-31 16:08:22 UTC
Permalink
Post by Kevin Ashley
Are you able to use the pdfwrite
device at all (can you use it to turn one postscript file into
PDF, for instance ?)
Kevin, good thinking on this. I have two goals with ghostscript,
convert ps to pdf, which already works using ps2pdf. I looked in the
batch file and it is using pdfwrite. I will examine what it might be
setting so this will work for me. I will post back once I find out
more.

gswin32c doesn't appear to make any difference for me. They both
report the same error.
s***@adeptivesw.com
2006-08-31 22:45:47 UTC
Permalink
I think I have narrowed this down to a path issue. I simplified the
directories in my post, but once I tried these directories I wrote,
specifically for the output file, the pdf started generating properly.
The double quotes did fix my earlier problem where ghostscript would
report an issue with my path.

It's a good idea to always use double quotes when specifying the path
and filename. Single quotes do not work.

Thanks for the help.
SaGS
2006-09-01 07:41:42 UTC
Permalink
Post by s***@adeptivesw.com
...
It's a good idea to always use double quotes when specifying the path
and filename. Single quotes do not work.
...
Single quotes NEVER work for quoting a filename in Windows. They are
valid filename characters, as letters and digits are, and are
considered part of the filename itself. For quoting, ALWAYS use double
quotes.
David Kastrup
2006-08-31 15:07:38 UTC
Permalink
Post by s***@adeptivesw.com
I am trying to use Ghostscript in Windows to merge multiple PDFs into a
gswin32 -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=C:\Temp\tmp323.pdf
-dBATCH C:\Temp\pdf1.pdf C:\Temp\pdf2.pdf
**** Unable to open the initial device, quitting.
Try running gswin32c instead.
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
Russell Lang
2006-09-02 12:12:44 UTC
Permalink
Post by s***@adeptivesw.com
I am trying to use Ghostscript in Windows to merge multiple PDFs into a
gswin32 -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=C:\Temp\tmp323.pdf
-dBATCH C:\Temp\pdf1.pdf C:\Temp\pdf2.pdf
**** Unable to open the initial device, quitting.
The most common reason for this error with the pdfwrite device is that it can't open the output
file. The output file might be locked by another process, or the path may be wrong. As written by
others, using double quotes is essential on Windows if the path may contain a space.

I would instead use (assuming that c:\temp exists and is writeable)

"c:\program
files\gs\gs8.54\bin\gswin32c" -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile="C:\Temp\tmp323.pdf"
-c .setpdfwrite -f "C:\Temp\pdf1.pdf" "C:\Temp\pdf2.pdf"

This is effectively what ps2pdf.bat file does.

Loading...