Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert file.pdf file.png does not work on Windows (because of a Ghostscript mismatch) #198

Open
Krastanov opened this issue Mar 5, 2021 · 6 comments

Comments

@Krastanov
Copy link

Krastanov commented Mar 5, 2021

Edit: Ghostscript is now packaged and convert file.pdf file.png works on most platforms.

Original Message:

I was pleased to see that convert from ImageMagic_jll is so easy to use from inside of Julia. However, for converting pdf to png, it shells out to gs. I am attempting to package gs with BinaryBuilder. I am a novice into this and given that gs would be of use to this package, I was hoping someone could help me with fleshing out the various issues with the gs package. Here is a link to the current build_tarballs pull request: JuliaPackaging/Yggdrasil#2646

@Krastanov Krastanov changed the title convert file.pdf file.png requires Ghostscript convert file.pdf file.png does not work on Windows (because of a Ghostscript mismatch) Mar 7, 2021
@Krastanov
Copy link
Author

So, Ghostscript is now packaged https://juliahub.com/ui/Packages/Ghostscript_jll/A26Vb/9.53.3+0

convert works on Linux and Mac, but not on Windows. There is an issue with path finding for some of the configuration files.

To perform a conversion one needs both gs and convert in their PATH:

        gs() do gsbin
            imagemagick_convert() do bin
                run(`$bin input.pdf output.png`)
            end
        end

However, on Windows the following exception arises inside of convert:

convert.exe: UnableToOpenConfigureFile `delegates.xml' @ warning/configure.c/GetConfigureOptions/712.
convert.exe: FailedToExecuteCommand `"gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r500x500"  "-sOutputFile=C:/Users/RUNNER~1/AppData/Local/Temp/magick-2484CLvqAlSS92c3%d" "-fC:/Users/RUNNER~1/AppData/Local/Temp/magick-2484DuTJpe1QBI6D" "-fC:/Users/RUNNER~1/AppData/Local/Temp/magick-2484Jerj24FzP5tM"' (The system cannot find the file specified.

) @ error/delegate.c/ExternalDelegateCommand/459.
convert.exe: PDFDelegateFailed `The system cannot find the file specified.

' @ error/pdf.c/ReadPDFImage/811.

I think this is a problem with the ImageMagick_jll package, but I am not quite certain.

Here are test runs that show this code running on Linux and Mac, but not on Windows: https://github.com/Krastanov/Quantikz/runs/2048488216

Any insight and suggestions on where to debug would be greatly appreciated! Is this as simple as adding Ghostscript_jll as a dependency to ImageMagick_jll? I do not have a Windows machine so it is rather difficult for me to run tests.

@Krastanov

This comment has been minimized.

@Krastanov
Copy link
Author

Sigh, I was wrong in the above comment. The only reason FileIO worked was because I have ghostscript installed on my local machine. CI tests still fail. Ghostscript_jll solves this for Linux and Mac, but I am still open to suggestions for how to do it on Windows.

@Krastanov
Copy link
Author

Here is a simplified version of the bug report:

load("file.pdf") does not work without ghostscript installed on the system.

However, with Ghostscript_jll this works:

using Ghostscript_jll
gs() do bin # adds gs to the PATH
    load("file.pdf")
end

The issue is that it works only on Mac and Linux. On Windows, the convert.exe command fails to find the delegate file (as shown in the detailed error message in a previous comment). This can also be seen in these CI logs https://github.com/Krastanov/Quantikz/runs/2048843301

Krastanov added a commit to QuantumSavory/Quantikz.jl that referenced this issue Mar 7, 2021
@Krastanov
Copy link
Author

I was able to run convert -debug configure input.pdf output.png on the Windows CI and it seems part of the problem might be that some of the required configuration files in ImageMagick_jll are placed in the wrong location on Windows.

convert.exe looks for the file in C:\Users\runneradmin\.julia\artifacts\617bbb3e9d12da4f4910335239ea94e523ebd4aa\bin\delegates.xml while the file is actually in ...\etc. But at the end it seems it just runs with some default built-in assumption even if the file is not found. Then, when gs is being invoked inside of convert the command crashes.

Here is the CI log for

        gs() do bin
	    imagemagick_convert() do convert
	        run(`$convert -debug configure input.pdf out.png`)
	    end
        end

https://github.com/Krastanov/Quantikz/pull/1/checks?check_run_id=2049224946

@Krastanov
Copy link
Author

A workaround might be to stop worrying about ImageMagick_jll and just use Ghostscript_jll directly when converting a pdf to other formats (ImageMagick does not really do anything here anyway https://stackoverflow.com/a/36137513 ).

Krastanov added a commit to QuantumSavory/Quantikz.jl that referenced this issue Mar 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant