Ghostscript find out more debugging information - ghostscript

I am creating a pdf file using ghostscript 9.15. I have been using ghostscript for about 5 years and haven’t encountered any serious issues till this week.
Essentially I am running the query below….
“c://distiller/exes/gswin32c.exe" -sDEVICE="pdfwrite" -dNOPAUSE -dBATCH -dNOSAFER -dQUIET -sFONTPATH="C:/Windows/Fonts" -sOUTPUTFILE="C:\distiller\test.pdf" "C:\ExactDistiller \example.ps"
and I get the error below
Current allocation mode is local Last OS error: No such file or
directory Current file position is 197197 GPL Ghostscript 9.15:
Unrecoverable error, exit code 1
I am getting the error “No such file or directory” but I have checked every file path and checked every font is installed and all seems fine but still no luck. I just want to know is there a way of finding out what file / directory is causing the issue?

Well the first thing I would do is not set -dQUIET, turning off information isn't a good way to debug a problem. Not setting -dBATCH and -dNOPAUSE might be helpful too as it might show you more of what is going on. Note that -dNOSAFER is in fact the default, you don't need to set that unless you have previously set your environment to include -dSAFER
In short, when trying to debug the problem, simplify it as far as possible, don't set any switches unless you know you need them, or they contribute to the problem.
You could then paste the stdout transcript which might shed some illumination.
Secondly, your directory appears to contain a trailing space before the separator "c:\ExactDistiller \example.ps", is that correct ? A 'No such file or directory' error will be thrown (without a PostScript error) if you get the input filename incorrect.
If there is a PostScript error revealed when you stop issuing -dQUIET then you can paste it in your original question (by editing it) and I'll take a look. It may be necessary to see your example.ps file, depending on what that reveals.

Related

why is ghostscript replacing embedded fonts?

well I've given up. I don't think I understand how GS works... as far as I understand GS replaces all fonts that are not embedded and should not touch already embedded ones? why is it replacing them? I have a pdf file that contains 2 embedded fonts and 1 not embedded (ArialMT).
I'm using command:
"gswin64c.exe -I "C:/Program Files/gs/gs9.56.1/Resource/Init" -sFONTMAP="Fontmap.GS" -dNOSAFER -dPDFACompatibilityPolicy=1 -sColorConversionStrategy=LeaveColorUnchanged -dBATCH -dNOPAUSE -sDEVICE="pdfwrite" -dAutoRotatePages=/None -dPDFA=3 -sOutputFile="pdfa.pdf" "original.pdf"
all I get with this command is this error:
GPL Ghostscript 9.56.1: Actual TT subtable offset xxxxx differs from one in the TT header yyyy. (multiple ones like this)
The following errors were encountered at least once while processing this file:
error executing PDF token
**** This file had errors that were repaired or ignored.
**** The file was produced by:
**** >>>> StreamServe Communication Server 16.6.1 GA Build 319 (64 bit) <<<<
**** Please notify the author of the software that produced this
**** file that it does not conform to Adobe's published PDF
**** specification.
the output is a pdf without ANY fonts...
is there any way to force GS not to replace font if it wasn't found on the system?
why is it replacing ArialMT with NimbusSans-Regular even though I have declared a specific path to ArialMT in my FontMap.GS file?
I'd rather not share this pdf file as it contains sensitive customer data.
(osadzony podzestaw=embedded subset)
Ghost Script substitution will require embeddable fonts on windows those are usually stored in C:\Windows\Fonts
Thus if font substitution was simple (without look-up) your command could be simplified
gswin64c.exe -sFONTPATH="C:\Windows\Fonts" -dNOSAFER -sDEVICE=pdfwrite -dNEWPDF=false -dPDFA=3 -dPDFACompatibilityPolicy=1 -sColorConversionStrategy=LeaveColorUnchanged -dAutoRotatePages=/None -o"pdfa.pdf" "original.pdf"
you need to add -dNEWPDF=false Since to include additional mapping you add -I "C:/Program Files/gs/gs9.56.1/Resource/Init" -sFONTMAP=Fontmap.gs
Thus the following should be a startpoint
gswin64c.exe -sFONTPATH="C:\Windows\Fonts" -I "C:/Program Files/gs/gs9.56.1/Resource/Init" -sFONTMAP=Fontmap.gs -dNOSAFER -sDEVICE=pdfwrite -dNEWPDF=false -dPDFA=3 -dPDFACompatibilityPolicy=1 -sColorConversionStrategy=LeaveColorUnchanged -dAutoRotatePages=/None -o"pdfa.pdf" "original.pdf"
It will not remove warnings using a PDF file from the same developer, the difference was now there is no mention of Nimbus, but the substitutions should be better/fuller as the warning messages verified the fonts were eventually applied from windows
Note the file is smaller although the fonts are embedded, and in side by side comparison they look the same.
GPL Ghostscript 9.56.1: PDFA doesn't allow images with Interpolate true.
and
The following errors were encountered at least once while processing this file:
missing white space after number
error executing PDF token
**** This file had errors that were repaired or ignored.
**** Please notify the author of the software that produced this
**** file that it does not conform to Adobe's published PDF
**** specification.
from their report.
If I save the file from Acrobat the file size drops but the same issues reside

