GhostScript File Path in ImageMagick

I am trying to use ImageMagick to convert PDF files to PNG on PC and OSX, but I cannot actually install GhostScript on any of the computers that will use my software.

Is there a way to associate GhostScript with ImageMagick and just redirect ImageMagick's path to this package, so I can use it without officially “installing” it on a user computer?

I found this page , but I can’t figure out how you can change the delegates.xml file in ImageMagick so that it works correctly. I understand that I need to change part of this line:

<delegate decode="pdf" encode="eps" mode="bi" command=""@ PSDelegate@ " -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop -sDEVICE=epswrite "-sOutputFile=%o" -- "%i"" /> 

but I'm not sure what to do - where to insert the path or which path should be based on --- the location of ImageMagick or something else? Any help would be greatly appreciated.

UPDATE v1.2: I tried changing the delegate above to the following, with an executable on the command line:

  <delegate decode="pdf" encode="eps" mode="bi" command="&quot;F:\ImageMagickTest\ImageMagick\gs\bin\gswin32c.exe&quot; -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop -sDEVICE=epswrite &quot;-sOutputFile=%o&quot; -- &quot;%i&quot;"/> 

but when I run the program, I get the following error at the cmd prompt:

 Microsoft Windows XP [Version 5.1.2600] 

(C) Copyright 1985-2001 Microsoft Corp.

 F:\Documents and Settings\Administrator>F:\ImageMagickTest\ImageMagick\convert.e xe F:\ImageMagickTest\PDFs\Appointment.pdf F:\ImageMagickTest\ConvertedPDFs\Appo intment.png convert.exe: `%s' (%d) "F:/ImageMagickTest/ImageMagick/gs9.06/bin/gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -d EPSCrop -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -d GraphicsAlphaBits=4 "-r72x72" "-sOutputFile=F:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/ magick-5996ZNQmVN7RFumY--0000001" "-fF:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/magick-5 996r7pmg8XgvrNB" "-fF:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/magick-5996yhTQgwoLswnn" @ error/utility.c/SystemCommand/1890. convert.exe: Postscript delegate failed `F:\ImageMagickTest\PDFs\Appointment.pdf ': No such file or directory @ error/pdf.c/ReadPDFImage/679. convert.exe: no images defined `F:\ImageMagickTest\ConvertedPDFs\Appointment.png ' @ error/convert.c/ConvertImageCommand/3044. 

It seems to me that this indicates that he does not find the file "Appointment.pdf". But it is there. What am I not rattling?

For fun, here is the full gs path taken from Windows Explorer:

 F:\ImageMagickTest\ImageMagick\gs\bin\gswin32c.exe 

For even more fun, here is the C # script that calls it from the Unity 3D application (I am not getting any errors):

  string currDir = System.Environment.CurrentDirectory; string convertPath = currDir + @"\ImageMagick\convert.exe"; string convertedDir = currDir + @"\ConvertedPDFs\"; string pdfFolder = currDir + @"\PDFs\"; string fileName = "Appointment"; string argumentForImageMagick; argumentForImageMagick = pdfFolder + fileName + ".pdf" + " " + convertedDir + fileName + ".png"; ProcessStartInfo info = new ProcessStartInfo {Arguments = argumentForImageMagick , FileName = convertPath}; System.Diagnostics.Process.Start(info).WaitForInputIdle(); 
+4
source share
4 answers

Try replacing the ""@PSDelegate" -q this line with "/usr/local/bin/gs -q (or any other path that you are going to install Ghostscript executables for).

Depending on your environment, you may need to add additional parameters to this command / line that tells gs (on Windows: gswin32c.exe or gswin64c.exe ) where its libraries should be found:
-I/usr/local/share/ghostscript/9.06/lib/


Update:. Try running this Ghostscript command directly in the cmd.exe window to see if it works (or what errors it occurs):

 "F:/ImageMagickTest/ImageMagick/gs9.06/bin/gswin32c.exe" \ -o F:/ImageMagickTest/PDFs/test.png \ -dEPSCrop \ -dAlignToPixels=0 \ -dGridFitTT=2 \ -sDEVICE=pngalpha \ -dTextAlphaBits=4 \ -dGraphicsAlphaBits=4 \ -r72 \ F:/ImageMagickTest/PDFs/Appointment.pdf 

Don't worry about my use of slashes ('/') as directory separators - Ghostscript on Windows can handle them just fine.

I hope your installation of Ghostscript will be the latest version (otherwise it will not understand the -o syntax for the output file).

If this command does not work, you should see some error message in the window (because I skipped the -q -dQUIET ).

Ghostscript is probably not finding its libraries, because you may have only copied the .exe file and not installed the full package correctly.

Perhaps you need to add -I"F:/ImageMagickTest/ImageMagick/gs9.06/lib" or something similar to the command line (I don't know if your Ghostscript /lib directory really was just a hunch!):

 "F:/ImageMagickTest/ImageMagick/gs9.06/bin/gswin32c.exe" \ -o F:/ImageMagickTest/PDFs/test.png \ -I"F:/ImageMagickTest/ImageMagick/gs9.06/lib" \ -dEPSCrop \ -dAlignToPixels=0 \ -dGridFitTT=2 \ -sDEVICE=pngalpha \ -dTextAlphaBits=4 \ -dGraphicsAlphaBits=4 \ -r72 \ F:/ImageMagickTest/PDFs/Appointment.pdf 

You should continue with changing the line in the delegates.xml file after you manage to run Ghostscript directly in the cmd.exe window.

+1
source

I had the same problem with this attempt to use ImageMagick and GhostScript on a computer without administrator rights (using portable versions of both). Got an error trying to manually set the path to GhostScript in the delegates.xml file, trying to put hidden PDF files in TIFF.

I found a solution to replace all instances of "@PSDelegate" with the full path, for example: &quot;C:\<path_to_exec>\gswin32c.exe&quot; in the delegates.xml file, not just a specific PDF line. After that, he did a great job.

This is possible because GhostScript is also used for other formats and may depend on other instances of "@PSDelegate" in the delegates.xml file when converting the PDF file.

+1
source

I also got a Postscript delegate failed message when starting ImageMagick to read a PDF. The problem is caused by ImageMagick reading one of the following registry entries (in SOFTAWRE) to get the path to the gs executable on Windows.

  • GPL Ghostscript
  • GNU Ghostscript
  • AFPL Ghostscript
  • Aladdin ghostscript

The problem was that the very old version of the Ghost script installed on the user's computer was pointed out and the PDF could not be converted to an image.

The solution was to remove the offensive ancient package from the computer or update the delegates.xml file to explicitly point to the gs executable file sent.

0
source

I had the same problem and none of the answers helped. It turned out that there was a 32-bit version of ImageMagick and a 64-bit version of GhostScript that did not play well. So we removed the 64-bit GhostScript and installed the 32-bit version instead, and it worked fine after the paths in the delegates.xml file ended

0
source

Source: https://habr.com/ru/post/1445008/


All Articles