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"
Related
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 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 :)
as the title says I am trying to convert png to pdf.
I could not find well described example anywhere about this.
I used this command
gs sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -sOutputFile=test.pdf test.png
but all I get is
Error: /syntaxerror in (binary token, type=137)
Operand stack:
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1894 1 3 %oparray_pop 1893 1 3 %oparray_pop 1877 1 3 %oparray_pop 1771 1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push
Dictionary stack:
--dict:1161/1684(ro)(G)-- --dict:0/20(G)-- --dict:77/200(L)--
Current allocation mode is local
GPL Ghostscript 9.07: Unrecoverable error, exit code 1
this error message. And now I started wodering if such feature is possible in ghostscript. Should I use other software?
** I'm runing the latest 9.07 version
Ghostscript can output multiple formats (png included) but I don't believe it is able to take png as an input. You may be able to accomplish your goal using something like imagemagick's convert utility, though: convert test.png test.pdf
Yes, image magick can do this no problem - here's the cmd line for looping through all the pngs in a folder and converting to pdf:
cd to the folder with the pngs
mogrify -format pdf -density 300 -units PixelsPerInch *png
When using this command on PDFs larger than about 600KB
<? passthru("convert -verbose -scale '200x200+0+0>' ".$pdf."[0] $image"); ?>
I get this error output:
ERROR: /rangecheck in resolveR
Operand stack:
PageCount 4763294 47 46
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-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval--
Dictionary stack:
--dict:1129/1686(ro)(G)-- --dict:0/20(G)-- --dict:107/200(L)-- --dict:107/200(L)-- --dict:104/127(ro)(G)-- --dict:241/347(ro)(G)-- --dict:16/24(L)--
Current allocation mode is local
Anyone have a workaround for these larger files? I need to pull a page 1 thumbnail from some as large as 4 MB.
Per Kurt below I also tried accessing gs directly:
<?
$image = "3.jpg";
$pdf = '3/ABS_Survey_for_Load_Lines_CIB_100.pdf';
if (!file_exists($image)) {
echo passthru("gs \
-sOutputFile=$image \
-sDEVICE=jpeg \
-g200x200 \
-dPDFFitPage \
$pdf");
}
?>
This gives same error:
ESP Ghostscript 815.02 (2006-04-19)
Copyright (C) 2004 artofcode LLC, Benicia, CA. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
ERROR: /rangecheck in resolveR
Operand stack:
PageCount 4763294 47 46
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-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval--
Dictionary stack:
--dict:1122/1686(ro)(G)-- --dict:0/20(G)-- --dict:107/200(L)-- --dict:107/200(L)-- --dict:104/127(ro)(G)-- --dict:241/347(ro)(G)-- --dict:16/24(L)--
Current allocation mode is local
ImageMagick's convert does not open and process PDF files itself. Instead it uses as a delegate for PDF inputs Ghostscript.
The error you show is a typical Ghostscript error message.
To debug this, you should try first to run Ghostscript directly to see if it is really Ghostscript's fault:
gs \
-dBATCH \
-dNOPAUSE \
-sOutputFile=200x200px-output.jpeg \
-sDEVICE=jpeg \
-g200x200 \
-dPDFFitPage \
2000-kilobyte-input.pdf
Also, look for the version of Ghostscript you have: gs -v. (You should use a recent version, for example 9.05)
Update:
Since your version of Ghostscript (ESPGS 8.15.2)...
...is more than 6 years old (at the time PDF-1.6 and Acrobat 7 were the newest versions for PDF),
...but since you very likely are processing even the most current PDF formats (PDF-1.7 and Acrobat X are current now),
...you are well advised to upgrade your Ghostscript (which has to consume such new files) to a current version too.
Bad news! I was playing with an online converter using a problem PDF and it gave a "bad pdf" error. All of the PDFs will open in Acrobat mind you but- I took some of the problem ones and re-saved them using my Acrobat 9 and lo and behold the thumbnails got created no problem...
So the issue had to do with whatever software the shipyard used to make the PDFs.
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.