Accessing files from Ghostscript commands with -dSAFER

I'm trying to write a number of gs commands for server-side use. The user-provided PDF/JPEG files, I have to work with cannot be assumed to be safe (broken or even malicious files could be provided). Therefore, I'm trying to write all of my Ghostscript commands with -dSAFER, to guarantee at least a basic level of security.
Unfortunately, -dSAFER appears to be incompatible with certain gs commands. Take for example the following command:
# count number of pages in PDF
gs -dQUIET -dBATCH -dNOPAUSE -dNOSAFER -dNODISPLAY \
-c "(input.pdf) (r) file runpdfbegin pdfpagecount = quit"
How would you re-write this command with -dSAFER? The command fails if I just add -dSAFER, because gs can't read the file input.pdf (which is what I expect). How do I tell gs that is permitted to read input.pdf, but nothing else? Maybe there's a way to permit reading of files only from certain directories?
Here's a second example command:
# convert JPEG to single-page PDF
gs -dQUIET -dBATCH -dNOPAUSE -dNOSAFER \
-sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dPDFSettings=/printer \
-sColorConversionStrategy=Gray -dProcessColorModel=/DeviceGray \
-sOutputFile=output.pdf \
viewjpeg.ps \
-c "(input.jpg) << /PageSize 2 index viewJPEGgetsize 2 array astore >> setpagedevice viewJPEG"
This command has exactly the same problem as the first one. How do I re-write this with -dSAFER?
Please include a link to the relevant documentation in your answer if you think that -dSAFER is really not needed for my commands.
You can add directories to the search list using -I, IIRC any such directory is permitted to be read. For the current directory you can also use -P- and -P.
See Use.htm in the ghostpdl/doc directory.
However, even if adding the current directory allows you to read the file, this will soon stop working with -dSAFER anyway. There's an ongoing programme to 'harden' the interpreter when -dSAFER is set by hiding/remobing any non-standard operators especially if there's any possibility they could be misused.
Your proposed usage is, simply, incompatible with -dSAFER. The commands you are using will almost certainly be specifically prohibited because they are inherently unsafe. Essentially by messing about inside PDF files like that, your PostScript program is unsafe.
Of course, you know that your PostScript program is safe, and since you are not executing any part of the PDF, the PDF is also safe. The PDF would only be unsafe if you attempted to actually execute the contents, which your program doesn't do. It simply opens the file reads the Pages tree, and tells you the value associated with the Count key.
So you don't need to set -dSAFER in this particular example anyway. However any such program which did execute the PDF content (eg by rendering any part of it, or sending it to the pdfwrite device) would not be safe.
Your second example also doesn't need SAFER, since a JPEG can't contain code to access the disk.

Missing ICC Data in ghostscript

