def main(argv): code = 1 use_gui, _ = Gtk.init_check(argv) # insert display device parameters as first arguments # this controls the format of the pixbuf that ghostscript will deliver # see display_sync for details # fast CAIRO_FORMAT_RGB24 = gs.DISPLAY_COLORS_RGB | gs.DISPLAY_UNUSED_LAST | \ gs.DISPLAY_DEPTH_8 | gs.DISPLAY_LITTLEENDIAN # interesting SEPARATION_FORMAT = gs.DISPLAY_COLORS_SEPARATION | gs.DISPLAY_ALPHA_NONE | \ gs.DISPLAY_DEPTH_8 | gs.DISPLAY_BIGENDIAN # if there are spot colors they are mixed into the cmyk values CMYK_FORMAT = gs.DISPLAY_COLORS_CMYK | gs.DISPLAY_ALPHA_NONE | \ gs.DISPLAY_DEPTH_8 | gs.DISPLAY_BIGENDIAN dformat = "-dDisplayFormat=%d" % \ ( CAIRO_FORMAT_RGB24 | gs.DISPLAY_TOPFIRST ) nargv = [argv[0], dformat] + argv[1:] #run Ghostscript try: instance = gs.new_instance() gs.set_stdio(instance, gsdll_stdin, gsdll_stdout, gsdll_stderr) if use_gui: gs.set_display_callback(instance, c.byref(display)) code = gs.init_with_args(instance, nargv) if code == 0: code = gs.run_string(instance, start_string) code1 = gs.exit(instance) if code == 0 or code == gs.e_Quit: code = code1 if code == gs.e_Quit: code = 0 # user executed 'quit' gs.delete_instance(instance) except gs.GhostscriptError as e: code = e.code sys.stderr.write(e.message) finally: exit_status = 0; if code in [0, gs.e_Info, gs.e_Quit]: pass elif code == gs.e_Fatal: exit_status = 1 else: exit_status = 255 return exit_status
# # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # __author__ = "Hartmut Goebel <*****@*****.**>" __copyright__ = "Copyright 2010 by Hartmut Goebel <*****@*****.**>" __licence__ = "GNU General Public License version 3 (GPL v3)" __credits__ = "Based on an example from http://www.ghostscript.com/doc/8.63/API.htm" import sys from ghostscript import _gsprint as gs start_string = "systemdict /start get exec\n" instance = gs.new_instance() # set_stdio() is not yet implemented #gs.set_stdio(isntance, gsdll_stdin, gsdll_stdout, gsdll_stderr) code = gs.init_with_args(instance, sys.argv) if code == 0: code = gs.run_string(instance, start_string) code1 = gs.exit(instance) if code == 0 or code == gs.e_Quit: code = code1 gs.delete_instance(instance) if not (code == 0 or code == gs.e_Quit): sys.exit(1)
# General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # __author__ = "Hartmut Goebel <*****@*****.**>" __copyright__ = "Copyright 2010 by Hartmut Goebel <*****@*****.**>" __licence__ = "GNU General Public License version 3 (GPL v3)" __credits__ = "Based on an example from http://www.ghostscript.com/doc/8.63/API.htm" import sys from ghostscript import _gsprint as gs start_string = "systemdict /start get exec\n" instance = gs.new_instance() # set_stdio() is not yet implemented #gs.set_stdio(isntance, gsdll_stdin, gsdll_stdout, gsdll_stderr) code = gs.init_with_args(instance, sys.argv) if code == 0: code = gs.run_string(instance, start_string) code1 = gs.exit(instance) if code == 0 or code == gs.e_Quit: code = code1 gs.delete_instance(instance) if not (code == 0 or code == gs.e_Quit): sys.exit(1)