GhostScript version: 9.53.3
I need to stamp a pdf with (Entwurf) for all pages.
<<
/EndPage
{
gsave
/Helvetica-Bold 120 selectfont .5 .setfillconstantalpha .45 setgray
130 430 moveto 30 rotate (Entwurf) show -30 rotate
130 130 moveto 30 rotate (Entwurf) show -30 rotate
grestore
true
} bind
>> setpagedevice
Without .5 .setfillconstantalpha this script runs successfully. I have used 0.5 .setopacityalpha before but it crashes the same way and is deprecated since 9.53.
cat start.pdf | gs -q -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=/workspace/test.pdf Watermark_def.ps -
Error: /undefined in /--.endpage--
Operand stack:
(/tmp/gs_KvXeWS) --nostringval-- --dict:7/16(L)-- false --dict:4/6(L)-- 2 0 2 0.5
Execution stack:
%interp_exit .runexec2 --nostringval-- .endpage --nostringval-- 2 %stopped_push --nostringval-- .endpage .endpage false 1 %stopped_push 1990 1 3 %oparray_pop 1989 1 3 %oparray_pop 1977 1 3 %oparray_pop .endpage 1978 3 3 %oparray_pop .endpage .endpage 2 1 12 .endpage %for_pos_int_continue .endpage 1938 4 7 %oparray_pop .endpage 1820 6 7 %oparray_pop .endpage 9 .endpage
Dictionary stack:
--dict:731/1123(ro)(G)-- --dict:1/20(G)-- --dict:80/200(L)-- --dict:80/200(L)-- --dict:133/256(ro)(G)-- --dict:320/325(ro)(G)-- --dict:31/32(L)--
Current allocation mode is local
GPL Ghostscript 9.53.3: Unrecoverable error, exit code 1
That isn't a crash. It's a graceful exit on an error condition.
.setfillconstantalpha is a non-standard PostScript extension, PostScript does not support transparency (except in some limited fashions) so you can't use alpha blending in a normal PostScript program.
Ghostscript, because of the needs of PDF, does support transparency in the graphics library, and some limited support was added to the PostScript language to enable its use. This is decidedly non-standard and will not work on any other PostScript interpreter.
However, the use of these extensions is dependent on various operations happening in the correct sequence; get it wrong and it may crash. So by default, you can't use them in order to prevent malicious programs crashing the interpreter (or worse).
If you want to use these extensions (and take the risk of things blowing up) then you need to specifically allow them. This is documented, see the online documentation here and look for -dALLOWPSTRANSPARENCY. Also here.
Related
I am trying to convert a PS file to PDF via Ghostscript (version 9.52). My problem is that the PS file has a reference to an external EPS file, this is a logo file which is normally in the printer memory. I have the source of this EPS file as well. When using the 'ps2pdf' script installed with Ghostscript I get an error on loading the EPS file. The code where the EPS gets loaded looks like this:
/showpage {} def
/setpagedevice /pop load def
(logo.eps) run
restore
When I run 'ps2pdf' the following error is shown:
Error: /invalidfileaccess in --run--
Operand stack:
--nostringval-- (logo.eps) (r)
Execution stack:
%interp_exit .runexec2 --nostringval-- run --nostringval-- 2 %stopped_push --nostringval-- run run false 1 %stopped_push 1990 1 3 %oparray_pop 1989 1 3 %oparray_pop 1977 1 3 %oparray_pop 1833 1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- run --nostringval-- 2 %stopped_push --nostringval-- 1990 2 3 %oparray_pop run
Dictionary stack:
--dict:739/1123(ro)(G)-- --dict:0/20(G)-- --dict:82/200(L)--
Current allocation mode is local
Any suggestions on how to convert a PS file with EPS references to PDF?
As noted in the recent release notes (and warned about for literally years) Ghostscript now ships with SAFER as the default.
When SAFER is actiuve the PostScript file operators are disabled, and will fail with an invalidfileaccess error. You need to either set -dNOSAFER (NOT recommended) or add the files you want to be able to access to the list of accessible files, reading and writing are treated separately).
This is all covered in the docuementation, you can find it online here (look for -dSAFER lower down the page from that link) or locally in ghostpdl/doc/Use.htm
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
Using Ghostscript 8.71 in Ubuntu, but having trouble reading a PDF file that has the times new roman font on all its pages.
I downloaded the msttcorefonts package and created a Fontmap file for Ghostscript, but this just doesnt seem to work.
My Fontmap file looks like this:
/Times (/usr/share/fonts/truetype/msttcorefonts/times.ttf);
/Times-Roman (/usr/share/fonts/truetype/msttcorefonts/times.ttf);
/Times-Bold (/usr/share/fonts/truetype/msttcorefonts/timesbd.ttf);
/Times-BoldItalic (/usr/share/fonts/truetype/msttcorefonts/timesbi.ttf);
/Times-Italic (/usr/share/fonts/truetype/msttcorefonts/timesi.ttf);
The Ghostscript command I use:
gs -sFONTMAP=/usr/share/ghostscript/8.71/Fontmap bad.pdf -o good.pdf
And this is the error I get:
GPL Ghostscript 8.71 (2010-02-10)
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 3.
Page 1
Error: /undefined in --run--
Operand stack:
--dict:5/14(L)-- F2 11.0 FontObject --dict:8/8(L)-- --dict:8/8(L)-- 397 --dict:8/8(L)--
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1878 1 3 %oparray_pop 1877 1 3 %oparray_pop 1861 1 3 %oparray_pop --nostringval-- --nostringval-- 2 1 3 --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-- --nostringval--
Dictionary stack:
--dict:1151/1684(ro)(G)-- --dict:1/20(G)-- --dict:75/200(L)-- --dict:75/200(L)-- --dict:108/127(ro)(G)-- --dict:288/300(ro)(G)-- --dict:22/25(L)-- --dict:6/8(L)-- --dict:25/40(L)-- --dict:1151/1684(ro)(G)-- --dict:10/10(L)--
Current allocation mode is local
Last OS error: 2
GPL Ghostscript 8.71: Unrecoverable error, exit code 1
Could anyone please help me on this? I feel like I've exhausted all possibilities that I can think of.
Here is the PDF file I'm trying to run through Ghostscript: bad.pdf
If I load all fonts like so:
gs -c 'loadallfonts quit'
Then the only references to the Times New Roman font is:
Loading TimesNewRomanPS-BoldItalicMT font from /usr/share/fonts/truetype/msttcorefonts/timesbi.ttf... 4310316 2923512 4001304 2206507 1 done.
Reading the properties of the attached PDF, I can see the font it actually wants is TimesNewRomainPSMT. Why is gs not loading all fonts in the msttcorefonts folder?
This is what the pdffonts utility reports about bad.pdf:
pdffonts bad.pdf
name type encoding emb sub uni object ID
--------------------------- ----------------- ---------------- --- --- --- ---------
Times-Roman Type 1 WinAnsi no no no 12 0
DejaVuSerifCondensed Type 1 WinAnsi yes no no 13 0
DejaVuSansCondensed Type 1 WinAnsi yes no no 16 0
DejaVuSansCondensed-Bold Type 1 WinAnsi yes no no 19 0
This means the following:
The font's name which is not embedded is Times-Roman, not TimesNewRomanPSMT as you think. (I guess you used the Adobe Acrobat/Reader "file properties" dialog to look at the font properties? And there you saw this font name tagged as "Actual Font" or similar? This means that Acrobat is using this font named TimesNewRomanPSMT as a substitute, because it does not have a font named Times-Roman itself!)
There are 3 fonts from the DejaVu family embedded. These are not subsetted, but embedded as full fonts.
So far, so good...
Or?
Now see what happens if I try to let the newest Ghostscript version, compiled from current Git sources, process this bad.pdf:
gs -o new.pdf -sDEVICE=pdfwrite bad.pdf
GPL Ghostscript GIT PRERELEASE 9.16 (2014-09-22)
Copyright (C) 2014 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 3.
Page 1
**** Warning: can't process font stream, loading font by the name.
Substituting font Helvetica-Narrow for DejaVuSerifCondensed.
Loading NimbusSanL-ReguCond font from %rom%Resource/Font/NimbusSanL-ReguCond... 4671296 3041958 2433440 1055875 3 done.
Loading NimbusRomNo9L-Regu font from %rom%Resource/Font/NimbusRomNo9L-Regu... 4688240 3115971 2494016 1110728 3 done.
Page 2
**** Warning: can't process font stream, loading font by the name.
Substituting font Helvetica-Narrow for DejaVuSerifCondensed.
Page 3
**** Warning: can't process font stream, loading font by the name.
Substituting font Helvetica-Narrow for DejaVuSerifCondensed.
**** This file had errors that were repaired or ignored.
**** The file was produced by:
**** ====== mPDF 4.6 ======
**** Please notify the author of the software that produced this
**** file that it does not conform to Adobe's published PDF
**** specification.
Your embedded fonts cannot be processed by Ghostscript.
There seems to be much more wrong with this particular PDF than what you think.
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 have XPS file that is needed to be converted to PDF. I'm trying to use GSWin tool. But I cannot, I don't know why.
The command line is:
C:\Windows\system32>"C:\Program Files
(x86)\gs\gs9.04\bin\gswin32c.exe" sOutputFile="c:\temp\test2.pdf"
-sDEVICE=pdfwrite -dNOPAUSE "C:\TEMP\test2.xps"
The output is:
Error: /undefined in PK♥
Operand stack:
Execution stack: %interp_exit .runexec2 --nostringval--
--nostringval-- --nostringval-
- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- fa lse 1 %stopped_push 1926 1 3 %oparray_pop 1925 1 3 %oparray_ pop 1909 1 3
%oparray_pop 1803 1 3 %oparray_pop --nostringval-
- %errorexec_pop .runexec2 --nostringval-- --nostringval-- --nostringv al-- 2 %stopped_push --nostringval-- Dictionary stack: --dict:1165/1684(ro)(G)-- --dict:0/20(G)--
--dict:77/200(L)-- Current allocation mode is local Current file position is 3 GPL Ghostscript 9.04: Unrecoverable error, exit code 1
I don't understand it and don't know how to make it work. I suppose I use it improper but I'm not sure how to fix it.
Thanks!
Ghostscript (gswin32.exe) only accepts PostScript or PDF as an input, so you can't use it to deal with XPS. You need another member of the family, GhostXPS (gxps.exe), which accepts XPS as an input. There is also GhostPCL (pxl6.exe) which accepts PCL as an input.
All the family members are available under GPL and can be downloaded from the Ghostscript downloads site:
http://www.ghostscript.com/download/