Postscript to PDF with EPS reference - pdf

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

Related

GhostScript (9.20, AIX) error converting PDF to PCL

GhostScript 9.20 is giving the following error in attempting to convert a 1-page PDF to PCL:
**** Error reading a content stream. The page may be incomplete.
Output may be incorrect.
Error: /typecheck in --run--
Operand stack:
--dict:4/4(L)-- 9 11150 9 0 --nostringval-- AP --nostringval-- BS --nostringval-- DA (/Helv 10 Tf 0 g) F 4 FT Tx Ff 12587008 MK --nostringval-- P --nostringval-- Rect --nostringval-- Subtype Widget T (MissingInformation) Type V --nostringval-- Annot
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1983 1 3 %oparray_pop 1982 1 3 %oparray_pop 1966 1 3 %oparray_pop --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- %array_continue --nostringval-- --nostringval--
Dictionary stack:
--dict:1205/1684(ro)(G)-- --dict:1/20(G)-- --dict:83/200(L)-- --dict:83/200(L)-- --dict:135/256(ro)(G)-- --dict:291/300(ro)(G)-- --dict:30/32(L)--
Current allocation mode is local
GPL Ghostscript 9.20: Unrecoverable error, exit code 1
It is being executed in Unix-AIX with the following:
gs -dSAFER -sDEVICE=pxlmono -sPAPERSIZE=letter -dFIXEDMEDIA -dPDFFitPage
Sample file that fails
Any thoughts would be appreciated!
Thanks,
Ron
Your PDF file has an error. It contains an annotation which has (object 9):
/V /APPTRIAGE#20CASEONED#3A#0D#0D...Part#20II#3A#20DrugExperimentation#20-#20Drugs#2FMedication#20Not#20Prescribed#3A#20Was#20doctor#20seen#3F#20Provide#20detail#20if#20yes.#0D#0D...Part#20II#3A#20AlcoholDrugTreatment#20-#20Alcohol#20Abuse#20Treatment#3A#20Was#20doctor#20seen#3F#20Provide#20detail#20if#20yes.#0D#0D...Part#20II#3A#20HivAids#20-#20HIV#3A#20Was#20doctor#20seen#3F#20Provide#20detail#20if#20yes.#0D#0D...Part#20II#3A#20HivAids#20-#20AIDS#3A#20Was#20doctor#20seen#3F#20Provide#20detail#20if#20yes.#0D#0D...Part#20II#3A#20LiverDisease#20-#20Esophagus#20Disorder#3A#20Was#20doctor#20seen#3F#20Provide#20detail#20if#20yes.#0D#0D...Part#20II#3A#20MentalDisorder#20-#20Counseling#20-#20Stress#3A#20Have#20you#20ever#20received#20disability#20or#20missed#20work#20due#20to#20psychiatric#20reasons#3F#20Provide#20details#20if#20yes.#0D#0D...Part#20II#3A#20MentalDisorder#20-#20Counseling#20-#20Stress#3A#20Do#20you#20see#20a#20psychiatrist#20or#20counselor#3F#20Provide#20details#20if#20yes.#0D#0D...Part#20II#3A#20MentalDisorder#20-#20Counseling#20-#20Stress#3A#20Was#20doctor#20seen#3F#20Provide#20detail#20if#20yes.#0D#0D...Part#20II#3A#20MentalDisorder#20-#20Counseling#20-#20Stress#3A#20support#20group#20member#20info#20missing#0D#0D...Part#20II#3A#20MentalDisorder#20-#20Counseling#20-#20Stress#3A#20date#20diagnosed#20missing#0D#0D...Part#20II#3A#20MentalDisorder#20-#20Counseling#20-#20Depression#3A#20Have#20you#20ever#20received#20disability#20or#20missed#20work#20due#20to#20psychiatric#20reasons#3F#20Provide#20details#20if#20yes.#0D#0D...Part#20II#3A#20MentalDisorder#20-#20Counseling#20-#20Depression#3A#20Do#20you#20see#20a#20psychiatrist#20or#20counselor#3F#20Provide#20details#20if#20yes.#0D#0D...Part#20II#3A#20MentalDisorder#20-#20Counseling#20-#20Depression#3A#20Was#20doctor#20seen#3F#20Provide#20detail#20if#20yes.#0D#0D...Part#20II#3A#20MentalDisorder#20-#20Counseling#20-#20Depression#3A#20support#20group#20member#20info#20missing#0D#0D...Part#20II#3A#20MentalDisorder#20-#20Counseling#20-#20Depression#3A#20date#20diagnosed#20missing#0D#0D...Part#20II#3A#20MentalDisorder#20-#20Counseling#20-#20Anxiety#3A#20Have#20you#20ever#20received#20disability#20or#20missed#20work#20due#20to#20psychiatric#20reasons#3F#20Provide#20details#20if#20yes.#0D#0D...Part#20II#3A#20MentalDisorder#20-#20Counseling#20-#20Anxiety#3A#20Do#20you#20see#20a#20psychiatrist#20or#20counselor#3F#20Provide#20details#20if#20yes.#0D#0D...Part#20II#3A#20MentalDisorder#20-#20Counseling#20-#20Anxiety#3A#20Was#20doctor#20seen#3F#20Provide#20detail#20if#20yes.#0D#0D...Part#20II#3A#20MentalDisorder#20-#20Counseling#20-#20Anxiety#3A#20support#20group#20member#20info#20missing#0D#0D#28Continued#20on#20next#20page#29
The /V field of an annotation may be a text string or a stream. This annotation has a name object. So its immediately incorrect. Further to that, name objects are subject to an implementation limit which is given in Appendix C of the PDF Reference as 127 bytes, which is considerably less than this monster. Ghostscript permits larger names, but not this large.
Even if I 'fix' that, Ghostscript still doesn't like the file, and if you open the file in Acrobat, and then close it, it offers to 'save changes' which is a pretty good indication that Acrobat has silently ignored an error.
In fact the file has been edited and the edit has broken the file still further.
In short, your file is broken, that's why it doesn't work.

convert png to pdf using ghostscript

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

ImageMagick convert error: /rangecheck in resolveR with PDFs larger than 600KB

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.

GSWin: How to convert XPS to PDF?

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/

Ghostscript fonts using the api

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.