Ghostscript silent printing - printing

I am trying to print pdf file silently from command line (Windows7)and this is what I am using, but I get "gswin32.exe has stopped working." error message.
gswin32c.exe -sDEVICE=mswinpr2 -dBATCH -dNOPAUSE -dNoCancel -sOutputFile="%printer%Samsung M2020 Series" "c:\test.pdf"
I tried the above in other machine, but same result.
The following line prompts the print dialogue box which I don't want.
gswin32c.exe -sDEVICE=mswinpr2 -dBATCH -dNOPAUSE -dNoCancel -sOutputFile=\\spool "c:\test.pdf"
Is it possible to print silently using ghostscript?
thanks,

I installed GSView and this worked:
gsprint -noquery -all -printer "Samsung M2020 Series" "c:\scannedDocOnePage.pdf"

gswin32c.exe -sDEVICE=mswinpr2 -dBATCH -dNOPAUSE -sOutputFile="%printer%Samsung M2020 Series" file.pdf

I was able to get a silent print by removing -sOutputFile and use -dQueryUser=3 instead. This will always print to the default printer set up in control panel though.
"C:\Program Files\gs\gs9.52\bin\gswin64c.exe" -dNORANGEPAGESIZE -dPrinted -dNoCancel -dBATCH -dNOPAUSE -dNOSAFER -q -dNumCopies=1 -dQueryUser=3 -sDEVICE=mswinpr2 "mypdf.pdf"

Related

Cannot save kable to PDF due to error in magick_image_readpath

I am trying to save a table created in the Kable package in R Markdown. This has always worked for me in the past, but today when I try, using 'save_kable("X.pdf")' on any of my tables, I get the following error message:
Error in magick_image_readpath(enc2native(path), density, depth, strip) :
rsession: FailedToExecuteCommand `'gs' -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 '-sDEVICE=pngalpha' -dTextAlphaBits=4 -dGraphicsAlphaBits=4 '-r72x72' '-sOutputFile=/var/folders/qc/xs3g8dsx4g11rjbt0rf35dj00000gq/T//RtmpaRzbJq/magick-43640eHHAxmi4Z6n5%d' '-f/var/folders/qc/xs3g8dsx4g11rjbt0rf35dj00000gq/T//RtmpaRzbJq/magick-436404K7X59eUrjJR' '-f/var/folders/qc/xs3g8dsx4g11rjbt0rf35dj00000gq/T//RtmpaRzbJq/magick-43640Xy025Mi88F3t'' (1) # error/pdf.c/InvokePDFDelegate/292
I have restarted R Studio and tried again but it doesn't change anything. Does anyone know what this error message means or how to solve it?
I had the same problem. I resolved it by installing GhostScript on the machine.

Imagemagick FailedToExecuteCommand `"gswin32c.exe"

I am testing my file conversions on the test server and I got this error below. I tested the case on my local and it worked without a problem. On the server it gives me some trouble.
FailedToExecuteCommand `"gswin32c.exe" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g350x350 -dEPSCrop "-sOutputFile=C:/Windows/TEMP/magick-1520z9_ZtBD3O2dg%d" "-fC:/Windows/TEMP/magick-15203XcyD8hja0LJ" "-fC:/Windows/TEMP/magick-1520fnhOiV0JVLNJ"' (Le fichier spécifié est introuvable.) # error/delegate.c/ExternalDelegateCommand/475.convert:
Any help/tips would be greatly appreciated.
EDIT 2:
I also find a link where the imagemagick admin suggests to change the gs path in the delegates.xml. This solution looks promising but the delegate file has one entry for eps to ps conversions as below:
<delegate decode="eps" encode="ps" mode="bi" command=""#PSDelegate#" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 -sDEVICE=ps2write "-sOutputFile=%o" -- "%i""/>
And I can't seem to find how imagemagick refers to the GS location. I added gs to the path variable and/or modified the delegates.xml with the location to fix this.
EDIT 3:
I have a error "no images defined" from the imagemagick convert command as below. Do I need to set up some permissions for gs because I don't find the temporary folders in the Temp directory.These seems to work magically on my local, but hesitates to function on the test server.
convert: Postscript delegate failed [ghostscript library 9.22] -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g350x350 -dEPSCrop "-sOutputFile=C:/Windows/TEMP/magick-110207SjtG6NIBllO%d" "-fC:/Windows/TEMP/magick-1102057mSI5SPZ919" "-fC:/Windows/TEMP/magick-11020HeIOX7qThedE" -c showpage: (null)' # error/ps.c/ReadPSImage/884.convert: no images definedD:\inetpub\IndependenceAWS\Conversion_DEV_DCHI\78\20190208-121606-797-QSAX2N0OVB\JPG\icam_logo_ToJPG.JPG' # error/convert.c/ConvertImageCommand/3300
For the first problem,
FailedToExecuteCommand `"gswin32c.exe"
Configure the path of the ghostscript bin folder on the system variables and/or configure the delegates.xml which can be found in the folder path C:\Program Files\ImageMagick-7.0.8-Q16
Modify the delegate as below:
delegate decode="eps" encode="ps" mode="bi" command=""C:\Program
Files\gs\gs9.26\bin\gswin64.exe#" -q -dQUIET -dSAFER -dBATCH
-dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 -sDEVICE=ps2write "-sOutputFile=%o" -- "%i""
For the second problem where Imagemagick has problems to access the Temp folder of the C drive.
Add or uncomment the policy for the temporary file path as below
policy domain="resource" name="temporary-path"
value="D:/inetpub/IndependenceAWS/Conversion-Temp"/
Another edit in the same xml as below solves the problems and allows imagemagick to use the new folder for temporary conversions
policy domain="module" rights="read|write" pattern="{PS,PDF,XPS}"
A great thanks to all the people who have commented on my question and helped me solve these issues.
You need to install ghostscript.
You can download it here and install it and the error goes away.
For example, download the 64bit version, and double click it and go by its installation instructions. Then rerun your magick command, the FailedToExecuteCommand "gswin32c.exe" error will go away.
Note: as a comment mentioned: GS 9.26 has some bugs -- try downgrading to 9.23, 9.24 or 9.25. 3, using 9.27 produces neither errors nor output, but after changing to 9.24, all things are fine.
If anyone is having this issue with the MSYS2 build of ImageMagick, you need to install GhostScript through MSYS2: run either of:
on MSYS2 MinGW 64 bits: pacman -S mingw-w64-x86_64-ghostscript
on MSYS2 MinGW 32 bits: pacman -S mingw-w64-i686-ghostscript
Changed gs to full path.
Problem is here....
I know this is an old thread but I'd like to add my experience as it may help someone.
I was getting the same error as you, but for me the issue turned out to be not enough RAM.
This was running on a VM with not much RAM allocated, upgraded to 4GB and everything works great.

failed to execute command 'gs' when converting a single page of pdf to jpg in imagemagick

When I am executing the below command (to create thumbnail of a pdf file)
convert -density 300 'image.pdf' -colorspace RGB -resize '100x100^' -gravity north -extent 100x100 'image_thumbnail.jpg
I am getting the below error
convert: FailedToExecuteCommand `'gs' -sstdout=%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 '-sDEVICE=pngalpha' -dTextAlphaBits=4 -dGraphicsAlphaBits=4 '-r72x72' -dFirstPage=1 -dLastPage=1 '-sOutputFile=/tmp/magick-2243905865hWInyt6%d' '-f/tmp/magick-22439X8ArwDDJggvw' '-f/tmp/magick-22439Omw2cAWv3jxW'' (-1) # error/delegate.c/ExternalDelegateCommand/478.
Hi Prashant.
I had such an issue using node-pdf-image package. I had been investigating it for several days before I found the solution.
I tried to update the versions of ImageMagick and GhostScript, but it didn't help.
The only workaround I found was the next one: use GraphicsMagick and invoke the convert prefixed with gm - like gm convert [options].
But of course, this solution was acceptable for my stuff, and it depends on the task.

error message while converting pdf to jpg file

I am trying to convert a PDF file to jpg file, this is what I was doing and the related error message. What are the reasons for this kind of error?
magick convert -density 600 C:\Users\Desktop\temp.pdf C:\Users\Desktop\temp.jpg
convert: FailedToExecuteCommand `"gswin32c.exe" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r600x600" "-sOutputFile=C:/Users/ugwz/AppData/Local/Temp/magick-36562c7WhZLZFMM6%d" "-fC:/Users/ugwz/AppData/Local/Temp/magick-3656VktS46lP2HwZ" "-fC:/Users/ugwz/AppData/Local/Temp/magick-3656xOHiogtkf3t5"' (The system cannot find the file specified.
) # error/delegate.c/ExternalDelegateCommand/459.
convert: PDFDelegateFailed `The system cannot find the file specified.
' # error/pdf.c/ReadPDFImage/796.
convert: no images defined `C:\Users\Desktop\temp.jpg' # error/convert.c/ConvertImageCommand/3275.
To validate the existence of original file location, here is the output
C:\Users\Desktop>dir temp.pdf
Volume in drive C is Global Information Link
Volume Serial Number is 6646-37D4
Directory of C:\Users\Desktop
07/10/2018 01:55 PM 175,108 temp.pdf
1 File(s) 175,108 bytes
0 Dir(s) 12,942,802,944 bytes free

Prevent Ghostscript from writing errors to standard output

I'm using Ghostscript to rasterize the first page of a PDF file to JPEG. To avoid creating tempfiles, the PDF data is piped into Ghoscripts's stdin and the JPEG is "drained" on stdout. This pipeline works like a charm until GS receives invalid PDF data: Instead of reporting all error messages on stderr as I would have expected, it still writes some of the messages to stdout instead.
To reproduce:
$ echo "Not a PDF" >test.txt
$ /usr/bin/gs -q -sDEVICE=jpeg -dBATCH -dNOPAUSE -dFirstPage=1 -dLastPage=1 \
-r300 -sOutputFile=- - < test.txt 2>/dev/null
Error: /undefined in Not
Operand stack:
Execution stack:
...
Note the 2>/dev/null above does not suppress the error messages. Ghostscript's documentation already warned that writing to stdout requires the -q flag to suppress messages on stdout, but I still seem to be missing something here.
If you want to really silence Ghostscript, modify your command line like this:
/usr/bin/gs -q \
-sstdout=%stderr \
-sDEVICE=jpeg \
-dBATCH \
-dNOPAUSE \
-dLastPage=1 \
-r300 \
-sOutputFile=- \
- < test.txt 2>/dev/null
The addition of -sstdout=%stderr allows Postscript stdout to be redirected, while still allowing drivers to write to stdout. (That patch is in Ghostscript since ~2001, Sept 22.)

Resources