I have several Postscript files I need to convert to PDF for work. (No I cannot send you the PS files, it's confidential).
They were created using Adobe 3.0 standards :
(%!PS-Adobe-3.0
%%Creator: Emtex - vdd2ps 212.5.1)
So i need to invoke ps2pdf12.
When I try ps2pdf12 test.ps output.pdf I get this :
"Error: /undefined in ps2pdf12
Operand Stack:
Execution stack :
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-
- 2 %stopped_push --nostringval-- --nostringval-- %loop_continue --n
ostringval-- --nostringval-- false 1 %stopped_push .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval
--
Dictionary stack:
--dict:1166/1684(ro)(G)-- --dict:0/20(G)-- --dict:77/200(L)--
Current allocation mode is local
Current file position is 9
"
I run the script using GhostScript 9.05 or 9.20 and I get the same error.
I also tried using directly ghostScript with things like
"gs -o "output.pdf" -sDEVICE=pdfwrite -dCompatibilityLevel=1.2 -r=720 "test.PS" "
but I get the same mistakes.
When I am in Ghostview to watch my PS and I go to File-->Convert and I choose pdfwrite and resolution = 720, I get the pdf...
Any ideas where my problem come from?
Thanks in advance
If the PostScript program causes Ghostscript to throw an error, then the PostScript program is most likely defective.
I'm afraid that the fact that the file begins with %!PS-Adobe-3.0 doesn't mean much. That is actually supposed to be the version of the Document Structuring Convention which the program is compatible with, but unfortunately many PostScript producers don't understand that, and thinking that it just means 'this is a PostScript file' stick it on the front. SO you can't read anything from it.
I'm afraid that if you can't share an example of the program then there is, frankly, almost nothing anyone can do to help. My guess (and that's all it is without seeing an example) is that the PostScript is broken.
After several tries and checks with GSView, i managed to get the following quote and it seems to work fine.
gswin32c.exe -o "output.pdf" -dNOSAFER -sDEVICE=pdfwrite -r720 -dAutoRotatePages=false -dCompatibilityLevel=1.2 -dUseFlateCompression=true -dMaxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true -dNumRenderingThreads=2 -c "60000000 setvmthreshold" -f -dEPSCrop "test.PS"
Thanks for your help :)
Related
I was trying to convert jpg to pdf using ghost script. The command which I was using was
C:\Users\kbged\Desktop\XAMPP\php\bin\gs\gs9.54.0\bin\gswin64c -sDEVICE=pdfwrite -sOutputFile=C:\Users\kbged\Pictures\php48D4.pdf C:\Users\kbged\Desktop\XAMPP\php\bin\gs\gs9.54.0\lib\viewjpeg.ps -c (C:\Users\kbged\Pictures\group_image.jpg) viewJPEG
However, this end with following error:
GPL Ghostscript 9.54.0 (2021-03-30)
Copyright (C) 2021 Artifex Software, Inc. All rights reserved.
This software is supplied under the GNU AGPLv3 and comes with NO WARRANTY:
see the file COPYING for details.
Error: /stackunderflow in --dup--
Operand stack:
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval--
Dictionary stack:
--dict:732/1123(ro)(G)-- --dict:0/20(G)-- --dict:78/200(L)-- --dict:8/20(L)--
Current allocation mode is local
GPL Ghostscript 9.54.0: Unrecoverable error, exit code 1
I tried to look into that viewjpeg.ps file and almost towards the end I see
% This lets you do stuff on the command line like:
% gs -sDEVICE=pdfwrite -o stuff%03d.pdf viewjpeg.ps -c "(image.jpg) << /PageSize 2 index viewJPEGgetsize 2 array astore >> setpagedevice viewJPEG"
% so the output size matches the original image.
I actually don't understand where the error lies...
Any help would be appreciated! Thanks!
There are several ways to convert image to PDF and this is possibly not the best way to convert Jpeg to PDF in Ghostscript, but you asked why it did not work for you.
The following should in a cmd file, first work per the example, once proven then try changing the <> of the last line that you think need altering. Note that long lines are very fragile and there must be NO space after ^
Also the order and combinations can easily throw GS into an error state.
CMD Filenames are best always "FullPath\quoted" and if you don't want to inititally CD to the output directory (to make it much easier to avoid using escaped name) then change the start of last line to
-c "("C:\\Users\\kbged\\Pictures\\group_image.jpg") <<......
Beware the much simpler method would be to write your own input.PS to avoid potential command line truncation.
#echo off
REM switch to folder of jpeg
cd "C:\Users\kbged\Pictures"
"C:\Users\kbged\Desktop\XAMPP\php\bin\gs\gs9.54.0\bin\gswin64c.exe" -dNOSAFER -sDEVICE=pdfwrite ^
-o "C:\Users\kbged\Pictures\php48D4.pdf" "C:\Users\kbged\Desktop\XAMPP\php\bin\gs\gs9.54.0\lib\viewjpeg.ps" ^
-c "(group_image.jpg) << /PageSize 2 index viewJPEGgetsize 2 array astore >> setpagedevice viewJPEG"
My ultimate goal is to know the ink coverage (sDEVICE=ink_cov)of every separation in my PDF including spot color and cmyk. I am trying to pull these out as separate grey scale files so I can process them with ink_cov but every time I run my script I get --nostringval--. I have tried all sorts of combination for naming the channels but nothing works. Here is my script :
gswin64c -dBATCH -dNOPAUSE -sDEVICE=tiffsep -c -sOutputFile=C:\gsfiles\myseps.tiff "<< /SeparationColorNames [/Process Cyan /Process Magenta /Process Yellow /Process Black /myspotred] >> setpagedevice" myspotred.pdf
here is the result
Error: /undefinedfilename in (<< /SeparationColorNames [/Process Cyan /Process Magenta /Process Yellow /Process Black /myspotred] >> setpagedevice)
Operand stack:
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push
Dictionary stack:
--dict:738/1123(ro)(G)-- --dict:0/20(G)-- --dict:75/200(L)--
Current allocation mode is local
Last OS error: Invalid argument
GPL Ghostscript 9.52: Unrecoverable error, exit code 1
Here's the file in acrobat
Acrobat view of separations
Thanks for any help
You don't need to mess with SeparationColorNames.
Even if you did, you need to specify /Cyan not Cyan. The PostScript world doesn't have a /Process key at all, that's NChannel, which is specific to PDF and not supported by PostScript.
You've put a -c in the wrong place (before -sOutputFile instead of before the actual PostScript). Fortunately that is then negated by -sOutputFile. However what that means is that your PostScript fragment is then not treated as PostScript (because that's what -c means and the -c is terminates by the -s). So that chunk of PostScript gets treated as a filename which is why you get an undefinedfilename error.
To get all the separations just do :
gswin64c -sDEVICE=tiffsep -o C:\gsfiles\myseps%d.tiff myspotred.pdf
If you really want to specify the Separation Names then this:
gswin64c -sDEVICE=tiffsep -o C:\gsfiles\myseps%d.tiff -c "<< /SeparationColorNames [/myspotred] >> setpagedevice" -f myspotred.pdf
should be sufficient, The Process colourants are given by the ProcessColorModel of the device, which in this case is CMYK. You don't enter the Process colourants in the SeparationColorNames array for the very good reason that they are not Separation colours.
Note (for general PostScript) that real physical devices may not permit you to change the colourants, they are read only. So you can retrieve them via a currentpagedevice, but setpagedevice may not be able to alter them.
I am trying to fix my pure black colored text problem in PDF conversion. I am able to convert my sRGB pdf to CMYK pdf but text colors are not kept in pure black. I already tried to use ghostscript: convert PDF into CMYK preserving pure Black for text trick but even I compiled "apple_..." files in my current directory, I always get :
gsicc_open_search(): Could not find ~/temp/AdobeCPs/CMYK/apple_to_jNP_neutrals.icc .
the command I am using:
gs -q -sDEVICE=pdfwrite -o sample.pdf -sColorConversionStrategy=CMYK
-sSourceObjectICC=control.txt test.pdf
My output is :
./base/gsicc_manage.c:1088: gsicc_open_search(): Could not find Graphic_RGB apple_to_jNP_neutrals.icc 0 1 0
+ ./base/gsicc_manage.c:660: gsicc_set_srcgtag_struct(): setting of control.txt src obj color info failed
| ./base/gsicc_manage.c:2731: gs_setsrcgtagicc(): cannot find srctag file
While reading gs_lev2.ps:
Error: /unknownerror in --.setuserparams--
Operand stack:
(gs_res.ps\000gs_typ42.ps\000gs_cidfn.ps\000gs_cidcm.ps\000gs_fntem.ps\000gs_cidtt.ps\000gs_cidfm.ps\000gs_cmap.ps\000gs_setpd.ps\000gs_fapi.ps\000gs_typ32.ps\000gs_frsd.ps\000gs_ll3.ps\000gs_mex_e.ps\000gs_mro_e.ps\000gs_pdf_e.ps\000gs_wan_e.ps\000pdf...) (gs_lev2.ps) --dict:31/31(G)-- --dict:1/1(G)-- --dict:1/1(G)--
Execution stack:
%interp_exit --nostringval-- --nostringval-- %loop_continue --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push --nostringval-- --nostringval--
Dictionary stack:
--dict:798/1123(G)-- --dict:71/200(L)-- --dict:798/1123(G)-- --dict:133/251(G)-- --dict:21/25(L)--
Last OS error: No such file or directory
Current file position is 24631
Unrecoverable error: syntaxerror in --nostringval--
Operand stack:
gs_res.psgs_typ42.psgs_cidfn.psgs_cidcm.psgs_fntem.psgs_cidtt.psgs_cidfm.psgs_cmap.psgs_setpd.psgs_fapi.psgs_typ32.psgs_frsd.psgs_ll3.psgs_mex_e.psgs_mro_e.psgs_pdf_e.psgs_wan_e.pspdf_ops.psgs_l2img.pspdf_rbld.pspdf_base.pspdf_draw.pspdf_font.pspdf_main.pspdf_sec.psgs_cff.psgs_mgl_e.psgs_ttf.psgs_icc.psgs_dps.psgs_dpnxt.psgs_epsf.psgs_pdfwr.ps gs_lev2.ps --nostringval-- --nostringval-- --nostringval-- false
Unrecoverable error: undefined in .uninstallpagedevice
Operand stack:
gs_res.psgs_typ42.psgs_cidfn.psgs_cidcm.psgs_fntem.psgs_cidtt.psgs_cidfm.psgs_cmap.psgs_setpd.psgs_fapi.psgs_typ32.psgs_frsd.psgs_ll3.psgs_mex_e.psgs_mro_e.psgs_pdf_e.psgs_wan_e.pspdf_ops.psgs_l2img.pspdf_rbld.pspdf_base.pspdf_draw.pspdf_font.pspdf_main.pspdf_sec.psgs_cff.psgs_mgl_e.psgs_ttf.psgs_icc.psgs_dps.psgs_dpnxt.psgs_epsf.psgs_pdfwr.ps gs_lev2.ps --nostringval-- --nostringval-- --nostringval-- false
My control.txt file is :
Image_RGB apple_to_jNP_photo.icc 0 1 0
Graphic_RGB apple_to_jNP_neutrals.icc 0 1 0
Text_RGB apple_to_jNP_neutrals.icc 0 1 0
echo $GS_LIB
/usr/share/ghostscript/9.18/Resource
ls /usr/share/ghostscript/9.18/Resource
CIDFont CIDFSubst CMap ColorSpace Decoding Encoding Font IdiomSet Init SubstCID
current directory :
~/temp/AdobeCPs/CMYK$ ls
AppleRGB.icc CoatedGRACoL2006.icc JapanColor2003WebCoated.icc USWebCoatedSWOP.icc
apple_to_jNP_neutrals.icc control.txt JapanWebCoated.icc USWebUncoated.icc
apple_to_jNP_photo.icc JapanColor2001Coated.icc sample.pdf WebCoatedFOGRA28.icc
CoatedFOGRA27.icc JapanColor2001Uncoated.icc test.pdf WebCoatedSWOP2006Grade3.icc
CoatedFOGRA39.icc JapanColor2002Newspaper.icc UncoatedFOGRA29.icc WebCoatedSWOP2006Grade5.icc
Could you help ?
Even though this is a quite old thread it seems not yet solved.
I had the same error as mentioned above with blanks as separators in the control.txt instead of tabs (as mentioned in the Ghostscript version Color Management WhitePaper).
Changing to tabs fixed the problem for me.
Your command line and input file isn't relevant to the problem, the failure is during startup:
| ./base/gsicc_manage.c:2731: gs_setsrcgtagicc(): cannot find srctag
file While reading gs_lev2.ps:
gs_lev2.ps is part of Ghostscript's startup code. That's all executed before you even get to the point of reading the command line options.
You haven't said which version of Ghostscript you are using, on which OS, or where you got it from, but it looks to me like you version is fundamentally broken.
I infer from your text that you are using version 9.18, that's 5 versions (2.5 years) out of date, the current version is 9.23. I'd suggest you get the vanilla Ghostscript source from the downloads page and compile that.
I've got a bit of an issue with Ghostscript. I'm writing an application in .NET that uses the Ghostscript API, gs32dll.dll. It works just fine for a number of pdfs, but there a couple that have this little movie can dingbat, and ghostscript throws an error about not having that font. I know I have to make a listing for that font in the cidfmap file, but since I'm not using an actual install of ghostscript, I don't have local paths pointing to that file. I want this program to be installed on a number of computers, but I'd rather not install the full blown ghostscript on these computers. So, I was wondering if it would be possible to put a copy of cidfmap in with the dll. I figured it might look in its path first. I'd even be cool with ghostscript skipping the conversion of that character. I'm open to any ideas.
About the program:
I teach math. We have these note taking guides on pdf. Every section in each chapter has two pdfs, one with and one without answers. I'm using ghostscript to convert the pdfs to images (jpegs). Once finished, the user will be able to use the smartboard pen to highlight the area where an answer would be, and the answer will be cut from the answer document image and pasted on the same location of the blank document. I plan on giving this out to the other math teachers once I've finished. I'd like to keep the program self contained, so I don't have to explain to them how to install ghostscript and whatnot. I'd just like to hand them a folder.
Revision = 900
RevisionDate = 20100914
Product = GPL Ghostscript
Copyright = Copyright (C) 2010 Artifex Software, Inc. All rights reserved.
GPL Ghostscript 9.00 (2010-09-14)
Copyright (C) 2010 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 5.
Page 1
Page 2
Can't find CID font "ZapfDingbats".
Substituting CID font /Adobe-Identity for /ZapfDingbats, see doc/Use.htm#CIDFont
Substitution.
The substitute CID font "Adobe-Identity" is not provided either. Will exit with
error.
Error: /undefined in findresource
Operand stack:
--dict:11/20(L)-- G27 1 --dict:5/5(L)-- --dict:5/5(L)-- ZapfDingbat
s-Identity-H --dict:10/12(ro)(G)-- --nostringval-- CIDFontObject --dict:
7/7(L)-- --dict:7/7(L)-- Adobe-Identity
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-
- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- fa
lse 1 %stopped_push 1910 1 3 %oparray_pop 1909 1 3 %oparray_
pop 1893 1 3 %oparray_pop --nostringval-- --nostringval-- 3 1
5 --nostringval-- %for_pos_int_continue --nostringval-- --nostringval--
--nostringval-- --nostringval-- %array_continue --nostringval-- false
1 %stopped_push --nostringval-- %loop_continue --nostringval-- --nos
tringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval
-- %array_continue --nostringval-- --nostringval-- --nostringval-- --n
ostringval-- --nostringval-- %loop_continue
Dictionary stack:
--dict:1158/1684(ro)(G)-- --dict:1/20(G)-- --dict:82/200(L)-- --dict:82
/200(L)-- --dict:108/127(ro)(G)-- --dict:293/300(ro)(G)-- --dict:23/30(L)-
- --dict:6/8(L)-- --dict:22/40(L)-- --dict:14/15(L)--
Current allocation mode is local
Last OS error: No such file or directory
GPL Ghostscript 9.00: Unrecoverable error, exit code 1
On a Linux commanline, invoke
gs -h
on Windows, invoke
gswin32c.exe -h
This should show you the search path(s) used by your instance of Ghostscript. This may help you to determine where in your folder structure you'd have to place your font resource.
You can also use an additional CLI parameter to override any builtin search paths:
gswin32c.exe ^
-I"d:/absolute/path/to/dir;../relative/path/to/dir;c:/other dir with spaces" ^
[...]
Note that on Windows Ghostscript is able to use forward slashes as directory delimiters for paths.
I'm sure you can somehow add that sort of invocation (-I...) to your software.
How about separating your program in a client and a server part?
Then a server could have all of Ghostscript and all kinds of fonts installed on it, and the clienst accessing this server would not need Ghostscript at all.
Might help with licensing issues too, depending on your situation.
In response to edited question:
Probably you can install Ghostscript locally to a portable folder within your program drectory:
Look at this forum comment for inspiration. I know others have succeeded too.
I tried
gswin32c -sDEVICE=jpeg -sOutputFile=foo.jpg foo.pdf
but I get the ff. output from Ghostscript on the page where the Chinese font is used.
Substituting CID font resource/Adobe-CNS1 for /·s²Ó©úÅé.
Error: /undefinedresource in --findresource--
Operand stack:
--dict:4/4(L)-- F3 12.96 --dict:6/6(L)-- --dict:6/6(L)-- ·s²Ó©úÅé --dict:9/12(ro)(G)-- --nostringval-- --dict:8/8(L)-- --dict:8/8(L)-- Adobe-CNS1 CIDFont Adobe-CNS1
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1 3 %oparray_pop 1 3 %oparray_pop 1 3 %oparray_pop --nostringval-- --nostringval-- 3 1 33 --nostringval-- %for_pos_int_continue --nostringval-- --nostringval-- --nostringval-- --nostringval-- %array_continue --nostringval-- false 1 %stopped_push --nostringval-- %loop_continue --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- %array_continue --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- %loop_continue --nostringval-- 12 9 %oparray_pop --nostringval-- --nostringval-- --nostringval--
Dictionary stack:
--dict:1122/1686(ro)(G)-- --dict:2/20(G)-- --dict:75/200(L)-- --dict:75/200(L)-- --dict:105/127(ro)(G)-- --dict:253/347(ro)(G)-- --dict:21/24(L)-- --dict:4/6(L)-- --dict:26/31(L)-- --dict:20/26(ro)(G)--
Current allocation mode is local
Last OS error: No such file or directory
GPL Ghostscript 8.54: Unrecoverable error, exit code 1
It's obvious that Ghostscript's encoding is non-Unicode because it got garbage (/·s²Ó©úÅé) when it read the font name which is in Chinese. Here is a screen shot of the Chinese fonts used as listed by Adobe Reader 9.
Interesting problem.
However, it's not necessarily Ghostscript's fault here, that you only see /·s²Ó©úÅé.
From your command, I see you was using Ghostscript on Windows, inside a cmd.exe shell window. And it is cmd.exe which may not be able to display properly what Ghostscript asks it to display. This could have two separate reasons (or both at the same time)
the 'codepage' your cmd.exe window uses cannot handle CID or Unicode characters/glyphs.
the font used by your cmd.exe does not contain and therefore cannot handle CID/Unicode glyphs.
You should query your cmd.exe window first, which 'codepage' it uses. Type:
chcp
and see if it is anything that can NOT display multi-byte characters and glyphs (like "codepage 850").
If so, try to change your codepage in your current cmd.exe window, using this command:
chcp 65001
or
chcp 65000
This should switch you to Unicode (65001 == UTF-8-Unicode; 65000 == UTF-7-Unicode). If you did so, you also have to make sure that the font used in your cmd.exe window can display all (most) of the glyphs in question: therefore you should go into the settings of the cmd.exe window (click the top left corner icon of window title bar) and change the font to 'Lucida Console'.
Here are a few more codepage numbers which may help you:
932 : Japanese Shift-JIS
936 : Simplified Chinese GBK
949 : Korean
950 : Traditional Chinese Big5
But note, you may not be able to switch to these codepages, unless your computer is installed with Japanese/Chinese/Korean language support.
See also here:
http://en.wikipedia.org/wiki/Windows_code_page
http://en.wikipedia.org/wiki/Mojibake
Having said all this above, this may still not solve your problem. Ghostscript may still show the same error, because it is not finding the font it wants to use (CID font resource/Adobe-CNS1) in place of ·s²Ó©úÅé. But at least you would understand better, which font it wants to replace. Your console would display the same asian glyphs as your Adobe Reader screenshot shows... ;-)
Chry Cheng: I'm still trying to find a solution to your problem with Ghostscript, but I didn't have time to do the required research yet...
I don't know if you must use Ghostscript for some reason. But if not, here is another option: MuPDF. Brought to you by artofcode LLC & Artifex Inc. -- the same people that develop Ghostscript.
And MuPDF didn't have any problem for me to render your example file! (Funnily, Ghostscript chokes on page 2; Acrobat Reader also choked, but offered to download and install an additional Asian font, not naming it, but saying it was "to support traditional Chinese". After installing it, Acrobat Reader however does not show a single chinese glyph on page 2!)
MuPDF:
Open Source;
multiplatform (Windows, Mac OS X, Unix, ...soon maybe Android, iPhone too?);
very lightweight (see screenshots below);
very fast;
secure (no JavaScript support);
very surely not bloated with features;
does display all pages of your example PDF
interface is very simple (keyboard navigation only, no menues or icons):
(Chry Cheng: I wonder if you also notice that one little thing in my screenshots that was a bit surprising and mysterious for me...)