For some documents that I need to convert into images (jpeg) through the (templated) command gs -dNOPAUSE -sDEVICE=jpeg -dBATCH -r133 -sOutputFile=/my/path/%d.jpg file, sometimes I get the following error :
./base/gdevp14.c:3632: pdf14_update_device_color_procs_push_c(): Missing ICC data
the process then launches a signal 11 (which is a segfault I believe). I'm using Ghostscript 9.05 on the machines where this crashes, but on another machine equipped with Ghostscript 9.10, it runs just fine, for (exactly) the same document.
I thought that I could be missing something, but what could it be ?
thanks !
Update to something a little more recent. The current version is 9.16. If you continue to experience problems then file a bug report. I would guess that your bug has been fixed somewhere between 9.05 and 9.10.....
By overriding the ICC settings, it seems that it is doing fine : gs -dNOPAUSE -sDEVICE=jpeg -dOverrideICC -dBATCH -r133 -sOutputFile=/my/path/%d.jpg file.
A PDF that was failing, once exported to a new PDF worked just fine, so I guess there was something amiss in the original PDF, that ghostscript didn't like very much. Overriding the ICC settings with the default ones on the current machine seems to do the trick.

discoloration of images created by ghostscript

I m converting a pdf into image using ghostscript
It almost produces good images but for one pdf the created image is having a white strip
however this strip is not present in the original pdf.
script which i hv used is below
gs -dNOPAUSE -sDEVICE=jpeg -dFirstPage=1 -dLastPage=2 -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile=fileName.gif -dJPEGQ=100 -r300 -q pdfName.pdf -c quit
Here the created image http://www.pictureshack.us/images/65486_1.gif
i am using Ghostscript 8.70 and the issue is fixed for the latest update i.e 9.06, but i cant upgrade to this...moreover found the issue its due -r300, so when i specify resolution of 100 then it works fine for this pdf but not for many other pdf...
You don't say what version of Ghostscript you are using, and you haven't provided the original PDF file, so I can't test it on current code. However, this 'looks like' a transparency bug, and may well be fixed in recent versions of Ghostscript.
I would suggest you upgrade to 9.06 if you haven't already and try that. If the problem persists please open a bug report at http://bugs.ghostscript.com Please attach the original PDF file and the command line you are using.

Programming a Filter/Backend to 'Print to PDF' with CUPS from any Mac OS X application

Okay so here is what I want to do. I want to add a print option that prints whatever the user's document is to a PDF and adds some headers before sending it off to a device.
I guess my questions are: how do I add a virtual "printer" driver for the user that will launch the application I've been developing that will make the PDF (or make the PDF and launch my application with references to the newly generated PDF)? How do I interface with CUPS to generate the PDF? I'm not sure I'm being clear, so let me know if more information would be helpful.
I've worked through this printing with CUPS tutorial and seem to get everything set up okay, but the file never seems to appear in the appropriate temporary location. And if anyone is looking for a user-end PDF-printer, this cups-pdf-for-mac-os-x is one that works through the installer, however I have the same issue of no file appearing in the indicated directory when I download the source and follow the instructions in the readme. If anyone can get either of these to work on a mac through the terminal, please let me know step-by-step how you did it.
The way to go is this:
Set up a print queue with any driver you like. But I recommend to use a PostScript driver/PPD. (A PostScript PPD is one which does not contain any *cupsFilter: ... line.):
Initially, use the (educational) CUPS backend named 2dir. That one can be copied from this website: KDE Printing Developer Tools Wiki. Make sure when copying that you get the line endings right (Unix-like).
Commandline to set up the initial queue:
lpadmin \
-p pdfqueue \
-v 2dir:/tmp/pdfqueue \
-E \
-P /path/to/postscript-printer.ppd
The 2dir backend now will write all output to directory /tmp/pdfqueue/ and it will use a uniq name for each job. Each result should for now be a PostScript file. (with none of the modifications you want yet).
Locate the PPD used by this queue in /etc/cups/ppd/ (its name should be pdfqueue.ppd).
Add the following line (best, near the top of the PPD):
*cupsFilter: "application/pdf 0 -" (Make sure the *cupsFilter starts at the very beginning of the line.) This line tells cupsd to auto-setup a filtering chain that produces PDF and then call the last filter named '-' before it sends the file via a backend to a printer. That '-' filter is a special one: it does nothing, it is a passthrough filter.
Re-start the CUPS scheduler:sudo launchctl unload /System/Library/LaunchDaemons/org.cups.cupsd.plist
sudo launchctl load /System/Library/LaunchDaemons/org.cups.cupsd.plist
From now on your pdfqueue will cause each job printed to it to end up as PDF in /tmp/pdfqueue/*.pdf.
Study the 2dir backend script. It's simple Bash, and reasonably well commented.
Modify the 2dir in a way that adds your desired modifications to your PDF before saving on the result in /tmp/pdfqueue/*.pdf...
Update: Looks like I forgot 2 quotes in my originally prescribed *cupsFilter: ... line above. Sorry!
I really wish I could accept two answers because I don't think I could have done this without all of #Kurt Pfeifle 's help for Mac specifics and just understanding printer drivers and locations of files. But here's what I did:
Download the source code from codepoet cups-pdf-for-mac-os-x. (For non-macs, you can look at http://www.cups-pdf.de/) The readme is greatly detailed and if you read all of the instructions carefully, it will work, however I had a little trouble getting all the pieces, so I will outline exactly what I did in the hopes of saving someone else some trouble. For this, the directory with the source code is called "cups-pdfdownloaddir".
Compile cups-pdf.c contained in the src folder as the readme specifies:
gcc -09 -s -lcups -o cups-pdf cups-pdf.c
There may be a warning: ld: warning: option -s is obsolete and being ignored, but this posed no issue for me. Copy the binary into /usr/libexec/cups/backend. You will likely have to the sudo command, which will prompt you for your password. For example:
sudo cp /cups-pdfdownloaddir/src/cups-pdf /usr/libexec/cups/backend
Also, don't forget to change the permissions on this file--it needs root permissions (700) which can be changed with the following after moving cupd-pdf into the backend directory:
sudo chmod 700 /usr/libexec/cups/backend/cups-pdf
Edit the file contained in /cups-pdfdownloaddir/extra/cups-pdf.conf. Under the "PDF Conversion Settings" header, find a line under the GhostScript that reads #GhostScript /usr/bin/gs. I did not uncomment it in case I needed it, but simply added beneath it the line Ghostscript /usr/bin/pstopdf. (There should be no pre-cursor # for any of these modifications)
Find the line under GSCall that reads #GSCall %s -q -dCompatibilityLevel=%s -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite -sOutputFile="%s" -dAutoRotatePage\
s=/PageByPage -dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode -dPDFSETTINGS=/prepress -c .setpdfwrite \
-f %s Again without uncommenting this, under this I added the line GSCall %s %s -o %s %s
Find the line under PDFVer that reads #PDFVer 1.4 and change it to PDFVer, no spaces or following characters.
Now save and exit editing before copying this file to /etc/cups with the following command
sudo cp cups-pdfdownloaddir/extra/cups-pdf.conf /etc/cups
Be careful of editing in a text editor because newlines in UNIX and Mac environments are different and can potentially ruin scripts. You can always use a perl command to remove them, but I'm paranoid and prefer not to deal with it in the first place.
You should now be able to open a program (e.g. Word, Excel, ...) and select File >> Print and find an available printer called CUPS-PDF. Print to this printer, and you should find your pdfs in /var/spool/cups-pdf/yourusername/ by default.
*Also, I figured this might be helpful because it helped me: if something gets screwed up in following these directions and you need to start over/get rid of it, in order to remove the driver you need to (1) remove the cups-pdf backend from /usr/libexec/cups/backend (2) remove the cups-pdf.conf from /etc/cups/ (3) Go into System Preferences >> Print & Fax and delete the CUPS-PDF printer.
This is how I successfully set up a pdf backend/filter for myself, however there are more details, and other information on customization contained in the readme file. Hope this helps someone else!

Resources