/// <summary> /// Sets the stdio and display device callback handlers. /// </summary> /// <param name="stdIO">Stdio callback handler.</param> /// <param name="displayDevice">DisplayDevice callback handler.</param> public void Setup(GhostscriptStdIO stdIO, GhostscriptDisplayDeviceHandler displayDevice) { // check if we need to set stdio handler if (stdIO != null) { // check if stdio handler is not already set if (_stdIO == null) { // GSAPI: set the stdio callback handlers int rc_stdio = _gs.gsapi_set_stdio(_gs_instance, stdIO != null ? stdIO._std_in : null, stdIO != null ? stdIO._std_out : null, stdIO != null ? stdIO._std_err : null); // check if the stdio callback handlers are set correctly if (ierrors.IsError(rc_stdio)) { throw new GhostscriptAPICallException("gsapi_set_stdio", rc_stdio); } // remember it _stdIO = stdIO; } else { throw new GhostscriptException("StdIO callback handler is already set."); } } // check if a custom display device needs to be used if (displayDevice != null) { // check if display device is already set if (_displayDevice == null) { // allocate a memory for the display device callback handler _displayDevice_callback_handle = Marshal.AllocCoTaskMem(displayDevice._callback.size); // copy display device callback structure content to the pre-allocated block of memory Marshal.StructureToPtr(displayDevice._callback, _displayDevice_callback_handle, true); // GSAPI: set the display device callback handler int rc_dev = _gs.gsapi_set_display_callback(_gs_instance, _displayDevice_callback_handle); // check if the display callback handler is set correctly if (ierrors.IsError(rc_dev)) { throw new GhostscriptAPICallException("gsapi_set_display_callback", rc_dev); } // remember it _displayDevice = displayDevice; } else { throw new GhostscriptException("DisplayDevice callback is already set!"); } } }
public void StartProcessing(GhostscriptDevice device, GhostscriptStdIO stdIO_callback) { if (device == null) { throw new ArgumentNullException("device"); } this.StartProcessing(device.GetSwitches(), stdIO_callback); }
public GhostscriptRasterizer(GhostscriptStdIO stdIo) { _viewer = new GhostscriptViewer(); _viewer.ShowPageAfterOpen = false; _viewer.ProgressiveUpdate = false; _viewer.DisplayPage += new GhostscriptViewerViewEventHandler(_viewer_DisplayPage); if (stdIo != null) { _viewer.AttachStdIO(stdIo); } }
public GhostscriptRasterizer(GhostscriptStdIO stdIo) { _viewer = new GhostscriptViewer(); _viewer.ShowPageAfterOpen = false; _viewer.ProgressiveUpdate = false; _viewer.DisplayPage += new GhostscriptViewerViewEventHandler(_viewer_DisplayPage); if (stdIo != null) { _viewer.AttachStdIO(stdIo); } }
/// <summary> /// Run Ghostscript. /// </summary> /// <param name="args">Command arguments</param> /// <param name="stdIO_callback">StdIO callback, can be set to null if you dont want to handle it.</param> public void Process(string[] args, GhostscriptStdIO stdIO_callback) { IntPtr instance = IntPtr.Zero; int rc_ins = _gs.gsapi_new_instance(out instance, IntPtr.Zero); if (ierrors.IsError(rc_ins)) { throw new GhostscriptAPICallException("gsapi_new_instance", rc_ins); } try { _stdIO_Callback = stdIO_callback; _internalStdIO_Callback = new GhostscriptProcessorInternalStdIOHandler( new StdInputEventHandler(OnStdIoInput), new StdOutputEventHandler(OnStdIoOutput), new StdErrorEventHandler(OnStdIoError)); int rc_stdio = _gs.gsapi_set_stdio(instance, _internalStdIO_Callback._std_in, _internalStdIO_Callback._std_out, _internalStdIO_Callback._std_err); if (ierrors.IsError(rc_stdio)) { throw new GhostscriptAPICallException("gsapi_set_stdio", rc_stdio); } int rc_init = _gs.gsapi_init_with_args(instance, args.Length, args); if (ierrors.IsErrorIgnoreQuit(rc_init)) { throw new GhostscriptAPICallException("gsapi_init_with_args", rc_init); } int rc_exit = _gs.gsapi_exit(instance); if (ierrors.IsErrorIgnoreQuit(rc_exit)) { throw new GhostscriptAPICallException("gsapi_exit", rc_exit); } } finally { _gs.gsapi_delete_instance(instance); } }
public void Setup(GhostscriptStdIO stdIO, GhostscriptDisplayDevice displayDevice) { if (stdIO != null) { if (_stdIO == null) { int rc_stdio = _gs.gsapi_set_stdio(_gs_instance, stdIO != null ? stdIO._std_in : null, stdIO != null ? stdIO._std_out : null, stdIO != null ? stdIO._std_err : null); if (ierrors.IsError(rc_stdio)) { throw new GhostscriptAPICallException("gsapi_set_stdio", rc_stdio); } _stdIO = stdIO; } else { throw new GhostscriptException("StdIO callback is already set!"); } } if (displayDevice != null) { if (_displayDevice == null) { _displayDevice_callback_handle = Marshal.AllocCoTaskMem(displayDevice._callback.size); Marshal.StructureToPtr(displayDevice._callback, _displayDevice_callback_handle, true); int rc_dev = _gs.gsapi_set_display_callback(_gs_instance, _displayDevice_callback_handle); if (ierrors.IsError(rc_dev)) { throw new GhostscriptAPICallException("gsapi_set_display_callback", rc_dev); } _displayDevice = displayDevice; } else { throw new GhostscriptException("DisplayDevice callback is already set!"); } } }
public void AttachStdIO(GhostscriptStdIO stdIoCallback) { _stdIoCallback = stdIoCallback; }
/// <summary> /// Run Ghostscript. /// </summary> /// <param name="args">Command arguments</param> /// <param name="stdIO_callback">StdIO callback, can be set to null if you dont want to handle it.</param> public void StartProcessing(string[] args, GhostscriptStdIO stdIO_callback) { if (args == null) { throw new ArgumentNullException("args"); } if (args.Length < 3) { throw new ArgumentOutOfRangeException("args"); } for (int i = 0; i < args.Length; i++) { args[i] = System.Text.Encoding.Default.GetString(System.Text.Encoding.UTF8.GetBytes(args[i])); } _isRunning = true; IntPtr instance = IntPtr.Zero; int rc_ins = _gs.gsapi_new_instance(out instance, IntPtr.Zero); if (ierrors.IsError(rc_ins)) { throw new GhostscriptAPICallException("gsapi_new_instance", rc_ins); } try { _stdIO_Callback = stdIO_callback; _internalStdIO_Callback = new GhostscriptProcessorInternalStdIOHandler( new StdInputEventHandler(OnStdIoInput), new StdOutputEventHandler(OnStdIoOutput), new StdErrorEventHandler(OnStdIoError)); int rc_stdio = _gs.gsapi_set_stdio(instance, _internalStdIO_Callback._std_in, _internalStdIO_Callback._std_out, _internalStdIO_Callback._std_err); _poolCallBack = new gsapi_pool_callback(Pool); int rc_pool = _gs.gsapi_set_poll(instance, _poolCallBack); if (ierrors.IsError(rc_pool)) { throw new GhostscriptAPICallException("gsapi_set_poll", rc_pool); } if (ierrors.IsError(rc_stdio)) { throw new GhostscriptAPICallException("gsapi_set_stdio", rc_stdio); } this.OnStarted(new GhostscriptProcessorEventArgs()); _stopProcessing = false; if (_gs.is_gsapi_set_arg_encoding_supported) { int rc_enc = _gs.gsapi_set_arg_encoding(instance, GS_ARG_ENCODING.UTF8); } int rc_init = _gs.gsapi_init_with_args(instance, args.Length, args); if (ierrors.IsErrorIgnoreQuit(rc_init)) { if (!ierrors.IsInterrupt(rc_init)) { throw new GhostscriptAPICallException("gsapi_init_with_args", rc_init); } } int rc_exit = _gs.gsapi_exit(instance); if (ierrors.IsErrorIgnoreQuit(rc_exit)) { throw new GhostscriptAPICallException("gsapi_exit", rc_exit); } } finally { _gs.gsapi_delete_instance(instance); GC.Collect(); _isRunning = false; this.OnCompleted(new GhostscriptProcessorEventArgs()); } }
public void StartProcessing(GhostscriptDevice device, GhostscriptStdIO stdIO_callback) { if (device == null) { throw new ArgumentNullException("device"); } this.StartProcessing(device.GetSwitches(), stdIO_callback); }
public void Process(string[] args, GhostscriptStdIO stdIO_callback) { this.StartProcessing(args, stdIO_callback); }
public void Process(GhostscriptDevice device, GhostscriptStdIO stdIO_callback) { this.StartProcessing(device, stdIO_callback); }
/// <summary> /// Run Ghostscript. /// </summary> /// <param name="args">Command arguments</param> /// <param name="stdIO_callback">StdIO callback, can be set to null if you dont want to handle it.</param> public void StartProcessing(string[] args, GhostscriptStdIO stdIO_callback) { if (args == null) { throw new ArgumentNullException("args"); } if (args.Length < 3) { throw new ArgumentOutOfRangeException("args"); } for (int i = 0; i < args.Length; i++) { args[i] = System.Text.Encoding.Default.GetString(System.Text.Encoding.UTF8.GetBytes(args[i])); } _isRunning = true; IntPtr instance = IntPtr.Zero; int rc_ins = _gs.gsapi_new_instance(out instance, IntPtr.Zero); if (ierrors.IsError(rc_ins)) { throw new GhostscriptAPICallException("gsapi_new_instance", rc_ins); } try { _stdIO_Callback = stdIO_callback; _internalStdIO_Callback = new GhostscriptProcessorInternalStdIOHandler( new StdInputEventHandler(OnStdIoInput), new StdOutputEventHandler(OnStdIoOutput), new StdErrorEventHandler(OnStdIoError)); int rc_stdio = _gs.gsapi_set_stdio(instance, _internalStdIO_Callback._std_in, _internalStdIO_Callback._std_out, _internalStdIO_Callback._std_err); _poolCallBack = new gsapi_pool_callback(Pool); int rc_pool = _gs.gsapi_set_poll(instance, _poolCallBack); if (ierrors.IsError(rc_pool)) { throw new GhostscriptAPICallException("gsapi_set_poll", rc_pool); } if (ierrors.IsError(rc_stdio)) { throw new GhostscriptAPICallException("gsapi_set_stdio", rc_stdio); } this.OnStarted(new GhostscriptProcessorEventArgs()); _stopProcessing = false; if (_gs.is_gsapi_set_arg_encoding_supported) { int rc_enc = _gs.gsapi_set_arg_encoding(instance, GS_ARG_ENCODING.UTF8); } int rc_init = _gs.gsapi_init_with_args(instance, args.Length, args); if (ierrors.IsErrorIgnoreQuit(rc_init)) { if (!ierrors.IsInterrupt(rc_init)) { throw new GhostscriptAPICallException("gsapi_init_with_args", rc_init); } } int rc_exit = _gs.gsapi_exit(instance); if (ierrors.IsErrorIgnoreQuit(rc_exit)) { throw new GhostscriptAPICallException("gsapi_exit", rc_exit); } } finally { _gs.gsapi_delete_instance(instance); GC.Collect(); _isRunning = false; this.OnCompleted(new GhostscriptProcessorEventArgs()); } }
public void Process(string[] args, GhostscriptStdIO stdIO_callback) { this.StartProcessing(args, stdIO_callback); }
public void Process(GhostscriptDevice device, GhostscriptStdIO stdIO_callback) { this.StartProcessing(device, stdIO_callback); }
public void AttachStdIO(GhostscriptStdIO stdIoCallback) { _stdIoCallback = stdIoCallback; }
/// <summary> /// Sets the stdio and display device callback handlers. /// </summary> /// <param name="stdIO">Stdio callback handler.</param> /// <param name="displayDevice">DisplayDevice callback handler.</param> public void Setup(GhostscriptStdIO stdIO, GhostscriptDisplayDeviceHandler displayDevice) { // check if we need to set stdio handler if (stdIO != null) { // check if stdio handler is not already set if (_stdIO == null) { // GSAPI: set the stdio callback handlers int rc_stdio = _gs.gsapi_set_stdio(_gs_instance, stdIO != null ? stdIO._std_in : null, stdIO != null ? stdIO._std_out : null, stdIO != null ? stdIO._std_err : null); // check if the stdio callback handlers are set correctly if (ierrors.IsError(rc_stdio)) { throw new GhostscriptAPICallException("gsapi_set_stdio", rc_stdio); } // remember it _stdIO = stdIO; } else { throw new GhostscriptException("StdIO callback handler is already set."); } } // check if a custom display device needs to be used if (displayDevice != null) { // check if display device is already set if (_displayDevice == null) { // allocate a memory for the display device callback handler _displayDevice_callback_handle = Marshal.AllocCoTaskMem(displayDevice._callback.size); // copy display device callback structure content to the pre-allocated block of memory Marshal.StructureToPtr(displayDevice._callback, _displayDevice_callback_handle, true); // GSAPI: set the display device callback handler int rc_dev = _gs.gsapi_set_display_callback(_gs_instance, _displayDevice_callback_handle); // check if the display callback handler is set correctly if (ierrors.IsError(rc_dev)) { throw new GhostscriptAPICallException("gsapi_set_display_callback", rc_dev); } // remember it _displayDevice = displayDevice; } else { throw new GhostscriptException("DisplayDevice callback is already set!"); } } }
/// <summary> /// Run Ghostscript. /// </summary> /// <param name="args">Command arguments</param> /// <param name="stdIO_callback">StdIO callback, can be set to null if you dont want to handle it.</param> public void StartProcessing(string[] args, GhostscriptStdIO stdIO_callback = null) { if (args == null) { throw new ArgumentNullException("args"); } if (args.Length < 3) { throw new ArgumentOutOfRangeException("args"); } for (int i = 0; i < args.Length; i++) { args[i] = System.Text.Encoding.Default.GetString(System.Text.Encoding.UTF8.GetBytes(args[i])); } _isRunning = true; IntPtr instance = IntPtr.Zero; int rc_ins = _gs.gsapi_new_instance(out instance, IntPtr.Zero); if (ierrors.IsError(rc_ins)) { throw new GhostscriptAPICallException("gsapi_new_instance", rc_ins, _internalStdIO_Callback); } try { _stdIO_Callback = stdIO_callback; _internalStdIO_Callback = new GhostscriptProcessorInternalStdIOHandler( new StdInputEventHandler(OnStdIoInput), new StdOutputEventHandler(OnStdIoOutput), new StdErrorEventHandler(OnStdIoError)); int rc_stdio = _gs.gsapi_set_stdio(instance, _internalStdIO_Callback._std_in, _internalStdIO_Callback._std_out, _internalStdIO_Callback._std_err); _poolCallBack = new gsapi_pool_callback(Pool); int rc_pool = _gs.gsapi_set_poll(instance, _poolCallBack); if (ierrors.IsError(rc_pool)) { throw new GhostscriptAPICallException("gsapi_set_poll", rc_pool, _internalStdIO_Callback); } if (ierrors.IsError(rc_stdio)) { throw new GhostscriptAPICallException("gsapi_set_stdio", rc_stdio, _internalStdIO_Callback); } this.OnStarted(new GhostscriptProcessorEventArgs()); _stopProcessing = false; if (_gs.is_gsapi_set_arg_encoding_supported) { int rc_enc = _gs.gsapi_set_arg_encoding(instance, GS_ARG_ENCODING.UTF8); } int rc_init = _gs.gsapi_init_with_args(instance, args.Length, args); if (ierrors.IsErrorIgnoreQuit(rc_init)) { if (!ierrors.IsInterrupt(rc_init)) { throw new GhostscriptAPICallException("gsapi_init_with_args", rc_init, _internalStdIO_Callback); } } } finally { // gsapi_exit() : // // Exit the interpreter. This MUST be called on shutdown if gsapi_init_with_args() has been called, and just before gsapi_delete_instance(). // // ^^^ that's from the docs at https://ghostscript.com/doc/9.52/API.htm#exit (emphasis mine): it's placed in the `finally` clause // section here to ensure it is called when rc_init == e_Fatal (or other error) occurs and throws an exception in the code chunk above. try { int rc_exit = _gs.gsapi_exit(instance); if (ierrors.IsErrorIgnoreQuit(rc_exit)) { throw new GhostscriptAPICallException("gsapi_exit", rc_exit, _internalStdIO_Callback); } } finally { _gs.gsapi_delete_instance(instance); GC.Collect(); _isRunning = false; this.OnCompleted(new GhostscriptProcessorEventArgs()); } } }