diff --git a/camelot/backends/ghostscript_backend.py b/camelot/backends/ghostscript_backend.py index e0c2f42..cba3e83 100644 --- a/camelot/backends/ghostscript_backend.py +++ b/camelot/backends/ghostscript_backend.py @@ -1,10 +1,40 @@ # -*- coding: utf-8 -*- +import sys +import ctypes +from ctypes.util import find_library + import ghostscript +def installed_posix(): + library = find_library("gs") + return library is not None + + +def installed_windows(): + library = find_library( + "".join(("gsdll", str(ctypes.sizeof(ctypes.c_voidp) * 8), ".dll")) + ) + return library is not None + + class GhostscriptBackend(object): + def installed(self): + if sys.platform in ["linux", "darwin"]: + return installed_posix() + elif sys.platform == "win32": + return installed_windows() + else: + return installed_posix() + def convert(self, pdf_path, png_path, resolution=300): + if not self.installed(): + raise OSError( + "Ghostscript is not installed. Please install it using the instructions" + "here: https://camelot-py.readthedocs.io/en/master/user/install-deps.html" + ) + gs_args = [ "gs", "-q",