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
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
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.
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/
I normally create a jpg thumbnail from PDF files this way:
exec('convert -contrast ./xyz.pdf[0] ./xyz.jpg');
Alternativly I can also use this variation to create the thumbnails:
exec("/usr/bin/gs -q -dBATCH -dMaxBitmap=300000000 -dNOPAUSE -dSAFER -sDEVICE=jpeg -dJPEGQ=100 -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -r72 -dFirstPage=1 -dLastPage=1 -sOutputFile=./xyz.jpg ./xyz.pdf -c quit");
Now most of the thumbnails are created without any problems. But there are alwasy some cases where the thumbnails aren't created at all. No matter which of the two variations I use. The PDF files seem to be "ok" (at least I can open and view them without any problems).
Is there any other way to get the thumbnails (via script) that could work?
Thanks a lot
The error message I receive is:
[0] => Error: /limitcheck in --run--
[1] => Operand stack:
[2] => --nostringval-- --dict:9/18(L)-- --nostringval--
[3] => Execution stack:
[4] => %interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1905 1 3 %oparray_pop 1904 1 3 %oparray_pop 1888 1 3 %oparray_pop --nostringval-- --nostringval-- 2 1 1 --nostringval-- %for_pos_int_continue --nostringval-- --nostringval-- --nostringval-- --nostringval-- %array_continue --nostringval-- false 1 %stopped_push --nostringval-- %loop_continue --nostringval--
[5] => Dictionary stack:
[6] => --dict:1159/1684(ro)(G)-- --dict:2/20(G)-- --dict:97/200(L)-- --dict:97/200(L)-- --dict:107/127(ro)(G)-- --dict:275/300(ro)(G)-- --dict:22/25(L)-- --dict:4/6(L)-- --dict:22/40(L)-- --dict:1/1(ro)(G)-- --dict:1/1(ro)(G)--
[7] => Current allocation mode is local
[8] => Last OS error: 2
Add the -verbose flag. It will give you all sorts of extra information.
My suspicion would be the version of the PDF file that is causing your issue. ImageMagick uses Ghostscript to process PDFs. I am not sure what version of PDF Ghostscript currently supports, but most opensource tools do not handle the latest version of PDF files.
Edit:
Thought I should add this note, not sure what scripting language you are using to exec from or what OS you are on, but you will probably need to parse the error stream to get the information from the commands. Not sure if the verbose output is written to the error stream, but I am fairly sure the error information (invalid file format, etc) is written to the error stream.
I posted a blog article on how to find out the PDF version used in a PDF file at http://www.jpedal.org/PDFblog/2010/09/how-do-i-find-out-the-pdf-version-used/