diff options
Diffstat (limited to 'doc/language-bindings')
43 files changed, 9154 insertions, 0 deletions
diff --git a/doc/language-bindings/c-sharp-ghost-api.html b/doc/language-bindings/c-sharp-ghost-api.html new file mode 100644 index 00000000..b98732af --- /dev/null +++ b/doc/language-bindings/c-sharp-ghost-api.html @@ -0,0 +1,475 @@ +<html lang="en"> + <head> + <title>Ghostscript language bindings</title> + <meta http-equiv="content-type" content="text/html; charset=utf-8"> + <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width"> + <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:200,200i,300,300i,400,400i,600,600i,700,700i,900,900i" rel="stylesheet"> + <link rel="shortcut icon" type="image/png" href="../images/favicon.png"> + <link href="css/default.css" rel="stylesheet" type="text/css" /> + <script type="text/javascript" src="js/default.js"></script> + </head> + + <body> + + <header><h1></h1><div class="menu-icon" onclick="javascript:showMenu();"></div></header> + + <div id="burger-menu"> + <div class="navigation"> + <div class="title first">Introduction</div> + <div class="link"><a href="index.html">About our APIs</a></div> + <div class="link"><a href="demo-code.html">Demo code</a></div> + + <div class="title">C#</div> + <div class="link"><a href="c-sharp-intro.html">Overview</a></div> + <div class="link selected"><a href="c-sharp-ghost-api.html">GhostAPI</a></div> + <div class="link"><a href="c-sharp-ghost-net.html">GhostNET</a></div> + <div class="link"><a href="c-sharp-ghost-mono.html">GhostMono</a></div> + + <div class="title">Java</div> + <div class="link"><a href="java-intro.html">Overview</a></div> + <div class="link"><a href="java-gsjavajar.html">gsjava.jar</a></div> + + <div class="title">Python</div> + <div class="link"><a href="python-intro.html">Overview</a></div> + <div class="link"><a href="python-gsapi.html">gsapi.py</a></div> + </div> + </div> + <div class="main"> + + <div class="left"> + <div class="title first">Introduction</div> + <div class="link"><a href="index.html">About our APIs</a></div> + <div class="link"><a href="demo-code.html">Demo code</a></div> + + <div class="title">C#</div> + <div class="link"><a href="c-sharp-intro.html">Overview</a></div> + <div class="link selected"><a href="c-sharp-ghost-api.html">GhostAPI</a></div> + <div class="link"><a href="c-sharp-ghost-net.html">GhostNET</a></div> + <div class="link"><a href="c-sharp-ghost-mono.html">GhostMono</a></div> + + <div class="title">Java</div> + <div class="link"><a href="java-intro.html">Overview</a></div> + <div class="link"><a href="java-gsjavajar.html">gsjava.jar</a></div> + + <div class="title">Python</div> + <div class="link"><a href="python-intro.html">Overview</a></div> + <div class="link"><a href="python-gsapi.html">gsapi.py</a></div> + + </div> + + <div class="middle"> + +<!-- note: don't tab indent <article> as it has <pre> code which will have its layout adversly affected --> +<article class="markdown-body entry-content"><h1 id="ghostapi">GhostAPI</h1> +<div class="banner"> + <div class="c-sharp-text"></div> + <div class="vendor-logo c-sharp-logo"></div> +</div> + + +<h2 id="about">About</h2> +<p><code>GhostAPI</code> is the <code>C#</code> bridge into the Ghostscript <code>C</code> library.</p> +<p><code>GhostAPI</code> contains some essential <a href="#structs-and-enums">structs & enums</a> as well as a static class for some <a href="#constants">constants</a>, finally it contains the main <a href="#gsapi">GSAPI</a> class which holds the key methods which interface with the <code>C</code> library.</p> +<h2 id="structs-and-enums">Structs and Enums</h2> +<h3 id="gsapi_revision_t">gsapi_revision_t</h3> +<p>This <code>struct</code> is used to contain information pertinent to the version of Ghostscript.</p> +<div class="tag structDefinition csharp"></div> + +<pre><code class="language-c">public struct gsapi_revision_t +{ + public IntPtr product; + public IntPtr copyright; + public int revision; + public int revisiondate; +}</code></pre> +<h3 id="gs_set_param_type">gs_set_param_type</h3> +<div class="tag enumDefinition csharp"></div> + +<pre><code class="language-c">public enum gs_set_param_type +{ + gs_spt_invalid = -1, + gs_spt_null = 0, /* void * is NULL */ + gs_spt_bool = 1, /* void * is NULL (false) or non-NULL (true) */ + gs_spt_int = 2, /* void * is a pointer to an int */ + gs_spt_float = 3, /* void * is a float * */ + gs_spt_name = 4, /* void * is a char * */ + gs_spt_string = 5, /* void * is a char * */ + gs_spt_long = 6, /* void * is a long * */ + gs_spt_i64 = 7, /* void * is an int64_t * */ + gs_spt_size_t = 8, /* void * is a size_t * */ + gs_spt_parsed = 9, /* void * is a pointer to a char * to be parsed */ + gs_spt_more_to_come = 1 << 31 +};</code></pre> +<h3 id="gsencoding">gsEncoding</h3> +<div class="tag enumDefinition csharp"></div> + + +<pre><code class="language-c">public enum gsEncoding +{ + GS_ARG_ENCODING_LOCAL = 0, + GS_ARG_ENCODING_UTF8 = 1, + GS_ARG_ENCODING_UTF16LE = 2 +};</code></pre> +<h2 id="constants">Constants</h2> +<p>Constants are stored in the static class <code>gsConstants</code> for direct referencing.</p> +<h3 id="gsconstants">gsConstants</h3> +<div class="tag classDefinition csharp"></div> + +<pre><code class="language-c">static class gsConstants +{ + public const int E_QUIT = -101; + public const int GS_READ_BUFFER = 32768; + public const int DISPLAY_UNUSED_LAST = (1 << 7); + public const int DISPLAY_COLORS_RGB = (1 << 2); + public const int DISPLAY_DEPTH_8 = (1 << 11); + public const int DISPLAY_LITTLEENDIAN = (1 << 16); + public const int DISPLAY_BIGENDIAN = (0 << 16); +}</code></pre> +<h2 id="gsapi">GSAPI</h2> +<p>Methods contained within are explained below.</p> +<p><code>gsapi_run_*</code> and <code>gsapi_exit</code> methods return an <code>int</code> code which can be interpreted as follows:</p> +<table> +<thead> +<tr> +<th>code</th> +<th>status</th> +</tr> +</thead> +<tbody><tr> +<td><code>0</code></td> +<td>no error</td> +</tr> +<tr> +<td><code>gsConstants.E_QUIT</code></td> +<td>"quit" has been executed. This is not an error. <a href="#gsapi_exit">gsapi_exit</a> must be called next</td> +</tr> +<tr> +<td><code><0</code></td> +<td>error</td> +</tr> +</tbody></table> +<blockquote> +<p><strong>NOTE</strong><br> +For full detail on these return code please see: +<a href="https://www.ghostscript.com/doc/current/API.htm#return_codes">https://www.ghostscript.com/doc/current/API.htm#return_codes</a></p> +</blockquote> +<blockquote> +<p><strong>NOTE</strong><br>All <a href="#gsapi">GSAPI</a> methods aside from <a href="#gsapi_revision">gsapi_revision</a> and <a href="#gsapi_new_instance">gsapi_new_instance</a> should pass an instance of Ghostscript as their first parameter with <code>IntPtr instance</code></p> +</blockquote> +<h3 id="gsapi_revision">gsapi_revision</h3> +<p>This method returns the revision numbers and strings of the Ghostscript interpreter library; you should call it before any other interpreter library functions to make sure that the correct version of the Ghostscript interpreter has been loaded.</p> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public static extern int gsapi_revision(ref gsapi_revision_t vers, + int size);</code></pre> +<blockquote> +<p><strong>NOTE</strong><br>The method should write to a reference variable which conforms to the struct <a href="#gsapi_revision_t">gsapi_revision_t</a>.</p> +</blockquote> +<h3 id="gsapi_new_instance">gsapi_new_instance</h3> +<p>Creates a new instance of Ghostscript. This instance is passed to most other <a href="#gsapi">GSAPI</a> methods. Unless Ghostscript has been compiled with the <code>GS_THREADSAFE</code> define, only one instance at a time is supported.</p> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public static extern int gsapi_new_instance(out IntPtr pinstance, + IntPtr caller_handle);</code></pre> +<blockquote> +<p><strong>NOTE</strong><br>The method returns a pointer which represents your instance of Ghostscript.</p> +</blockquote> +<h3 id="gsapi_delete_instance">gsapi_delete_instance</h3> +<p>Destroy an instance of Ghostscript. Before you call this, Ghostscript must have finished. If Ghostscript has been initialised, you must call <a href="#gsapi_exit">gsapi_exit</a> beforehand.</p> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public static extern void gsapi_delete_instance(IntPtr instance);</code></pre> +<div class="tag sampleCode csharp"></div> + +<pre><code class="language-c">GSAPI.gsapi_delete_instance(gsInstance); +gsInstance = IntPtr.Zero;</code></pre> +<h3 id="gsapi_set_stdio_with_handle">gsapi_set_stdio_with_handle</h3> +<p>Set the callback functions for <code>stdio</code>, together with the handle to use in the callback functions. The <code>stdin</code> callback function should return the number of characters read, 0 for EOF, or -1 for error. The <code>stdout</code> and <code>stderr</code> callback functions should return the number of characters written.</p> +<blockquote> +<p><strong>NOTE</strong><br>These callbacks do not affect output device I/O when using "%stdout" as the output file. In that case, device output will still be directed to the process "stdout" file descriptor, not to the <code>stdio</code> callback.</p> +</blockquote> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public static extern int gsapi_set_stdio_with_handle(IntPtr instance, + gs_stdio_handler stdin, + gs_stdio_handler stdout, + gs_stdio_handler stderr, + IntPtr caller_handle);</code></pre> +<h3 id="gsapi_set_stdio">gsapi_set_stdio</h3> +<p>Set the callback functions for <code>stdio</code>. The handle used in the callbacks will be taken from the value passed to <a href="#gsapi_new_instance">gsapi_new_instance</a>. Otherwise the behaviour of this function matches <a href="#gsapi_set_stdio_with_handle">gsapi_set_stdio_with_handle</a>.</p> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public static extern int gsapi_set_stdio_with_handle(IntPtr instance, + gs_stdio_handler stdin, + gs_stdio_handler stdout, + gs_stdio_handler stderr);</code></pre> +<h3 id="gsapi_set_poll_with_handle">gsapi_set_poll_with_handle</h3> +<p>Set the callback function for polling, together with the handle to pass to the callback function. This function will only be called if the Ghostscript interpreter was compiled with <code>CHECK_INTERRUPTS</code> as described in <code>gpcheck.h</code>.</p> +<p>The polling function should return zero if all is well, and return negative if it wants ghostscript to abort. This is often used for checking for a user cancel. This can also be used for handling window events or cooperative multitasking.</p> +<p>The polling function is called very frequently during interpretation and rendering so it must be fast. If the function is slow, then using a counter to <code>return 0</code> immediately some number of times can be used to reduce the performance impact.</p> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public static extern int gsapi_set_poll_with_handle(IntPtr instance, + gsPollHandler pollfn, + IntPtr caller_handle);</code></pre> +<h3 id="gsapi_set_poll">gsapi_set_poll</h3> +<p>Set the callback function for polling. The handle passed to the callback function will be taken from the handle passed to <a href="#gsapi_new_instance">gsapi_new_instance</a>. Otherwise the behaviour of this function matches <a href="#gsapi_set_poll_with_handle">gsapi_set_poll_with_handle</a>.</p> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public static extern int gsapi_set_poll(IntPtr instance, + gsPollHandler pollfn);</code></pre> +<h3 id="gsapi_set_display_callback">gsapi_set_display_callback</h3> +<p>This call is deprecated; please use <a href="#gsapi_register_callout">gsapi_register_callout</a> to register a <a href="#gscallout">callout handler</a> for the display device in preference.</p> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public static extern int gsapi_set_display_callback(IntPtr pinstance, + IntPtr caller_handle);</code></pre> +<h3 id="gsapi_register_callout">gsapi_register_callout</h3> +<p>This call registers a <a href="#gscallout">callout handler</a>.</p> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public static extern int gsapi_register_callout(IntPtr instance, + gsCallOut callout, + IntPtr callout_handle);</code></pre> +<h3 id="gsapi_deregister_callout">gsapi_deregister_callout</h3> +<p>This call deregisters a <a href="#gscallout">callout handler</a> previously registered with <a href="#gsapi_register_callout">gsapi_register_callout</a>. All three arguments must match exactly for the <a href="#gscallout">callout handler</a> to be deregistered.</p> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public static extern int gsapi_deregister_callout(IntPtr instance, + gsCallOut callout, + IntPtr callout_handle);</code></pre> +<h3 id="gsapi_set_arg_encoding">gsapi_set_arg_encoding</h3> +<p>Set the encoding used for the interpretation of all subsequent arguments supplied via the <code>GhostAPI</code> interface on this instance. By default we expect args to be in encoding <code>0</code> (the 'local' encoding for this OS). On Windows this means "the currently selected codepage". On Linux this typically means <code>utf8</code>. This means that omitting to call this function will leave Ghostscript running exactly as it always has. Please note that use of the 'local' encoding is now deprecated and should be avoided in new code. This must be called after <a href="#gsapi_new_instance">gsapi_new_instance</a> and before <a href="#gsapi_init_with_args">gsapi_init_with_args</a>.</p> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public static extern int gsapi_set_arg_encoding(IntPtr instance, + int encoding);</code></pre> +<h3 id="gsapi_set_default_device_list">gsapi_set_default_device_list</h3> +<p>Set the string containing the list of default device names, for example "display x11alpha x11 bbox". Allows the calling application to influence which device(s) Ghostscript will try, in order, in its selection of the default device. This must be called after <a href="#gsapi_new_instance">gsapi_new_instance</a> and before <a href="#gsapi_init_with_args">gsapi_init_with_args</a>.</p> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public static extern int gsapi_set_default_device_list(IntPtr instance, + IntPtr list, + ref int listlen);</code></pre> +<h3 id="gsapi_get_default_device_list">gsapi_get_default_device_list</h3> +<p>Returns a pointer to the current default device string. This must be called after <a href="#gsapi_new_instance">gsapi_new_instance</a> and before <a href="#gsapi_init_with_args">gsapi_init_with_args</a>.</p> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public static extern int gsapi_get_default_device_list(IntPtr instance, + ref IntPtr list, + ref int listlen);</code></pre> +<h3 id="gsapi_init_with_args">gsapi_init_with_args</h3> +<p>To initialise the interpreter, pass your <code>instance</code> of Ghostscript, your argument count, <code>argc</code>, and your argument variables, <code>argv</code>.</p> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public static extern int gsapi_init_with_args(IntPtr instance, + int argc, + IntPtr argv);</code></pre> +<h3 id="gsapi_run_-">gsapi_run_*</h3> +<p>If these functions return <code><= -100</code>, either quit or a fatal error has occured. You must call <a href="#gsapi_exit">gsapi_exit</a> next. The only exception is <a href="#gsapi_run_string_continue">gsapi_run_string_continue</a> which will return <code>gs_error_NeedInput</code> if all is well.</p> +<p>There is a 64 KB length limit on any buffer submitted to a <code>gsapi_run_*</code> function for processing. If you have more than 65535 bytes of input then you must split it into smaller pieces and submit each in a separate <a href="#gsapi_run_string_continue">gsapi_run_string_continue</a> call.</p> +<h3 id="gsapi_run_string_begin">gsapi_run_string_begin</h3> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public static extern int gsapi_run_string_begin(IntPtr instance, + int usererr, + ref int exitcode);</code></pre> +<h3 id="gsapi_run_string_continue">gsapi_run_string_continue</h3> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public static extern int gsapi_run_string_continue(IntPtr instance, + IntPtr command, + int count, + int usererr, + ref int exitcode);</code></pre> +<h3 id="gsapi_run_string_with_length">gsapi_run_string_with_length</h3> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public static extern int gsapi_run_string_with_length(IntPtr instance, + IntPtr command, + uint length, + int usererr, + ref int exitcode);</code></pre> +<h3 id="gsapi_run_string">gsapi_run_string</h3> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public static extern int gsapi_run_string(IntPtr instance, + IntPtr command, + int usererr, + ref int exitcode);</code></pre> +<h3 id="gsapi_run_string_end">gsapi_run_string_end</h3> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public static extern int gsapi_run_string_end(IntPtr instance, + int usererr, + ref int exitcode);</code></pre> +<h3 id="gsapi_run_file">gsapi_run_file</h3> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public static extern int gsapi_run_file(IntPtr instance, + IntPtr filename, + int usererr, + ref int exitcode);</code></pre> +<h3 id="gsapi_exit">gsapi_exit</h3> +<p>Exit the interpreter. This must be called on shutdown if <a href="#gsapi_init_with_args">gsapi_init_with_args</a> has been called, and just before <a href="#gsapi_delete_instance">gsapi_delete_instance</a>.</p> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public static extern int gsapi_exit(IntPtr instance);</code></pre> +<h3 id="gsapi_set_param">gsapi_set_param</h3> +<p>Sets a parameter.</p> +<p>Broadly, this is equivalent to setting a parameter using -d, -s or -p on the command line. This call cannot be made during a <a href="#gsapi_run_string">gsapi_run_string</a> operation.</p> +<p>Parameters in this context are not the same as 'arguments' as processed by <a href="#gsapi_init_with_args">gsapi_init_with_args</a>, but often the same thing can be achieved. For example, with <a href="#gsapi_init_with_args">gsapi_init_with_args</a>, we can pass "-r200" to change the resolution. Broadly the same thing can be achieved by using <a href="#gsapi_set_param">gsapi_set_param</a> to set a parsed value of "<</HWResolution [ 200.0 200.0 ]>>".</p> +<p>Internally, when we set a parameter, we perform an <code>initgraphics</code> operation. This means that using <a href="#gsapi_set_param">gsapi_set_param</a> other than at the start of a page is likely to give unexpected results.</p> +<p>Attempting to set a parameter that the device does not recognise will be silently ignored, and that parameter will not be found in subsequent <a href="#gsapi_get_param">gsapi_get_param</a> calls.</p> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public static extern int gsapi_set_param(IntPtr instance, + IntPtr param, + IntPtr value, + gs_set_param_type type);</code></pre> +<blockquote> +<p><strong>NOTE</strong><br>The <code>type</code> argument, as a <a href="#gs_set_param_type">gs_set_param_type</a>, dictates the kind of object that the <code>value</code> argument points to.</p> +</blockquote> +<blockquote> +<p><strong>NOTE</strong><br>For more on the C implementation of parameters see: <a href="https://www.ghostscript.com/doc/current/Use.htm#Parameters">Ghostscript parameters in C</a>.</p> +</blockquote> +<h3 id="gsapi_get_param">gsapi_get_param</h3> +<p>Retrieve the current value of a parameter.</p> +<p>If an error occurs, the return value is negative. Otherwise the return value is the number of bytes required for storage of the value. Call once with value <code>NULL</code> to get the number of bytes required, then call again with value pointing to at least the required number of bytes where the value will be copied out. Note that the caller is required to know the type of value in order to get it. For all types other than <a href="#gs_set_param_type">gs_spt_string</a>, <a href="#gs_set_param_type">gs_spt_name</a>, and <a href="#gs_set_param_type">gs_spt_parsed</a> knowing the type means you already know the size required.</p> +<p>This call retrieves parameters/values that have made it to the device. Thus, any values set using <a href="#gs_set_param_type">gs_spt_more_to_come</a> without a following call omitting that flag will not be retrieved. Similarly, attempting to get a parameter before <a href="#gsapi_init_with_args">gsapi_init_with_args</a> has been called will not list any, even if <a href="#gsapi_set_param">gsapi_set_param</a> has been used.</p> +<p>Attempting to read a parameter that is not set will return <code>gs_error_undefined</code> (-21). Note that calling <a href="#gsapi_set_param">gsapi_set_param</a> followed by <a href="#gsapi_get_param">gsapi_get_param</a> may not find the value, if the device did not recognise the key as being one of its configuration keys.</p> +<p>For the C documentation please refer to <a href="https://www.ghostscript.com/doc/current/API.htm#get_param">Ghostscript get_param</a>.</p> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public static extern int gsapi_get_param(IntPtr instance, + IntPtr param, + IntPtr value, + gs_set_param_type type);</code></pre> +<h3 id="gsapi_enumerate_params">gsapi_enumerate_params</h3> +<p>Enumerate the current parameters. Call repeatedly to list out the current parameters.</p> +<p>The first call should have <code>iter</code> = NULL. Subsequent calls should pass the same pointer in so the iterator can be updated. Negative return codes indicate error, 0 success, and 1 indicates that there are no more keys to read. On success, key will be updated to point to a null terminated string with the key name that is guaranteed to be valid until the next call to <a href="#gsapi_enumerate_params">gsapi_enumerate_params</a>. If <code>type</code> is non NULL then the pointer <code>type</code> will be updated to have the <code>type</code> of the parameter.</p> +<blockquote> +<p><strong>NOTE</strong><br>Only one enumeration can happen at a time. Starting a second enumeration will reset the first.</p> +</blockquote> +<p>The enumeration only returns parameters/values that have made it to the device. Thus, any values set using the <a href="#gs_set_param_type">gs_spt_more_to_come</a> without a following call omitting that flag will not be retrieved. Similarly, attempting to enumerate parameters before <a href="#gsapi_init_with_args">gsapi_init_with_args</a> has been called will not list any, even if <a href="#gsapi_set_param">gsapi_set_param</a> has been used.</p> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public static extern int gsapi_enumerate_params(IntPtr instance, + out IntPtr iter, + out IntPtr key, + IntPtr type);</code></pre> +<h3 id="gsapi_add_control_path">gsapi_add_control_path</h3> +<p>Add a (case sensitive) path to one of the lists of <a href="https://ghostscript.com/doc/current/Use.htm#Safer">permitted paths</a> for file access.</p> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public static extern int gsapi_add_control_path(IntPtr instance, + int type, + IntPtr path);</code></pre> +<h3 id="gsapi_remove_control_path">gsapi_remove_control_path</h3> +<p>Remove a (case sensitive) path from one of the lists of <a href="https://ghostscript.com/doc/current/Use.htm#Safer">permitted paths</a> for file access.</p> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public static extern int gsapi_remove_control_path(IntPtr instance, + int type, + IntPtr path);</code></pre> +<h3 id="gsapi_purge_control_paths">gsapi_purge_control_paths</h3> +<p>Clear all the paths from one of the lists of <a href="https://ghostscript.com/doc/current/Use.htm#Safer">permitted paths</a> for file access.</p> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public static extern void gsapi_purge_control_paths(IntPtr instance, + int type);</code></pre> +<h3 id="gsapi_activate_path_control">gsapi_activate_path_control</h3> +<p>Enable/Disable path control (i.e. whether paths are checked against <a href="https://ghostscript.com/doc/current/Use.htm#Safer">permitted paths</a> before access is granted).</p> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public static extern void gsapi_activate_path_control(IntPtr instance, + int enable);</code></pre> +<h3 id="gsapi_is_path_control_active">gsapi_is_path_control_active</h3> +<p>Query whether path control is activated or not.</p> +<div class="tag methodDefinition csharp"></div> + + +<pre><code class="language-c">public static extern int gsapi_is_path_control_active(IntPtr instance);</code></pre> +<h2 id="callback-and-callout-prototypes">Callback and Callout prototypes</h2> +<p><a href="#gsapi">GSAPI</a> also defines some prototype pointers which are defined as follows.</p> +<h3 id="gs_stdio_handler">gs_stdio_handler</h3> +<div class="tag callbackDefinition csharp"></div> + +<pre><code class="language-c">/* Callback proto for stdio */ +public delegate int gs_stdio_handler(IntPtr caller_handle, + IntPtr buffer, + int len);</code></pre> +<h3 id="gspollhandler">gsPollHandler</h3> +<div class="tag callbackDefinition csharp"></div> + +<pre><code class="language-c">/* Callback proto for poll function */ +public delegate int gsPollHandler(IntPtr caller_handle);</code></pre> +<h3 id="gscallout">gsCallOut</h3> +<div class="tag callbackDefinition csharp"></div> + +<pre><code class="language-c">/* Callout proto */ +public delegate int gsCallOut(IntPtr callout_handle, + IntPtr device_name, + int id, + int size, + IntPtr data); +</code></pre> +</article> + + </div><!--/middle --> + + + + <div class="right"> + + <div class="link"><a href="#about">About</a></div> + <div class="link"><a href="#structs-and-enums">Structs and Enums</a></div> + <div class="sub-link"><a href="#gsapi_revision_t">gsapi_revision_t</a></div> + <div class="sub-link"><a href="#gs_set_param_type">gs_set_param_type</a></div> + <div class="sub-link"><a href="#gsencoding">gsEncoding</a></div> + <div class="link"><a href="#constants">Constants</a></div> + <div class="sub-link"><a href="#gsconstants">gsConstants</a></div> + <div class="link"><a href="#gsapi">GSAPI</a></div> + <div class="sub-link"><a href="#gsapi_revision">gsapi_revision</a></div> + <div class="sub-link"><a href="#gsapi_new_instance">gsapi_new_instance</a></div> + <div class="sub-link"><a href="#gsapi_delete_instance">gsapi_delete_instance</a></div> + <div class="sub-link"><a href="#gsapi_set_stdio_with_handle">gsapi_set_stdio_with_handle</a></div> + <div class="sub-link"><a href="#gsapi_set_stdio">gsapi_set_stdio</a></div> + <div class="sub-link"><a href="#gsapi_set_poll_with_handle">gsapi_set_poll_with_handle</a></div> + <div class="sub-link"><a href="#gsapi_set_poll">gsapi_set_poll</a></div> + <div class="sub-link"><a href="#gsapi_set_display_callback">gsapi_set_display_callback</a></div> + <div class="sub-link"><a href="#gsapi_register_callout"> gsapi_register_callout</a></div> + <div class="sub-link"><a href="#gsapi_deregister_callout">gsapi_deregister_callout</a></div> + <div class="sub-link"><a href="#gsapi_set_arg_encoding">gsapi_set_arg_encoding</a></div> + <div class="sub-link"><a href="#gsapi_set_default_device_list">gsapi_set_default_device_list</a></div> + <div class="sub-link"><a href="#gsapi_get_default_device_list">gsapi_get_default_device_list</a></div> + <div class="sub-link"><a href="#gsapi_init_with_args">gsapi_init_with_args</a></div> + <div class="sub-link"><a href="#gsapi_run_-">gsapi_run_*</a></div> + <div class="sub-link"><a href="#gsapi_run_string_begin">gsapi_run_string_begin</a></div> + <div class="sub-link"><a href="#gsapi_run_string_continue">gsapi_run_string_continue</a></div> + <div class="sub-link"><a href="#gsapi_run_string_with_length">gsapi_run_string_with_length</a></div> + <div class="sub-link"><a href="#gsapi_run_string">gsapi_run_string</a></div> + <div class="sub-link"><a href="#gsapi_run_string_end">gsapi_run_string_end</a></div> + <div class="sub-link"><a href="#gsapi_run_file">gsapi_run_file</a></div> + <div class="sub-link"><a href="#gsapi_exit">gsapi_exit</a></div> + <div class="sub-link"><a href="#gsapi_set_param">gsapi_set_param</a></div> + <div class="sub-link"><a href="#gsapi_get_param">gsapi_get_param</a></div> + <div class="sub-link"><a href="#gsapi_enumerate_params">gsapi_enumerate_params</a></div> + <div class="sub-link"><a href="#gsapi_add_control_path">gsapi_add_control_path</a></div> + <div class="sub-link"><a href="#gsapi_remove_control_path">gsapi_remove_control_path</a></div> + <div class="sub-link"><a href="#gsapi_purge_control_paths">gsapi_purge_control_paths</a></div> + <div class="sub-link"><a href="#gsapi_activate_path_control">gsapi_activate_path_control</a></div> + <div class="sub-link"><a href="#gsapi_is_path_control_active">gsapi_is_path_control_active</a></div> + <div class="link"><a href="#callback-and-callout-prototypes">Callback and Callout prototypes</a></div> + <div class="sub-link"><a href="#gs_stdio_handler">gs_stdio_handler</a></div> + <div class="sub-link"><a href="#gspollhandler">gsPollHandler</a></div> + <div class="sub-link"><a href="#gscallout">gsCallOut</a></div> + </div> + + </div> + + <footer></footer> + + </body> + +</html> diff --git a/doc/language-bindings/c-sharp-ghost-mono.html b/doc/language-bindings/c-sharp-ghost-mono.html new file mode 100644 index 00000000..33c2ef83 --- /dev/null +++ b/doc/language-bindings/c-sharp-ghost-mono.html @@ -0,0 +1,582 @@ +<html lang="en"> + <head> + <title>Ghostscript language bindings</title> + <meta http-equiv="content-type" content="text/html; charset=utf-8"> + <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width"> + <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:200,200i,300,300i,400,400i,600,600i,700,700i,900,900i" rel="stylesheet"> + <link rel="shortcut icon" type="image/png" href="../images/favicon.png"> + <link href="css/default.css" rel="stylesheet" type="text/css" /> + <script type="text/javascript" src="js/default.js"></script> + </head> + + <body> + + <header><h1></h1><div class="menu-icon" onclick="javascript:showMenu();"></div></header> + + <div id="burger-menu"> + <div class="navigation"> + <div class="title first">Introduction</div> + <div class="link"><a href="index.html">About our APIs</a></div> + <div class="link"><a href="demo-code.html">Demo code</a></div> + + <div class="title">C#</div> + <div class="link"><a href="c-sharp-intro.html">Overview</a></div> + <div class="link"><a href="c-sharp-ghost-api.html">GhostAPI</a></div> + <div class="link"><a href="c-sharp-ghost-net.html">GhostNET</a></div> + <div class="link selected"><a href="c-sharp-ghost-mono.html">GhostMono</a></div> + + <div class="title">Java</div> + <div class="link"><a href="java-intro.html">Overview</a></div> + <div class="link"><a href="java-gsjavajar.html">gsjava.jar</a></div> + + <div class="title">Python</div> + <div class="link"><a href="python-intro.html">Overview</a></div> + <div class="link"><a href="python-gsapi.html">gsapi.py</a></div> + </div> + </div> + <div class="main"> + + <div class="left"> + <div class="title first">Introduction</div> + <div class="link"><a href="index.html">About our APIs</a></div> + <div class="link"><a href="demo-code.html">Demo code</a></div> + + <div class="title">C#</div> + <div class="link"><a href="c-sharp-intro.html">Overview</a></div> + <div class="link"><a href="c-sharp-ghost-api.html">GhostAPI</a></div> + <div class="link"><a href="c-sharp-ghost-net.html">GhostNET</a></div> + <div class="link selected"><a href="c-sharp-ghost-mono.html">GhostMono</a></div> + + <div class="title">Java</div> + <div class="link"><a href="java-intro.html">Overview</a></div> + <div class="link"><a href="java-gsjavajar.html">gsjava.jar</a></div> + + <div class="title">Python</div> + <div class="link"><a href="python-intro.html">Overview</a></div> + <div class="link"><a href="python-gsapi.html">gsapi.py</a></div> + </div> + + <div class="middle"> + +<!-- note: don't tab indent <article> as it has <pre> code which will have its layout adversly affected --> +<article class="markdown-body entry-content"><h1 id="ghostmono">GhostMono</h1> +<div class="banner"> + <div class="c-sharp-text"></div> + <div class="vendor-logo c-sharp-logo"></div> +</div> + + +<h2 id="about">About</h2> +<p><code>GhostMono</code> is the <code>C#</code> interface into the <code>GhostAPI</code> library developed for Linux systems.</p> +<h2 id="enums">Enums</h2> +<h3 id="tasks">Tasks</h3> +<p>The Ghostscript task type <code>enum</code> is used to inform <code>GhostAPI</code> of the type of operation which is being requested.</p> +<table> +<thead> +<tr> +<th>Task</th> +<th>Description</th> +</tr> +</thead> +<tbody><tr> +<td>PS_DISTILL</td> +<td>Task associated with converting a PostScript stream to a PDF document</td> +</tr> +<tr> +<td>CREATE_XPS</td> +<td>Task associated with outputting a copy of a document to XPS</td> +</tr> +<tr> +<td>SAVE_RESULT</td> +<td>Task associated with saving documents</td> +</tr> +<tr> +<td>GET_PAGE_COUNT</td> +<td>Task associated with getting the page count of a document</td> +</tr> +<tr> +<td>GENERIC</td> +<td>Generic task identifier</td> +</tr> +<tr> +<td>DISPLAY_DEV_THUMBS</td> +<td>Display Device task associated with rendering thumbnails</td> +</tr> +<tr> +<td>DISPLAY_DEV_NON_PDF</td> +<td>Display Device task associated with non-PDF or non-XPS rendering <sup><a href="#1-ghostscript-page-description-languages">1</a></sup></td> +</tr> +<tr> +<td>DISPLAY_DEV_PDF</td> +<td>Display Device task associated with PDF & XPS rendering <sup><a href="#1-ghostscript-page-description-languages">1</a></sup></td> +</tr> +<tr> +<td>DISPLAY_DEV_RUN_FILE</td> +<td>Display Device task associated with running files</td> +</tr> +</tbody></table> +<p>Task types are defined as <code>GS_Task_t</code>.</p> +<div class="tag enumDefinition csharp"></div> + +<pre><code class="language-c">public enum GS_Task_t +{ + PS_DISTILL, + CREATE_XPS, + SAVE_RESULT, + GET_PAGE_COUNT, + GENERIC, + DISPLAY_DEV_THUMBS, + DISPLAY_DEV_NON_PDF, + DISPLAY_DEV_PDF, + DISPLAY_DEV_RUN_FILE +}</code></pre> +<h3 id="results">Results</h3> +<p>Result types are defined as <code>GS_Result_t</code>.</p> +<div class="tag enumDefinition csharp"></div> + +<pre><code class="language-c">public enum GS_Result_t +{ + gsOK, + gsFAILED, + gsCANCELLED +}</code></pre> +<h3 id="status">Status</h3> +<p>Status is defined as <code>gsStatus</code>.</p> +<div class="tag enumDefinition csharp"></div> + +<pre><code class="language-c">public enum gsStatus +{ + GS_READY, + GS_BUSY, + GS_ERROR +};</code></pre> +<h2 id="the-parameter-struct">The Parameter Struct</h2> +<p>The parameter struct <code>gsParamState_t</code> allows for bundles of information to be processed by Ghostscript to complete overall requests.</p> +<div class="tag structDefinition csharp"></div> + +<pre><code class="language-c">public struct gsParamState_t +{ + public String outputfile; + public String inputfile; + public GS_Task_t task; + public GS_Result_t result; + public int num_pages; + public List<int> pages; + public int firstpage; + public int lastpage; + public int currpage; + public List<String> args; + public int return_code; + public double zoom; +};</code></pre> +<h3 id="parameters-explained">Parameters explained</h3> +<p>Setting up your parameters (with any dedicated bespoke method(s) which your application requires) is needed when communicating directly with <code>GhostAPI</code>.</p> +<p>When requesting Ghostscript to process an operation an application developer should send a parameter payload which defines the details for the operation.</p> +<p>For example in <code>GhostMono</code> we can see the public method as follows:</p> +<div class="tag sampleCode csharp"></div> + +<pre><code class="language-c">public gsStatus DistillPS(String fileName, int resolution) +{ + gsParamState_t gsparams = new gsParamState_t(); + gsparams.args = new List<string>(); + + gsparams.inputfile = fileName; + gsparams.args.Add("gs"); + gsparams.args.Add("-dNOPAUSE"); + gsparams.args.Add("-dBATCH"); + gsparams.args.Add("-I%rom%Resource/Init/"); + gsparams.args.Add("-dSAFER"); + gsparams.args.Add("-sDEVICE=pdfwrite"); + gsparams.outputfile = Path.GetTempFileName(); + gsparams.args.Add("-o" + gsparams.outputfile); + gsparams.task = GS_Task_t.PS_DISTILL; + + return RunGhostscriptAsync(gsparams); +}</code></pre> +<p>Here we can see a parameter payload being setup before being passed on to the asynchronous method <code>RunGhostscriptAsync</code> which sets up a worker thread to run according to the task type in the payload.</p> +<p><code>GhostMono</code> handles many common operations on an application developer's behalf, however if you require to write your own methods to interface with <code>GhostAPI</code> then referring to the public methods in <code>GhostMono</code> is a good starting point.</p> +<p>For full documentation on parameters refer to <a href="https://www.ghostscript.com/doc/current/Use.htm#Parameters">Ghostscript parameters</a>.</p> +<h2 id="the-event-class">The Event class</h2> +<p><code>GhostMono</code> contains a public class <code>gsThreadCallBack</code>. This class is used to set and get callback information as they occur. <code>GhostMono</code> will create these payloads and deliver them back to the application layer's <code>ProgressCallBack</code> method <a href="#delegates">asynchronously</a>.</p> +<div class="tag classDefinition csharp"></div> + +<pre><code class="language-c">public class gsThreadCallBack +{ + private bool m_completed; + private int m_progress; + private gsParamState_t m_param; + public bool Completed + { + get { return m_completed; } + } + public gsParamState_t Params + { + get { return m_param; } + } + public int Progress + { + get { return m_progress; } + } + public gsThreadCallBack(bool completed, int progress, gsParamState_t param) + { + m_completed = completed; + m_progress = progress; + m_param = param; + } +}</code></pre> +<h2 id="gsmono">GSMONO</h2> +<p>This class should be instantiated as a member variable in your application with callback definitions setup as required.</p> +<p>Handlers for asynchronous operations can injected by providing your own bespoke callback methods to your instance's <code>ProgressCallBack</code> function.</p> +<div class="tag sampleCode csharp"></div> + +<pre><code class="language-c">/* Set up ghostscript with callbacks for system updates */ +m_ghostscript = new GSMONO(); +m_ghostscript.ProgressCallBack += new GSMONO.Progress(gsProgress); +m_ghostscript.StdIOCallBack += new GSMONO.StdIO(gsIO); +m_ghostscript.DLLProblemCallBack += new GSMONO.DLLProblem(gsDLL); +m_ghostscript.PageRenderedCallBack += new GSMONO.PageRendered(gsPageRendered); +m_ghostscript.DisplayDeviceOpen(); + +/* example callback stubs for asynchronous operations */ +private void gsProgress(gsThreadCallBack asyncInformation) +{ + Console.WriteLine($"gsProgress().progress:{asyncInformation.Progress}"); + + if (asyncInformation.Completed) // task complete + { + // what was the task? + switch (asyncInformation.Params.task) + { + case GS_Task_t.CREATE_XPS: + Console.WriteLine($"CREATE_XPS.outputfile:"); + Console.WriteLine($"{asyncInformation.Params.result.outputfile}"); + break; + + case GS_Task_t.PS_DISTILL: + Console.WriteLine($"PS_DISTILL.outputfile:"); + Console.WriteLine($"{asyncInformation.Params.result.outputfile}"); + break; + + case GS_Task_t.SAVE_RESULT: + + break; + + case GS_Task_t.DISPLAY_DEV_THUMBS: + + break; + + case GS_Task_t.DISPLAY_DEV_RUN_FILE: + + break; + + case GS_Task_t.DISPLAY_DEV_PDF: + + break; + + case GS_Task_t.DISPLAY_DEV_NON_PDF: + + break; + + default: + + break; + } + + // task failed + if (asyncInformation.Params.result == GS_Result_t.gsFAILED) + { + switch (asyncInformation.Params.task) + { + case GS_Task_t.CREATE_XPS: + + break; + + case GS_Task_t.PS_DISTILL: + + break; + + case GS_Task_t.SAVE_RESULT: + + break; + + default: + + break; + } + return; + } + + // task cancelled + if (asyncInformation.Params.result == GS_Result_t.gsCANCELLED) + { + + } + } + else // task is still running + { + switch (asyncInformation.Params.task) + { + case GS_Task_t.CREATE_XPS: + + break; + + case GS_Task_t.PS_DISTILL: + + break; + + case GS_Task_t.SAVE_RESULT: + + break; + } + } +} + +private void gsIO(String message, int len) +{ + Console.WriteLine($"gsIO().message:{message}, length:{len}"); +} + +private void gsDLL(String message) +{ + Console.WriteLine($"gsDLL().message:{message}"); +} + +private void gsPageRendered(int width, + int height, + int raster, + IntPtr data, + gsParamState_t state) +{ + +};</code></pre> +<blockquote> +<p><strong>NOTE</strong><br>Once a Ghostscript operation is in progress any defined callback functions will be called as the operation runs up unto completion. These callback methods are essential for your application to interpret activity events and react accordingly.</p> +</blockquote> +<p>An explanation of callbacks and the available public methods within <code>GSMONO</code> are explained below.</p> +<h3 id="delegates">Delegates</h3> +<p>To handle asynchronous events <code>GhostMONO</code> has four delegates which define callback methods that an application can assign to.</p> +<table> +<thead> +<tr> +<th>Callback</th> +<th>Description</th> +</tr> +</thead> +<tbody><tr> +<td><code>DLLProblemCallBack</code></td> +<td>Occurs if there is some issue with the Ghostscript Shared Object (<code>libgpdl.so</code>)</td> +</tr> +<tr> +<td><code>StdIOCallBack</code></td> +<td>Occurs if Ghostscript outputs something to <code>stderr</code> or <code>stdout</code></td> +</tr> +<tr> +<td><code>ProgressCallBack</code></td> +<td>Occurs as Ghostscript makes its way through a file</td> +</tr> +<tr> +<td><code>PageRenderedCallBack</code></td> +<td>Occurs when a page has been rendered and the data from the display device is ready</td> +</tr> +</tbody></table> +<h4 id="dllproblemcallback">DLLProblemCallBack</h4> +<div class="tag callbackDefinition csharp"></div> + +<pre><code class="language-c">internal delegate void DLLProblem(String mess); +internal event DLLProblem DLLProblemCallBack;</code></pre> +<h4 id="stdiocallback">StdIOCallBack</h4> +<div class="tag callbackDefinition csharp"></div> + +<pre><code class="language-c">internal delegate void StdIO(String mess, + int len); +internal event StdIO StdIOCallBack;</code></pre> +<h4 id="progresscallback">ProgressCallBack</h4> +<div class="tag callbackDefinition csharp"></div> + +<pre><code class="language-c">internal delegate void Progress(gsEventArgs info); +internal event Progress ProgressCallBack;</code></pre> +<h4 id="pagerenderedcallback">PageRenderedCallBack</h4> +<div class="tag callbackDefinition csharp"></div> + +<pre><code class="language-c">internal delegate void PageRendered(int width, + int height, + int raster, + IntPtr data, + gsParamState_t state); +internal event PageRendered PageRenderedCallBack;</code></pre> +<h3 id="getversion">GetVersion</h3> +<p>Use this method to get Ghostscript version info as a handy <code>String</code>.</p> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public String GetVersion()</code></pre> +<div class="tag sampleCode csharp"></div> + +<pre><code class="language-c">String gs_vers = m_ghostscript.GetVersion();</code></pre> +<blockquote> +<p><strong>NOTE</strong><br>An exception will be thrown if there is any issue with the Ghostscript DLL.</p> +</blockquote> +<h3 id="displaydeviceopen">DisplayDeviceOpen</h3> +<p>Sets up the <a href="https://ghostscript.com/doc/current/Devices.htm#Display_devices">display device</a> ahead of time.</p> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public gsParamState_t DisplayDeviceOpen()</code></pre> +<div class="tag sampleCode csharp"></div> + +<pre><code class="language-c">m_ghostscript.DisplayDeviceOpen();</code></pre> +<blockquote> +<p><strong>NOTE</strong><br>Calling this method <a href="c-sharp-ghost-api.html#gsapi_new_instance">instantiates ghostscript</a> and configures the encoding and the callbacks for the display device.</p> +</blockquote> +<h3 id="displaydeviceclose">DisplayDeviceClose</h3> +<p>Closes the <a href="https://ghostscript.com/doc/current/Devices.htm#Display_devices">display device</a> and deletes the instance.</p> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public gsParamState_t DisplayDeviceClose()</code></pre> +<div class="tag sampleCode csharp"></div> + +<pre><code class="language-c">m_ghostscript.DisplayDeviceClose();</code></pre> +<blockquote> +<p><strong>NOTE</strong><br>Calling this method <a href="c-sharp-ghost-api.html#gsapi_delete_instance">deletes ghostscript</a>.</p> +</blockquote> +<h3 id="getpagecount">GetPageCount</h3> +<p>Use this method to get the number of pages in a supplied document.</p> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public int GetPageCount(String fileName)</code></pre> +<div class="tag sampleCode csharp"></div> + +<pre><code class="language-c">int page_number = m_ghostscript.GetPageCount("my_document.pdf");</code></pre> +<blockquote> +<p><strong>NOTE</strong><br>If Ghostscript is unable to determine the page count then this method will return <code>-1</code>.</p> +</blockquote> +<h3 id="distillps">DistillPS</h3> +<p>Launches a thread rendering all the pages of a supplied PostScript file to a PDF.</p> +<div class="tag methodDefinition csharp async"></div> + +<pre><code class="language-c">public gsStatus DistillPS(String fileName, int resolution)</code></pre> +<div class="tag sampleCode csharp"></div> + +<pre><code class="language-c">m_ghostscript.DistillPS("my_postscript_document.ps", 300);</code></pre> +<span class="smallText alignRight"> + +<p><em><a href="#delegates">asynchronous</a></em></p> +</span> + + + +<h3 id="displaydevicerenderall">DisplayDeviceRenderAll</h3> +<p>Launches a thread rendering all the document pages with the <a href="https://ghostscript.com/doc/current/Devices.htm#Display_devices">display device</a>. For use with languages that can be indexed via pages which include PDF and XPS. <a href="#1-ghostscript-page-description-languages">1</a></p> +<div class="tag methodDefinition csharp async"></div> + +<pre><code class="language-c">public gsStatus DisplayDeviceRenderAll(String fileName, double zoom, bool aa, GS_Task_t task)</code></pre> +<div class="tag sampleCode csharp"></div> + +<pre><code class="language-c">m_ghostscript.DisplayDeviceRenderAll("my_document.pdf", + 0.1, + false, + GS_Task_t.DISPLAY_DEV_THUMBS_NON_PDF);</code></pre> +<span class="smallText alignRight"> + +<p><em><a href="#delegates">asynchronous</a></em></p> +</span> + + +<h3 id="displaydevicerenderthumbs">DisplayDeviceRenderThumbs</h3> +<p>Launches a thread rendering all the pages with the <a href="https://ghostscript.com/doc/current/Devices.htm#Display_devices">display device</a> to collect thumbnail images.</p> +<p>Recommended zoom level for thumbnails is between 0.05 and 0.2, additionally anti-aliasing is probably not required.</p> +<div class="tag methodDefinition csharp async"></div> + +<pre><code class="language-c">public gsStatus DisplayDeviceRenderThumbs(String fileName, + double zoom, + bool aa)</code></pre> +<div class="tag sampleCode csharp"></div> + +<pre><code class="language-c">m_ghostscript.DisplayDeviceRenderThumbs("my_document.pdf", + 0.1, + false);</code></pre> +<span class="smallText alignRight"> + +<p><em><a href="#delegates">asynchronous</a></em></p> +</span> + + +<h3 id="displaydevicerenderpages">DisplayDeviceRenderPages</h3> +<p>Launches a thread rendering a set of pages with the <a href="https://ghostscript.com/doc/current/Devices.htm#Display_devices">display device</a>. For use with languages that can be indexed via pages which include PDF and XPS. <sup><a href="#1-ghostscript-page-description-languages">1</a></sup></p> +<div class="tag methodDefinition csharp async"></div> + +<pre><code class="language-c">public gsStatus DisplayDeviceRenderPages(String fileName, + int first_page, + int last_page, + double zoom)</code></pre> +<div class="tag sampleCode csharp"></div> + +<pre><code class="language-c">m_ghostscript.DisplayDeviceRenderPages("my_document.pdf", + 0, + 9, + 1.0);</code></pre> +<span class="smallText alignRight"> + +<p><em><a href="#delegates">asynchronous</a></em></p> +</span> + + +<h3 id="getstatus">GetStatus</h3> +<p>Returns the current <a href="#status">status</a> of <code>Ghostscript</code>.</p> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public gsStatus GetStatus()</code></pre> +<div class="tag sampleCode csharp"></div> + +<pre><code class="language-c">gsStatus status = m_ghostscript.GetStatus();</code></pre> +<h3 id="ghostscriptexception">GhostscriptException</h3> +<p>An application developer can log any exceptions in this public class as required by editing the constructor.</p> +<div class="tag classDefinition csharp"></div> + +<pre><code class="language-c">public class GhostscriptException : Exception +{ + public GhostscriptException(string message) : base(message) + { + // Report exceptions as required + } +}</code></pre> +<h2 id="notes">Notes</h2> +<h4 id="1-ghostscript-page-description-languages">1: Ghostscript & Page Description Languages</h4> +<p>Ghostscript handles the following <a href="https://en.wikipedia.org/wiki/Page_description_language">PDLs</a>: <code>PCL</code> <code>PDF</code> <code>PS</code> <code>XPS</code>.</p> +<p><code>PCL</code> and <code>PS</code> do not allow random access, meaning that, to print page 2 in a 100 page document, Ghostscript has to read the entire document stream of 100 pages.</p> +<p>On the other hand, <code>PDF</code> and <code>XPS</code> allow for going directly to page 2 and then only dealing with that content. The tasks <code>DISPLAY_DEV_NON_PDF</code> and <code>DISPLAY_DEV_PDF</code> keep track of what sort of input Ghostscript is dealing with and enables the application to direct progress or completion callbacks accordingly.</p> +</article> + + </div><!-- / middle --> + + <div class="right"> + + <div class="link"><a href="#about">About</a></div> + <div class="link"><a href="#enums">Enums</a></div> + <div class="sub-link"><a href="#tasks">Tasks</a></div> + <div class="sub-link"><a href="#results">Results</a></div> + <div class="sub-link"><a href="#status">Status</a></div> + <div class="link"><a href="#the-parameter-struct">The Parameter Struct</a></div> + <div class="sub-link"><a href="#parameters-explained">Parameters explained</a></div> + <div class="link"><a href="#the-event-class">The Event class</a></div> + <div class="link"><a href="#gsmono">GSMONO</a></div> + <div class="sub-link"><a href="#delegates">Delegates</a></div> + <div class="sub-link"><a href="#getversion">GetVersion</a></div> + <div class="sub-link"><a href="#displaydeviceopen">DisplayDeviceOpen</a></div> + <div class="sub-link"><a href="#displaydeviceclose">DisplayDeviceClose</a></div> + <div class="sub-link"><a href="#getpagecount">GetPageCount</a></div> + <div class="sub-link"><a href="#distillps">DistillPS</a></div> + <div class="sub-link"><a href="#displaydevicerenderall">DisplayDeviceRenderAll</a></div> + <div class="sub-link"><a href="#displaydevicerenderthumbs">DisplayDeviceRenderThumbs</a></div> + <div class="sub-link"><a href="#displaydevicerenderpages">DisplayDeviceRenderPages</a></div> + <div class="sub-link"><a href="#getstatus">GetStatus</a></div> + <div class="sub-link"><a href="#ghostscriptexception">GhostscriptException</a></div> + <div class="link"><a href="#notes">Notes</a></div> + + </div> + + </div> + + <footer></footer> + + </body> + +</html> diff --git a/doc/language-bindings/c-sharp-ghost-net.html b/doc/language-bindings/c-sharp-ghost-net.html new file mode 100644 index 00000000..1308abf6 --- /dev/null +++ b/doc/language-bindings/c-sharp-ghost-net.html @@ -0,0 +1,621 @@ +<html lang="en"> + <head> + <title>Ghostscript language bindings</title> + <meta http-equiv="content-type" content="text/html; charset=utf-8"> + <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width"> + <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:200,200i,300,300i,400,400i,600,600i,700,700i,900,900i" rel="stylesheet"> + <link rel="shortcut icon" type="image/png" href="../images/favicon.png"> + <link href="css/default.css" rel="stylesheet" type="text/css" /> + <script type="text/javascript" src="js/default.js"></script> + </head> + + <body> + + <header><h1></h1><div class="menu-icon" onclick="javascript:showMenu();"></div></header> + + <div id="burger-menu"> + <div class="navigation"> + <div class="title first">Introduction</div> + <div class="link"><a href="index.html">About our APIs</a></div> + <div class="link"><a href="demo-code.html">Demo code</a></div> + + <div class="title">C#</div> + <div class="link"><a href="c-sharp-intro.html">Overview</a></div> + <div class="link"><a href="c-sharp-ghost-api.html">GhostAPI</a></div> + <div class="link selected"><a href="c-sharp-ghost-net.html">GhostNET</a></div> + <div class="link"><a href="c-sharp-ghost-mono.html">GhostMono</a></div> + + <div class="title">Java</div> + <div class="link"><a href="java-intro.html">Overview</a></div> + <div class="link"><a href="java-gsjavajar.html">gsjava.jar</a></div> + + <div class="title">Python</div> + <div class="link"><a href="python-intro.html">Overview</a></div> + <div class="link"><a href="python-gsapi.html">gsapi.py</a></div> + </div> + </div> + <div class="main"> + + <div class="left"> + <div class="title first">Introduction</div> + <div class="link"><a href="index.html">About our APIs</a></div> + <div class="link"><a href="demo-code.html">Demo code</a></div> + + <div class="title">C#</div> + <div class="link"><a href="c-sharp-intro.html">Overview</a></div> + <div class="link"><a href="c-sharp-ghost-api.html">GhostAPI</a></div> + <div class="link selected"><a href="c-sharp-ghost-net.html">GhostNET</a></div> + <div class="link"><a href="c-sharp-ghost-mono.html">GhostMono</a></div> + + <div class="title">Java</div> + <div class="link"><a href="java-intro.html">Overview</a></div> + <div class="link"><a href="java-gsjavajar.html">gsjava.jar</a></div> + + <div class="title">Python</div> + <div class="link"><a href="python-intro.html">Overview</a></div> + <div class="link"><a href="python-gsapi.html">gsapi.py</a></div> + </div> + + <div class="middle"> + +<!-- note: don't tab indent <article> as it has <pre> code which will have its layout adversly affected --> +<article class="markdown-body entry-content"><h1 id="ghostnet">GhostNET</h1> +<div class="banner"> + <div class="c-sharp-text"></div> + <div class="vendor-logo c-sharp-logo"></div> +</div> + + +<h2 id="about">About</h2> +<p><code>GhostNET</code> is the <code>C#</code> interface into the <code>GhostAPI</code> library developed for Windows systems.</p> +<h2 id="enums">Enums</h2> +<h3 id="tasks">Tasks</h3> +<p>The Ghostscript task type <code>enum</code> is used to inform <code>GhostAPI</code> of the type of operation which is being requested.</p> +<table> +<thead> +<tr> +<th>Task</th> +<th>Description</th> +</tr> +</thead> +<tbody><tr> +<td>PS_DISTILL</td> +<td>Task associated with converting a PostScript stream to a PDF document</td> +</tr> +<tr> +<td>CREATE_XPS</td> +<td>Task associated with outputting a copy of a document to XPS</td> +</tr> +<tr> +<td>SAVE_RESULT</td> +<td>Task associated with saving documents</td> +</tr> +<tr> +<td>GET_PAGE_COUNT</td> +<td>Task associated with getting the page count of a document</td> +</tr> +<tr> +<td>GENERIC</td> +<td>Generic task identifier</td> +</tr> +<tr> +<td>DISPLAY_DEV_THUMBS</td> +<td>Display Device task associated with rendering thumbnails</td> +</tr> +<tr> +<td>DISPLAY_DEV_NON_PDF</td> +<td>Display Device task associated with non-PDF or non-XPS rendering <sup><a href="#1-ghostscript-page-description-languages">1</a></sup></td> +</tr> +<tr> +<td>DISPLAY_DEV_PDF</td> +<td>Display Device task associated with PDF & XPS rendering <sup><a href="#1-ghostscript-page-description-languages">1</a></sup></td> +</tr> +<tr> +<td>DISPLAY_DEV_RUN_FILE</td> +<td>Display Device task associated with running files</td> +</tr> +</tbody></table> +<p>Task types are defined as <code>GS_Task_t</code>.</p> +<div class="tag enumDefinition csharp"></div> + +<pre><code class="language-c">public enum GS_Task_t +{ + PS_DISTILL, + CREATE_XPS, + SAVE_RESULT, + GET_PAGE_COUNT, + GENERIC, + DISPLAY_DEV_THUMBS, + DISPLAY_DEV_NON_PDF, + DISPLAY_DEV_PDF, + DISPLAY_DEV_RUN_FILE +}</code></pre> +<h3 id="results">Results</h3> +<p>Result types are defined as <code>GS_Result_t</code>.</p> +<div class="tag enumDefinition csharp"></div> + +<pre><code class="language-c">public enum GS_Result_t +{ + gsOK, + gsFAILED, + gsCANCELLED +}</code></pre> +<h3 id="status">Status</h3> +<p>Status is defined as <code>gsStatus</code>.</p> +<div class="tag enumDefinition csharp"></div> + +<pre><code class="language-c">public enum gsStatus +{ + GS_READY, + GS_BUSY, + GS_ERROR +};</code></pre> +<h2 id="the-parameter-struct">The Parameter Struct</h2> +<p>The parameter struct <code>gsParamState_t</code> allows for bundles of information to be processed by Ghostscript to complete overall requests.</p> +<div class="tag structDefinition csharp"></div> + +<pre><code class="language-c">public struct gsParamState_t +{ + public String outputfile; + public String inputfile; + public GS_Task_t task; + public GS_Result_t result; + public int num_pages; + public List<int> pages; + public int firstpage; + public int lastpage; + public int currpage; + public List<String> args; + public int return_code; + public double zoom; + public bool aa; + public bool is_valid; +};</code></pre> +<h3 id="parameters-explained">Parameters explained</h3> +<p>Setting up your parameters (with any dedicated bespoke method(s) which your application requires) is needed when communicating directly with <code>GhostAPI</code>.</p> +<p>When requesting Ghostscript to process an operation an application developer should send a parameter payload which defines the details for the operation.</p> +<p>For example in <code>GhostNET</code> we can see the public method as follows:</p> +<div class="tag sampleCode csharp"></div> + +<pre><code class="language-c">public gsStatus DistillPS(String fileName, int resolution) +{ + gsParamState_t gsparams = new gsParamState_t(); + gsparams.args = new List<string>(); + + gsparams.inputfile = fileName; + gsparams.args.Add("gs"); + gsparams.args.Add("-sDEVICE=pdfwrite"); + gsparams.outputfile = Path.GetTempFileName(); + gsparams.args.Add("-o" + gsparams.outputfile); + gsparams.task = GS_Task_t.PS_DISTILL; + + return RunGhostscriptAsync(gsparams); +}</code></pre> +<p>Here we can see a parameter payload being setup before being passed on to the asynchronous method <code>RunGhostscriptAsync</code> which sets up a worker thread to run according to the task type in the payload.</p> +<p><code>GhostNET</code> handles many common operations on an application developer's behalf, however if you require to write your own methods to interface with <code>GhostAPI</code> then referring to the public methods in <code>GhostNET</code> is a good starting point.</p> +<p>For full documentation on parameters refer to <a href="https://www.ghostscript.com/doc/current/Use.htm#Parameters">Ghostscript parameters</a>.</p> +<h2 id="the-event-class">The Event class</h2> +<p><code>GhostNET</code> contains a public class <code>gsEventArgs</code> which is an extension of the C# class <a href="https://docs.microsoft.com/en-us/dotnet/api/system.eventargs?view=net-5.0">EventArgs</a>. This class is used to set and get events as they occur. <code>GhostNET</code> will create these payloads and deliver them back to the application layer's <code>ProgressCallBack</code> method <a href="#delegates">asynchronously</a>.</p> +<div class="tag classDefinition csharp"></div> + +<pre><code class="language-c">public class gsEventArgs : EventArgs +{ + private bool m_completed; + private int m_progress; + private gsParamState_t m_param; + public bool Completed + { + get { return m_completed; } + } + public gsParamState_t Params + { + get { return m_param; } + } + public int Progress + { + get { return m_progress; } + } + public gsEventArgs(bool completed, int progress, gsParamState_t param) + { + m_completed = completed; + m_progress = progress; + m_param = param; + } +}</code></pre> +<h2 id="gsnet">GSNET</h2> +<p>This class should be instantiated as a member variable in your application with callback definitions setup as required.</p> +<p>Handlers for asynchronous operations can injected by providing your own bespoke callback methods to your instance's <code>ProgressCallBack</code> function.</p> +<div class="tag sampleCode csharp"></div> + +<pre><code class="language-c">/* Set up ghostscript with callbacks for system updates */ +m_ghostscript = new GSNET(); +m_ghostscript.ProgressCallBack += new GSNET.Progress(gsProgress); +m_ghostscript.StdIOCallBack += new GSNET.StdIO(gsIO); +m_ghostscript.DLLProblemCallBack += new GSNET.DLLProblem(gsDLL); +m_ghostscript.PageRenderedCallBack += new GSNET.PageRendered(gsPageRendered); +m_ghostscript.DisplayDeviceOpen(); + +/* example callback stubs for asynchronous operations */ +private void gsProgress(gsEventArgs asyncInformation) +{ + Console.WriteLine($"gsProgress().progress:{asyncInformation.Progress}"); + + if (asyncInformation.Completed) // task complete + { + // what was the task? + switch (asyncInformation.Params.task) + { + case GS_Task_t.CREATE_XPS: + Console.WriteLine($"CREATE_XPS.outputfile:"); + Console.WriteLine($"{asyncInformation.Params.result.outputfile}"); + break; + + case GS_Task_t.PS_DISTILL: + Console.WriteLine($"PS_DISTILL.outputfile:"); + Console.WriteLine($"{asyncInformation.Params.result.outputfile}"); + break; + + case GS_Task_t.SAVE_RESULT: + + break; + + case GS_Task_t.DISPLAY_DEV_THUMBS: + + break; + + case GS_Task_t.DISPLAY_DEV_RUN_FILE: + + break; + + case GS_Task_t.DISPLAY_DEV_PDF: + + break; + + case GS_Task_t.DISPLAY_DEV_NON_PDF: + + break; + + default: + + break; + } + + // task failed + if (asyncInformation.Params.result == GS_Result_t.gsFAILED) + { + switch (asyncInformation.Params.task) + { + case GS_Task_t.CREATE_XPS: + + break; + + case GS_Task_t.PS_DISTILL: + + break; + + case GS_Task_t.SAVE_RESULT: + + break; + + default: + + break; + } + return; + } + + // task cancelled + if (asyncInformation.Params.result == GS_Result_t.gsCANCELLED) + { + + } + } + else // task is still running + { + switch (asyncInformation.Params.task) + { + case GS_Task_t.CREATE_XPS: + + break; + + case GS_Task_t.PS_DISTILL: + + break; + + case GS_Task_t.SAVE_RESULT: + + break; + } + } +} + +private void gsIO(String message, int len) +{ + Console.WriteLine($"gsIO().message:{message}, length:{len}"); +} + +private void gsDLL(String message) +{ + Console.WriteLine($"gsDLL().message:{message}"); +} + +private void gsPageRendered(int width, + int height, + int raster, + IntPtr data, + gsParamState_t state) +{ + +};</code></pre> +<blockquote> +<p><strong>NOTE</strong><br>Once a Ghostscript operation is in progress any defined callback functions will be called as the operation runs up unto completion. These callback methods are essential for your application to interpret activity events and react accordingly.</p> +</blockquote> +<p>An explanation of callbacks and the available public methods within <code>GSNET</code> are explained below.</p> +<h3 id="delegates">Delegates</h3> +<p>To handle asynchronous events <code>GhostNET</code> has four delegates which define callback methods that an application can assign to.</p> +<table> +<thead> +<tr> +<th>Callback</th> +<th>Description</th> +</tr> +</thead> +<tbody><tr> +<td><code>DLLProblemCallBack</code></td> +<td>Occurs if there is some issue with the Ghostscript DLL</td> +</tr> +<tr> +<td><code>StdIOCallBack</code></td> +<td>Occurs if Ghostscript outputs something to <code>stderr</code> or <code>stdout</code></td> +</tr> +<tr> +<td><code>ProgressCallBack</code></td> +<td>Occurs as Ghostscript makes its way through a file</td> +</tr> +<tr> +<td><code>PageRenderedCallBack</code></td> +<td>Occurs when a page has been rendered and the data from the display device is ready</td> +</tr> +</tbody></table> +<h4 id="dllproblemcallback">DLLProblemCallBack</h4> +<div class="tag callbackDefinition csharp"></div> + +<pre><code class="language-c">internal delegate void DLLProblem(String mess); +internal event DLLProblem DLLProblemCallBack;</code></pre> +<h4 id="stdiocallback">StdIOCallBack</h4> +<div class="tag callbackDefinition csharp"></div> + +<pre><code class="language-c">internal delegate void StdIO(String mess, + int len); +internal event StdIO StdIOCallBack;</code></pre> +<h4 id="progresscallback">ProgressCallBack</h4> +<div class="tag callbackDefinition csharp"></div> + +<pre><code class="language-c">internal delegate void Progress(gsEventArgs info); +internal event Progress ProgressCallBack;</code></pre> +<h4 id="pagerenderedcallback">PageRenderedCallBack</h4> +<div class="tag callbackDefinition csharp"></div> + +<pre><code class="language-c">internal delegate void PageRendered(int width, + int height, + int raster, + IntPtr data, + gsParamState_t state); +internal event PageRendered PageRenderedCallBack;</code></pre> +<h3 id="getversion">GetVersion</h3> +<p>Use this method to get Ghostscript version info as a handy <code>String</code>.</p> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public String GetVersion()</code></pre> +<div class="tag sampleCode csharp"></div> + +<pre><code class="language-c">String gs_vers = m_ghostscript.GetVersion();</code></pre> +<blockquote> +<p><strong>NOTE</strong><br>An exception will be thrown if there is any issue with the Ghostscript DLL.</p> +</blockquote> +<h3 id="displaydeviceopen">DisplayDeviceOpen</h3> +<p>Sets up the <a href="https://ghostscript.com/doc/current/Devices.htm#Display_devices">display device</a> ahead of time.</p> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public gsParamState_t DisplayDeviceOpen()</code></pre> +<div class="tag sampleCode csharp"></div> + +<pre><code class="language-c">m_ghostscript.DisplayDeviceOpen();</code></pre> +<blockquote> +<p><strong>NOTE</strong><br>Calling this method <a href="c-sharp-ghost-api.html#gsapi_new_instance">instantiates ghostscript</a> and configures the encoding and the callbacks for the display device.</p> +</blockquote> +<h3 id="displaydeviceclose">DisplayDeviceClose</h3> +<p>Closes the <a href="https://ghostscript.com/doc/current/Devices.htm#Display_devices">display device</a> and deletes the instance.</p> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public gsParamState_t DisplayDeviceClose()</code></pre> +<div class="tag sampleCode csharp"></div> + +<pre><code class="language-c">m_ghostscript.DisplayDeviceClose();</code></pre> +<blockquote> +<p><strong>NOTE</strong><br>Calling this method <a href="c-sharp-ghost-api.html#gsapi_delete_instance">deletes ghostscript</a>.</p> +</blockquote> +<h3 id="getpagecount">GetPageCount</h3> +<p>Use this method to get the number of pages in a supplied document.</p> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public int GetPageCount(String fileName)</code></pre> +<div class="tag sampleCode csharp"></div> + +<pre><code class="language-c">int page_number = m_ghostscript.GetPageCount("my_document.pdf");</code></pre> +<blockquote> +<p><strong>NOTE</strong><br>If Ghostscript is unable to determine the page count then this method will return <code>-1</code>.</p> +</blockquote> +<h3 id="createxps">CreateXPS</h3> +<p>Launches a thread to create an XPS document for Windows printing. This method is <a href="#delegates">asynchronous</a> and logic should be hooked into your application upon <a href="#gsnet">GSNET instantiation</a> to interpret progress.</p> +<div class="tag methodDefinition csharp async"></div> + +<pre><code class="language-c">public gsStatus CreateXPS(String fileName, + int resolution, + int num_pages, + double width, + double height, + bool fit_page, + int firstpage, + int lastpage)</code></pre> +<div class="tag sampleCode csharp"></div> + +<pre><code class="language-c">m_ghostscript.CreateXPS("my_document.pdf", + 300, + 10, + 1000, + 1000, + true, + 0, + 9);</code></pre> +<span class="smallText alignRight"> + +<p><em><a href="#delegates">asynchronous</a></em></p> +</span> + +<h3 id="distillps">DistillPS</h3> +<p>Launches a thread rendering all the pages of a supplied PostScript file to a PDF.</p> +<div class="tag methodDefinition csharp async"></div> + +<pre><code class="language-c">public gsStatus DistillPS(String fileName, int resolution)</code></pre> +<div class="tag sampleCode csharp"></div> + +<pre><code class="language-c">m_ghostscript.DistillPS("my_postscript_document.ps", 300);</code></pre> +<span class="smallText alignRight"> + +<p><em><a href="#delegates">asynchronous</a></em></p> +</span> + + +<h3 id="displaydevicerunfile">DisplayDeviceRunFile</h3> +<p>Launches a thread to run a file with the <a href="https://ghostscript.com/doc/current/Devices.htm#Display_devices">display device</a>.</p> +<div class="tag methodDefinition csharp async"></div> + +<pre><code class="language-c">public gsStatus DisplayDeviceRunFile(String fileName, + double zoom, + bool aa, // anti-aliasing value + int firstpage, + int lastpage)</code></pre> +<div class="tag sampleCode csharp"></div> + +<pre><code class="language-c">m_ghostscript.DisplayDeviceRunFile("my_document.pdf", + 1.0, + true, + 0, + 9);</code></pre> +<span class="smallText alignRight"> + +<p><em><a href="#delegates">asynchronous</a></em></p> +</span> + +<h3 id="displaydevicerenderthumbs">DisplayDeviceRenderThumbs</h3> +<p>Launches a thread rendering all the pages with the <a href="https://ghostscript.com/doc/current/Devices.htm#Display_devices">display device</a> to collect thumbnail images.</p> +<p>Recommended zoom level for thumbnails is between 0.05 and 0.2, additionally anti-aliasing is probably not required.</p> +<div class="tag methodDefinition csharp async"></div> + +<pre><code class="language-c">public gsStatus DisplayDeviceRenderThumbs(String fileName, + double zoom, + bool aa)</code></pre> +<div class="tag sampleCode csharp"></div> + +<pre><code class="language-c">m_ghostscript.DisplayDeviceRenderThumbs("my_document.pdf", + 0.1, + false);</code></pre> +<span class="smallText alignRight"> + +<p><em><a href="#delegates">asynchronous</a></em></p> +</span> + +<h3 id="displaydevicerenderpages">DisplayDeviceRenderPages</h3> +<p>Launches a thread rendering a set of pages with the <a href="https://ghostscript.com/doc/current/Devices.htm#Display_devices">display device</a>. For use with languages that can be indexed via pages which include PDF and XPS. <sup><a href="#1-ghostscript-page-description-languages">1</a></sup></p> +<div class="tag methodDefinition csharp async"></div> + +<pre><code class="language-c">public gsStatus DisplayDeviceRenderPages(String fileName, + int first_page, + int last_page, + double zoom)</code></pre> +<div class="tag sampleCode csharp"></div> + +<pre><code class="language-c">m_ghostscript.DisplayDeviceRenderPages("my_document.pdf", + 0, + 9, + 1.0);</code></pre> +<span class="smallText alignRight"> + +<p><em><a href="#delegates">asynchronous</a></em></p> +</span> + + + + +<h3 id="getstatus">GetStatus</h3> +<p>Returns the current <a href="#status">status</a> of <code>Ghostscript</code>.</p> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public gsStatus GetStatus()</code></pre> +<div class="tag sampleCode csharp"></div> + +<pre><code class="language-c">gsStatus status = m_ghostscript.GetStatus();</code></pre> +<h3 id="cancel">Cancel</h3> +<p>Cancels <a href="#delegates">asynchronous</a> operations.</p> +<div class="tag methodDefinition csharp"></div> + +<pre><code class="language-c">public void Cancel()</code></pre> +<div class="tag sampleCode csharp"></div> + +<pre><code class="language-c">m_ghostscript.Cancel();</code></pre> +<h3 id="ghostscriptexception">GhostscriptException</h3> +<p>An application developer can log any exceptions in this public class as required by editing the constructor.</p> +<div class="tag classDefinition csharp"></div> + +<pre><code class="language-c">public class GhostscriptException : Exception +{ + public GhostscriptException(string message) : base(message) + { + // Report exceptions as required + } +}</code></pre> +<h2 id="notes">Notes</h2> +<h4 id="1-ghostscript-page-description-languages">1: Ghostscript & Page Description Languages</h4> +<p>Ghostscript handles the following <a href="https://en.wikipedia.org/wiki/Page_description_language">PDLs</a>: <code>PCL</code> <code>PDF</code> <code>PS</code> <code>XPS</code>.</p> +<p><code>PCL</code> and <code>PS</code> do not allow random access, meaning that, to print page 2 in a 100 page document, Ghostscript has to read the entire document stream of 100 pages.</p> +<p>On the other hand, <code>PDF</code> and <code>XPS</code> allow for going directly to page 2 and then only dealing with that content. The tasks <code>DISPLAY_DEV_NON_PDF</code> and <code>DISPLAY_DEV_PDF</code> keep track of what sort of input Ghostscript is dealing with and enables the application to direct progress or completion callbacks accordingly.</p> +</article> + + </div><!-- /middle --> + + <div class="right"> + + <div class="link"><a href="#about">About</a></div> + <div class="link"><a href="#enums">Enums</a></div> + <div class="sub-link"><a href="#tasks">Tasks</a></div> + <div class="sub-link"><a href="#results">Results</a></div> + <div class="sub-link"><a href="#status">Status</a></div> + <div class="link"><a href="#the-parameter-struct">The Parameter Struct</a></div> + <div class="sub-link"><a href="#parameters-explained">Parameters explained</a></div> + <div class="link"><a href="#the-event-class">The Event class</a></div> + <div class="link"><a href="#gsnet">GSNET</a></div> + <div class="sub-link"><a href="#delegates">Delegates</a></div> + <div class="sub-link"><a href="#getversion">GetVersion</a></div> + <div class="sub-link"><a href="#displaydeviceopen">DisplayDeviceOpen</a></div> + <div class="sub-link"><a href="#displaydeviceclose">DisplayDeviceClose</a></div> + <div class="sub-link"><a href="#getpagecount">GetPageCount</a></div> + <div class="sub-link"><a href="#createxps">CreateXPS</a></div> + <div class="sub-link"><a href="#distillps">DistillPS</a></div> + <div class="sub-link"><a href="#displaydevicerunfile">DisplayDeviceRunFile</a></div> + <div class="sub-link"><a href="#displaydevicerenderthumbs">DisplayDeviceRenderThumbs</a></div> + <div class="sub-link"><a href="#displaydevicerenderpages">DisplayDeviceRenderPages</a></div> + <div class="sub-link"><a href="#getstatus">GetStatus</a></div> + <div class="sub-link"><a href="#cancel">Cancel</a></div> + <div class="sub-link"><a href="#ghostscriptexception">GhostscriptException</a></div> + <div class="link"><a href="#notes">Notes</a></div> + + </div> + + </div> + + <footer></footer> + + </body> + +</html> diff --git a/doc/language-bindings/c-sharp-intro.html b/doc/language-bindings/c-sharp-intro.html new file mode 100644 index 00000000..bfcbeead --- /dev/null +++ b/doc/language-bindings/c-sharp-intro.html @@ -0,0 +1,218 @@ +<html lang="en"> + <head> + <title>Ghostscript language bindings</title> + <meta http-equiv="content-type" content="text/html; charset=utf-8"> + <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width"> + <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:200,200i,300,300i,400,400i,600,600i,700,700i,900,900i" rel="stylesheet"> + <link rel="shortcut icon" type="image/png" href="../images/favicon.png"> + <link href="css/default.css" rel="stylesheet" type="text/css" /> + <script type="text/javascript" src="js/default.js"></script> + </head> + + <body> + + <header><h1></h1><div class="menu-icon" onclick="javascript:showMenu();"></div></header> + + <div id="burger-menu"> + <div class="navigation"> + <div class="title first">Introduction</div> + <div class="link"><a href="index.html">About our APIs</a></div> + <div class="link"><a href="demo-code.html">Demo code</a></div> + + <div class="title">C#</div> + <div class="link selected"><a href="c-sharp-intro.html">Overview</a></div> + <div class="link"><a href="c-sharp-ghost-api.html">GhostAPI</a></div> + <div class="link"><a href="c-sharp-ghost-net.html">GhostNET</a></div> + <div class="link"><a href="c-sharp-ghost-mono.html">GhostMono</a></div> + + <div class="title">Java</div> + <div class="link"><a href="java-intro.html">Overview</a></div> + <div class="link"><a href="java-gsjavajar.html">gsjava.jar</a></div> + + <div class="title">Python</div> + <div class="link"><a href="python-intro.html">Overview</a></div> + <div class="link"><a href="python-gsapi.html">gsapi.py</a></div> + </div> + </div> + <div class="main"> + + <div class="left"> + <div class="title first">Introduction</div> + <div class="link"><a href="index.html">About our APIs</a></div> + <div class="link"><a href="demo-code.html">Demo code</a></div> + + <div class="title">C#</div> + <div class="link selected"><a href="c-sharp-intro.html">Overview</a></div> + <div class="link"><a href="c-sharp-ghost-api.html">GhostAPI</a></div> + <div class="link"><a href="c-sharp-ghost-net.html">GhostNET</a></div> + <div class="link"><a href="c-sharp-ghost-mono.html">GhostMono</a></div> + + <div class="title">Java</div> + <div class="link"><a href="java-intro.html">Overview</a></div> + <div class="link"><a href="java-gsjavajar.html">gsjava.jar</a></div> + + <div class="title">Python</div> + <div class="link"><a href="python-intro.html">Overview</a></div> + <div class="link"><a href="python-gsapi.html">gsapi.py</a></div> + </div> + + <div class="middle"> + +<!-- note: don't tab indent <article> as it has <pre> code which will have its layout adversly affected --> +<article class="markdown-body entry-content"><h1 id="c-overview">C# overview</h1> +<div class="banner"> + <div class="c-sharp-text"></div> + <div class="vendor-logo c-sharp-logo"></div> +</div> + +<h2 id="about">About</h2> +<p>In the <a href="https://github.com/ArtifexSoftware/ghostpdl">GhostPDL repository</a> a sample <code>C#</code> project can be found in <code>/demos/csharp</code>.</p> +<p>Within this project the following namespaces and corresponding <code>C#</code> files are of relevance:</p> +<ul> +<li><a href="#ghostapi">GhostAPI</a> <code>ghostapi.cs</code></li> +<li><a href="#ghostnet">GhostNET</a> <code>ghostnet.cs</code></li> +<li><a href="#ghostmono">GhostMono</a> <code>ghostmono.cs</code></li> +</ul> +<h2 id="platform-setup">Platform & setup</h2> +<h3 id="building-ghostscript">Building Ghostscript</h3> +<p>Ghostscript should be built as a shared library for your platform.</p> +<p>See <a href="index.html#building-ghostscript">Building Ghostscript</a>.</p> +<h2 id="ghostapi">GhostAPI</h2> +<p><code>GhostAPI</code> is the main wrapper responsible for bridging over to the <code>C</code> library and ensuring that the correct DLLs are imported.</p> +<p><code>GhostAPI</code> contains the <code>ghostapi</code> class which <em>does not</em> need to be instantiated as it provides <code>public static</code> methods. These methods, which mirror their <code>C</code> counterparts, are as follows:</p> +<table> +<thead> +<tr> +<th>Method</th> +<th>Description</th> +</tr> +</thead> +<tbody><tr> +<td><a href="c-sharp-ghost-api#gsapi_revision">gsapi_revision</a></td> +<td>Returns the revision numbers and strings of the Ghostscript interpreter library</td> +</tr> +<tr> +<td><a href="c-sharp-ghost-api#gsapi_new_instance">gsapi_new_instance</a></td> +<td>Create a new instance of Ghostscript</td> +</tr> +<tr> +<td><a href="c-sharp-ghost-api#gsapi_delete_instance">gsapi_delete_instance</a></td> +<td>Destroy an instance of Ghostscript</td> +</tr> +<tr> +<td><a href="c-sharp-ghost-api#gsapi_set_stdio_with_handle">gsapi_set_stdio_with_handle</a></td> +<td>Set the callback functions for <code>stdio</code>, together with the handle to use in the callback functions</td> +</tr> +<tr> +<td><a href="c-sharp-ghost-api#gsapi_set_stdio">gsapi_set_stdio</a></td> +<td>Set the callback functions for <code>stdio</code></td> +</tr> +<tr> +<td><a href="c-sharp-ghost-api#gsapi_set_poll_with_handle">gsapi_set_poll_with_handle</a></td> +<td>Set the callback function for polling, together with the handle to pass to the callback function</td> +</tr> +<tr> +<td><a href="c-sharp-ghost-api#gsapi_set_poll">gsapi_set_poll</a></td> +<td>Set the callback function for polling</td> +</tr> +<tr> +<td><a href="c-sharp-ghost-api#gsapi_set_display_callback">gsapi_set_display_callback</a></td> +<td><em>deprecated</em></td> +</tr> +<tr> +<td><a href="c-sharp-ghost-api#gsapi_register_callout">gsapi_register_callout</a></td> +<td>This call registers a callout handler</td> +</tr> +<tr> +<td><a href="c-sharp-ghost-api#gsapi_deregister_callout">gsapi_deregister_callout</a></td> +<td>This call deregisters a previously registered callout handler</td> +</tr> +<tr> +<td><a href="c-sharp-ghost-api#gsapi_set_arg_encoding">gsapi_set_arg_encoding</a></td> +<td>Set the encoding used for the interpretation of all subsequent args supplied via the gsapi interface on this instance</td> +</tr> +<tr> +<td><a href="c-sharp-ghost-api#gsapi_set_default_device_list">gsapi_set_default_device_list</a></td> +<td>Set the string containing the list of default device names</td> +</tr> +<tr> +<td><a href="c-sharp-ghost-api#gsapi_get_default_device_list">gsapi_get_default_device_list</a></td> +<td>Returns a pointer to the current default device string</td> +</tr> +<tr> +<td><a href="c-sharp-ghost-api#gsapi_init_with_args">gsapi_init_with_args</a></td> +<td>Initialise the interpreter</td> +</tr> +<tr> +<td><a href="c-sharp-ghost-api#gsapi_run_wildcard">gsapi_run_*</a></td> +<td>Wildcard for various "run" methods</td> +</tr> +<tr> +<td><a href="c-sharp-ghost-api#gsapi_exit">gsapi_exit</a></td> +<td>Exit the interpreter</td> +</tr> +<tr> +<td><a href="c-sharp-ghost-api#gsapi_set_param">gsapi_set_param</a></td> +<td>Set a parameter</td> +</tr> +<tr> +<td><a href="c-sharp-ghost-api#gsapi_get_param">gsapi_get_param</a></td> +<td>Get a parameter</td> +</tr> +<tr> +<td><a href="c-sharp-ghost-api#gsapi_enumerate_params">gsapi_enumerate_params</a></td> +<td>Enumerate the current parameters</td> +</tr> +<tr> +<td><a href="c-sharp-ghost-api#gsapi_add_control_path">gsapi_add_control_path</a></td> +<td>Add a (case sensitive) path to one of the lists of permitted paths for file access</td> +</tr> +<tr> +<td><a href="c-sharp-ghost-api#gsapi_remove_control_path">gsapi_remove_control_path</a></td> +<td>Remove a (case sensitive) path from one of the lists of permitted paths for file access</td> +</tr> +<tr> +<td><a href="c-sharp-ghost-api#gsapi_purge_control_paths">gsapi_purge_control_paths</a></td> +<td>Clear all the paths from one of the lists of permitted paths for file access</td> +</tr> +<tr> +<td><a href="c-sharp-ghost-api#gsapi_activate_path_control">gsapi_activate_path_control</a></td> +<td>Enable/Disable path control</td> +</tr> +<tr> +<td><a href="c-sharp-ghost-api#gsapi_is_path_control_active">gsapi_is_path_control_active</a></td> +<td>Query whether path control is activated or not</td> +</tr> +</tbody></table> +<h2 id="ghostnet">GhostNET</h2> +<p><code>GhostNET</code> is the <a href="https://dotnet.microsoft.com/">.NET</a> interface into <code>GhostAPI</code>. It exemplifies how to do more complex operations involving multiple API calls and sequences.</p> +<h3 id="ghostnet-wpf-example">GhostNET WPF example</h3> +<p>In <code>demos/csharp/windows/ghostnet.sln</code> there is a sample C# demo project.</p> +<p>This project can be opened in <a href="https://visualstudio.microsoft.com">Visual Studio</a> and used to test the Ghostscript API alongside a UI which handles opening PostScript and PDF files. The sample application here allows for file browsing and Ghostscript file viewing.</p> +<p>Below is a screenshot of the sample application with a PDF open:</p> +<p><img src="images/ghostnet-wpf-example.png" alt="ghostnet wpf example UI"></p> +<h2 id="ghostmono">GhostMono</h2> +<p><code>GhostMono</code> is the <a href="https://www.mono-project.com/">Mono</a> equivalent of <code>GhostNET</code> and as such has no dependancy on a Windows environment.</p> +</article> + + </div> + + <div class="right"> + + <div class="link"><a href="#about">About</a></div> + <div class="link"><a href="#platform-setup">Platform & setup</a></div> + <div class="sub-link"><a href="#building-ghostscript">Building Ghostscript</a></div> + <div class="link"><a href="#ghostapi">GhostAPI</a></div> + <div class="link"><a href="#ghostnet">GhostNET</a></div> + <div class="sub-link"><a href="#ghostnet-wpf-example">GhostNET WPF example</a></div> + <div class="link"><a href="#ghostmono">GhostMono</a></div> + + </div> + + </div> + + <footer></footer> + + </body> + +</html> diff --git a/doc/language-bindings/css/default.css b/doc/language-bindings/css/default.css new file mode 100644 index 00000000..16297c1f --- /dev/null +++ b/doc/language-bindings/css/default.css @@ -0,0 +1,735 @@ +* { + -webkit-tap-highlight-color: rgba(0,0,0,0); + -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; + box-sizing: border-box; +} + +html, body, div, span, applet, object, iframe, +h1, h2, h3, h4, h5, h6, p, blockquote, pre, +a, abbr, acronym, address, big, cite, code, +del, dfn, em, img, ins, kbd, q, s, samp, +small, strike, strong, sub, tt, var, +b, u, i, center, +dl, dt, dd, ol, ul, li, +fieldset, form, label, legend, +table, caption, tbody, tfoot, thead, tr, th, td, +article, aside, canvas, details, embed, +figure, figcaption, footer, header, hgroup, +menu, nav, output, ruby, section, summary, +time, mark, audio, video { + margin: 0; + padding: 0; + border: 0; + font-size: 100%; + font: inherit; + vertical-align: baseline; +} + +/* HTML5 display-role reset for older browsers */ +article, aside, details, figcaption, figure, +footer, header, hgroup, menu, nav, section { + display: block; +} + +html, body { + position: relative; + height: 100%; +} + +body { + -webkit-touch-callout: none; /* prevent callout to copy image, etc when tap to hold */ + -webkit-text-size-adjust: none; /* prevent webkit from resizing text to fit */ + -webkit-user-select: text; /* prevent copy paste, to allow, change 'none' to 'text' */ + color:black; + background:#f9f9f9; + font-family:"Source Sans Pro", sans-serif; /* 200 = ExtraLight, 300 = Light, 400 = regular, 600 = semi-bold, 700 = bold, 900 = black */ + font-weight:400; + font-size:16px; + margin:0px; + padding:0px; +} + +.markdown-body, .entry-content { + padding: 0; +} + +.markdown-body code { + background-color: #ddd; + border-radius: 3px; + padding: 2px 6px; + font-family: monospace; +} + +.markdown-body pre { + background-color: #ddd; + word-wrap:normal; + margin-bottom:20px; + padding:20px; + overflow:auto; + font-size:85%; + line-height:1.45; + border-radius:3px +} + +.markdown-body pre>code { + padding:0; + margin:0; + font-size:100%; + word-break:normal; + white-space:pre; + background:transparent; + border:0; +} + +.markdown-body pre code, .markdown-body pre tt { + display:inline; + padding:0; + margin:0; + overflow:visible; + line-height:inherit; + word-wrap:normal; + background-color:transparent; + border:0 +} + +.markdown-body pre code::before, +.markdown-body pre code::after, +.markdown-body pre tt::before, +.markdown-body pre tt::after { + content:normal +} + +.markdown-body table { + color: #000; +} + +.markdown-body table code { + color: #000; +} + +.markdown-body table tr { + background-color: #fff; + border-bottom: 1px solid #c0c0c0; +} + +.markdown-body table tr:nth-child(2n) { + background-color: #ddd; +} + +header { + position: fixed; + width: 100%; + height:50px; + background: #0075cf url(../images/ghostscript.png) 10px center no-repeat; + background-size: 30px 30px; + color: #fff; + line-height: 50px; + text-indent: 50px; + z-index: 1; + display: flex; + justify-content: space-between; +} + +header .menu-icon { + display: none; + margin-right: 10px; + width:50px; + height:50px; + background:transparent url(../images/icon-burger-menu.png) center center no-repeat; + background-size: 50px 50px; +} + +header h1::after { + content: "Ghostscript language bindings"; +} + +footer::after { + content:"Copyright \00A9 2021 Artifex Software Inc. All rights reserved."; +} + +a { + text-decoration: none; + color: #0075cf; +} + +/** for in page anchor positioning - this offset is the height of the fixed header +/** This appends a pseudo-element before every h2/h3 tag with an id. +Adjusted height to accommodate header. **/ +h2[id]::before, h3[id]::before, h4[id]::before { + content: ''; + display: block; + height: 50px; + margin: 0; +} + +.main .middle h2, .main .middle h3, .main .middle h4 { + margin-top: -50px; + padding-top: 20px; +} + +.main .middle h2 { + border-bottom: 3px solid #999; +} + +.main .middle h3 { + border-bottom: 1px solid #999; +} + +i { + font-style: italic; +} + +p { + line-height: 24px; +} + +header h1 { + font-size:24px; + font-weight:600; +} + +h1 { + font-size:40px; + font-weight:600; +} + +h2 { + font-weight:600; + font-size:26px; + margin-bottom: 10px; +} + +h3 { + font-weight:600; + font-size:20px; + margin-bottom: 10px; +} + +h4 { + font-weight:600; + font-size:16px; + margin-bottom: 10px; +} + +li { + margin: 10px; +} + +table { + margin: 20px 0; + border-collapse: collapse; + table-layout:fixed; + max-width:600px; + width: 100%; + border: 1px solid #c0c0c0; +} + +th { + font-weight: bold; + background-color:#666; + color: #fff; + border-bottom: 1px solid #c0c0c0; + border-right: 1px solid #c0c0c0; +} + +tr { + text-overflow:clip; +} + +th, td { + text-align: left; + padding:14px; + word-wrap:break-word; +} + +td { + border-right: 1px solid #c0c0c0; +} + +footer { + position: relative; + left: 20%; + width: 60%; + height: 100px; + margin: 50px 0 0 0; + padding: 50px 20px; + background: url(../images/artifex-logo.png) 20px 0 no-repeat; + background-size: 200px auto; +} + + +em { + font-style: italic; +} + +#burger-menu { + display: none; + position: fixed; + top: 50px; + right: 0; + text-align: right; + z-index: 1; + background-color: rgba(0,0,0,0.95); + padding: 20px; + border-radius: 20px; + border: 1px solid #c0c0c0; + bottom:0; + overflow-y:scroll; + overflow-x:hidden; +} + +#burger-menu.show { + display: block; +} + +#burger-menu .navigation .title { + color: #fff; + margin-top: 8px; +} + +#burger-menu .navigation .link { + text-indent: 5px; + margin: 5px 10px 5px 0; +} + +.main { + padding-top: 50px; + display: flex; +} + +.main .left { + position: fixed; + margin: 0px; + inset: 50px auto 0 0; + width: 20%; + overflow-y:auto; + overflow-x:hidden; + padding: 20px 0 20px 20px; + border-right: 1px solid gainsboro; +} + +.main .left div { + padding: 2px 0 2px 0; +} + +.main .left .link { + padding-left: 40px; + text-indent: -20px; +} + +.main .left .link { + padding-left: 40px; + text-indent: -20px; +} + +.main .left .group { + padding-left: 20px; +} + +.main .left .link.selected, #burger-menu .navigation .link.selected { + background-color: #0075cf; + color: #fff; +} + +.main .left .link.selected a, #burger-menu .navigation .link.selected a{ + color: #fff; +} + +.main .middle { + position: relative; + left: 20%; + width: 60%; + padding: 10px 20px 20px 20px; +} + +.main article { + margin: auto; +} + +.main .middle p { + margin-bottom: 20px; +} + +.main .middle ul { + margin: 0 0 20px 20px; +} + +.main .middle img { + width: 100%; +} + +blockquote { + background-color: #eee; + width: 100%; + height: auto; + padding: 20px; + border-radius: 10px; + margin: 0 0 20px 0; +} + +blockquote strong { + font-size: 16px; + font-weight: bold; +} + +.markdown-body blockquote code { + background: #bbb; +} + +.main .right { + inset: 50px 0 0 auto; + width: 20%; + position:fixed; + overflow-y:auto; + overflow-x:hidden; + padding: 20px; + border-left: 1px solid gainsboro; +} + +.main .right .link { + padding: 2px 0 2px 20px; + text-indent: -20px; +} + +.main .right .sub-link { + padding: 1px 0 1px 40px; + text-indent: -20px; + font-size:12px; + word-wrap: break-word; +} + +.banner { + margin: 20px 0; + display:flex; + justify-content: space-between; + width:100%; + height:50px; + line-height:50px; + font-weight:bold; +} + +.banner.intro { + justify-content: flex-end; +} + +.vendor-logo { + width:25%; + height:50px; +} + +.gs-logo { + background: url(../images/ghostscript-grey.png) center center no-repeat; + background-size: 50px 50px; +} + +.c-logo { + width:50px; + height:50px; + background: url(../images/icon-vendor-c.png) center center no-repeat; + background-size: 50px 50px; +} + +.c-sharp-logo { + background: url(../images/icon-vendor-c-sharp.png) center center no-repeat; + background-size: 50px 50px; +} + +.java-logo { + background: url(../images/icon-vendor-java.png) center center no-repeat; + background-size: 50px 50px; +} + +.python-logo { + background: url(../images/icon-vendor-python.png) center center no-repeat; + background-size: 50px 50px; +} + +.banner.intro { + justify-content: flex-end; +} + +.banner .default-text::after { + content:""; +} + +.banner .c-sharp-text::after { + content:"C# API"; +} + +.banner .java-text::after { + content:"Java API"; +} + +.banner .python-text::after { + content:"Python API"; +} + +.tag { + padding:5px 0px; + background-color:transparent; + color:#666; + font-size:10px; +} + +.tag.shellCommand::before { + width:100%; + content:"\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0 SHELL COMMAND"; + background: url(../images/icon-shell-command.png) left center no-repeat; + background-size:13px 13px; +} + +.tag.sampleCode::after { + content:"SAMPLE CODE"; +} + +.tag.sampleCode.csharp::after { + width:100%; + content:"\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0 SAMPLE CODE"; + background: url(../images/icon-vendor-c-sharp.png) left center no-repeat; + background-size:13px 13px; +} + +.tag.sampleCode.java::after { + width:100%; + content:"\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0 SAMPLE CODE"; + background: url(../images/icon-vendor-java.png) left center no-repeat; + background-size:20px 20px; +} + +.tag.sampleCode.python::after { + width:100%; + content:"\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0 SAMPLE CODE"; + background: url(../images/icon-vendor-python.png) left center no-repeat; + background-size:13px 13px; +} + +.tag.structDefinition::after { + content:"STRUCT DEFINITION"; +} + +.tag.structDefinition.csharp::after { + width:100%; + content:"\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0 STRUCT DEFINITION"; + background: url(../images/icon-vendor-c-sharp.png) left center no-repeat; + background-size:13px 13px; +} + +.tag.enumDefinition::after { + content:"ENUM DEFINITION"; +} + +.tag.enumDefinition.csharp::after { + width:100%; + content:"\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0 ENUM DEFINITION"; + background: url(../images/icon-vendor-c-sharp.png) left center no-repeat; + background-size:13px 13px; +} + +.tag.enumDefinition.python::after { + width:100%; + content:"\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0 ENUM DEFINITION"; + background: url(../images/icon-vendor-python.png) left center no-repeat; + background-size:13px 13px; +} + +.tag.methodDefinition::after { + content:"METHOD DEFINITION"; +} + +.tag.methodDefinition.csharp::after { + width:100%; + content:"\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0 METHOD DEFINITION"; + background: url(../images/icon-vendor-c-sharp.png) left center no-repeat; + background-size:13px 13px; +} + +.tag.methodDefinition.java::after { + width:100%; + content:"\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0 METHOD DEFINITION"; + background: url(../images/icon-vendor-java.png) left center no-repeat; + background-size:20px 20px; +} + +.tag.methodDefinition.python::after { + width:100%; + content:"\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0 METHOD DEFINITION"; + background: url(../images/icon-vendor-python.png) left center no-repeat; + background-size:13px 13px; +} + +.tag.classDefinition::after { + content:"CLASS DEFINITION"; +} + +.tag.classDefinition.csharp::after { + width:100%; + content:"\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0 CLASS DEFINITION"; + background: url(../images/icon-vendor-c-sharp.png) left center no-repeat; + background-size:13px 13px; +} + +.tag.classDefinition.java::after { + width:100%; + content:"\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0 CLASS DEFINITION"; + background: url(../images/icon-vendor-java.png) left center no-repeat; + background-size:20px 20px; +} + +.tag.callbackDefinition::after { + content:"DELEGATE DEFINITION"; +} + +.tag.callbackDefinition.csharp::after { + width:100%; + content:"\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0 DELEGATE DEFINITION"; + background: url(../images/icon-vendor-c-sharp.png) left center no-repeat; + background-size:13px 13px; +} + +.tag.functionalInterface.java::after { + width:100%; + content:"\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0\00a0 FUNCTIONAL INTERFACE"; + background: url(../images/icon-vendor-java.png) left center no-repeat; + background-size:20px 20px; +} + +.smallText { + line-height: 12px; + font-size: 12px; +} + +.alignRight { + text-align: right; +} + +button.cta { + -webkit-appearance: none; + -moz-appearance: none; + border:0; + text-transform:uppercase; + border-radius:5px; + font-size:16px; + font-weight:500; + min-height:40px; + line-height:40px; + padding: 0 15px; + color:#fff; + cursor:pointer; +} + +button.cta.orange { + width:auto; + background-image: linear-gradient(to right, #ea5842, #ec6343, #ed6d45, #ef7747, #f0804a); +} + +button.cta.orange:hover { + background:#ea5842; +} + +button.cta a { + color:#fff; +} + +/* Dark mode */ +@media (prefers-color-scheme: dark) { + + body { + background-color: #111; + color: white; + } + + .markdown-body code, .markdown-body pre, code, .markdown-body blockquote code { + background-color: #444; + } + + .markdown-body table { + color: #fff; + } + + .markdown-body table code { + color: #fff; + } + + .markdown-body table tr { + background-color: #000; + } + + .markdown-body table tr:nth-child(2n) { + background-color: #222; + } + + footer { + background: url(../images/artifex-logo-white.png) 20px 0 no-repeat; + background-size: 200px auto; + } + + .main .middle .note, blockquote { + color: #000; + background-color: #fff; + } + + .main .middle .note code, blockquote code { + color: #fff; + } + + .vendor-logo, .tag { + -webkit-filter: invert(100%); + filter: invert(100%); + } +} + + +/* responsive sizes */ +@media only screen and (max-width: 1023px) { + .banner.intro { + justify-content: center; + } +} + +/* < Tablet portrait */ +@media all and (max-width : 767px) { + header .menu-icon { + display: block; + } + + footer { + left: 0%; + width: 100%; + } + + .main .left { + width: 0%; + display: none; + } + + .main .middle { + left: 0; + width: 100%; + } + + .main .right { + width: 0; + display: none; + } + + table { + width: 100%; + } +} + +@media all and (max-width : 375px) { + header h1 { + font-size:20px; + } + + table tr td { + font-size: 13px; + } +} + +@media all and (max-width : 320px) { + header h1 { + font-size:16px; + } +} diff --git a/doc/language-bindings/demo-code.html b/doc/language-bindings/demo-code.html new file mode 100644 index 00000000..876e3cb7 --- /dev/null +++ b/doc/language-bindings/demo-code.html @@ -0,0 +1,91 @@ +<html lang="en"> + <head> + <title>Ghostscript language bindings</title> + <meta http-equiv="content-type" content="text/html; charset=utf-8"> + <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width"> + <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:200,200i,300,300i,400,400i,600,600i,700,700i,900,900i" rel="stylesheet"> + <link rel="shortcut icon" type="image/png" href="../images/favicon.png"> + <link href="css/default.css" rel="stylesheet" type="text/css" /> + <script type="text/javascript" src="js/default.js"></script> + </head> + + <body> + + <header><h1></h1><div class="menu-icon" onclick="javascript:showMenu();"></div></header> + + <div id="burger-menu"> + <div class="navigation"> + <div class="title first">Introduction</div> + <div class="link"><a href="index.html">About our APIs</a></div> + <div class="link selected"><a href="demo-code.html">Demo code</a></div> + + <div class="title">C#</div> + <div class="link"><a href="c-sharp-intro.html">Overview</a></div> + <div class="link"><a href="c-sharp-ghost-api.html">GhostAPI</a></div> + <div class="link"><a href="c-sharp-ghost-net.html">GhostNET</a></div> + <div class="link"><a href="c-sharp-ghost-mono.html">GhostMono</a></div> + + <div class="title">Java</div> + <div class="link"><a href="java-intro.html">Overview</a></div> + <div class="link"><a href="java-gsjavajar.html">gsjava.jar</a></div> + + <div class="title">Python</div> + <div class="link"><a href="python-intro.html">Overview</a></div> + <div class="link"><a href="python-gsapi.html">gsapi.py</a></div> + </div> + </div> + <div class="main"> + + <div class="left"> + <div class="title first">Introduction</div> + <div class="link"><a href="index.html">About our APIs</a></div> + <div class="link selected"><a href="demo-code.html">Demo code</a></div> + + <div class="title">C#</div> + <div class="link"><a href="c-sharp-intro.html">Overview</a></div> + <div class="link"><a href="c-sharp-ghost-api.html">GhostAPI</a></div> + <div class="link"><a href="c-sharp-ghost-net.html">GhostNET</a></div> + <div class="link"><a href="c-sharp-ghost-mono.html">GhostMono</a></div> + + <div class="title">Java</div> + <div class="link"><a href="java-intro.html">Overview</a></div> + <div class="link"><a href="java-gsjavajar.html">gsjava.jar</a></div> + + <div class="title">Python</div> + <div class="link"><a href="python-intro.html">Overview</a></div> + <div class="link"><a href="python-gsapi.html">gsapi.py</a></div> + </div> + + <div class="middle"> + +<!-- note: don't tab indent <article> as it has <pre> code which will have its layout adversly affected --> +<article class="markdown-body entry-content"> + <h1 id="demo-code">Demo code</h1> +<div class="banner intro"> + <div class="default-text"></div> + <div class="vendor-logo gs-logo"></div> + <div class="vendor-logo c-sharp-logo"></div> + <div class="vendor-logo java-logo"></div> + <div class="vendor-logo python-logo"></div> +</div> + + +<h2 id="about">About</h2> + +<p>Please locate the <code>demos</code> folder in your <code>ghostpdl</code> source code download from the <a href="https://github.com/ArtifexSoftware/ghostpdl">GhostPDL repository</a> to find sample code demonstrating the language bindings in action.</p> +</article> + </div> + + <div class="right"> + + <div class="link"><a href="#about">About</a></div> + + </div> + + </div> + + <footer></footer> + + </body> + +</html> diff --git a/doc/language-bindings/gs-language-bindings.pdf b/doc/language-bindings/gs-language-bindings.pdf Binary files differnew file mode 100644 index 00000000..f01dc597 --- /dev/null +++ b/doc/language-bindings/gs-language-bindings.pdf diff --git a/doc/language-bindings/images/artifex-logo-white.png b/doc/language-bindings/images/artifex-logo-white.png Binary files differnew file mode 100644 index 00000000..112eb9bc --- /dev/null +++ b/doc/language-bindings/images/artifex-logo-white.png diff --git a/doc/language-bindings/images/artifex-logo.png b/doc/language-bindings/images/artifex-logo.png Binary files differnew file mode 100644 index 00000000..cde238a4 --- /dev/null +++ b/doc/language-bindings/images/artifex-logo.png diff --git a/doc/language-bindings/images/export-jar.png b/doc/language-bindings/images/export-jar.png Binary files differnew file mode 100644 index 00000000..55550496 --- /dev/null +++ b/doc/language-bindings/images/export-jar.png diff --git a/doc/language-bindings/images/ghostnet-wpf-example.png b/doc/language-bindings/images/ghostnet-wpf-example.png Binary files differnew file mode 100644 index 00000000..b5b1eaa1 --- /dev/null +++ b/doc/language-bindings/images/ghostnet-wpf-example.png diff --git a/doc/language-bindings/images/ghostscript-grey.png b/doc/language-bindings/images/ghostscript-grey.png Binary files differnew file mode 100644 index 00000000..b295ad05 --- /dev/null +++ b/doc/language-bindings/images/ghostscript-grey.png diff --git a/doc/language-bindings/images/ghostscript-plus-text-white.png b/doc/language-bindings/images/ghostscript-plus-text-white.png Binary files differnew file mode 100644 index 00000000..1b3d2a4e --- /dev/null +++ b/doc/language-bindings/images/ghostscript-plus-text-white.png diff --git a/doc/language-bindings/images/ghostscript-plus-text.png b/doc/language-bindings/images/ghostscript-plus-text.png Binary files differnew file mode 100644 index 00000000..15b17e5a --- /dev/null +++ b/doc/language-bindings/images/ghostscript-plus-text.png diff --git a/doc/language-bindings/images/ghostscript.png b/doc/language-bindings/images/ghostscript.png Binary files differnew file mode 100644 index 00000000..3369a123 --- /dev/null +++ b/doc/language-bindings/images/ghostscript.png diff --git a/doc/language-bindings/images/gsviewer.png b/doc/language-bindings/images/gsviewer.png Binary files differnew file mode 100644 index 00000000..75c9d5af --- /dev/null +++ b/doc/language-bindings/images/gsviewer.png diff --git a/doc/language-bindings/images/icon-burger-menu.png b/doc/language-bindings/images/icon-burger-menu.png Binary files differnew file mode 100644 index 00000000..d70fd43c --- /dev/null +++ b/doc/language-bindings/images/icon-burger-menu.png diff --git a/doc/language-bindings/images/icon-shell-command.png b/doc/language-bindings/images/icon-shell-command.png Binary files differnew file mode 100644 index 00000000..c538bc6c --- /dev/null +++ b/doc/language-bindings/images/icon-shell-command.png diff --git a/doc/language-bindings/images/icon-vendor-c-sharp.png b/doc/language-bindings/images/icon-vendor-c-sharp.png Binary files differnew file mode 100644 index 00000000..a4bc2c6d --- /dev/null +++ b/doc/language-bindings/images/icon-vendor-c-sharp.png diff --git a/doc/language-bindings/images/icon-vendor-c.png b/doc/language-bindings/images/icon-vendor-c.png Binary files differnew file mode 100644 index 00000000..b259df47 --- /dev/null +++ b/doc/language-bindings/images/icon-vendor-c.png diff --git a/doc/language-bindings/images/icon-vendor-java.png b/doc/language-bindings/images/icon-vendor-java.png Binary files differnew file mode 100644 index 00000000..56f2ea7c --- /dev/null +++ b/doc/language-bindings/images/icon-vendor-java.png diff --git a/doc/language-bindings/images/icon-vendor-python.png b/doc/language-bindings/images/icon-vendor-python.png Binary files differnew file mode 100644 index 00000000..bdbe2330 --- /dev/null +++ b/doc/language-bindings/images/icon-vendor-python.png diff --git a/doc/language-bindings/images/linking-jar.png b/doc/language-bindings/images/linking-jar.png Binary files differnew file mode 100644 index 00000000..ce64e587 --- /dev/null +++ b/doc/language-bindings/images/linking-jar.png diff --git a/doc/language-bindings/index.html b/doc/language-bindings/index.html new file mode 100644 index 00000000..7758abd7 --- /dev/null +++ b/doc/language-bindings/index.html @@ -0,0 +1,168 @@ +<html lang="en"> + <head> + <title>Ghostscript language bindings</title> + <meta http-equiv="content-type" content="text/html; charset=utf-8"> + <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width"> + <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:200,200i,300,300i,400,400i,600,600i,700,700i,900,900i" rel="stylesheet"> + <link rel="shortcut icon" type="image/png" href="../images/favicon.png"> + <link href="css/default.css" rel="stylesheet" type="text/css" /> + <script type="text/javascript" src="js/default.js"></script> + </head> + + <body> + + <header><h1></h1><div class="menu-icon" onclick="javascript:showMenu();"></div></header> + + <div id="burger-menu"> + <div class="navigation"> + <div class="title first">Introduction</div> + <div class="link selected"><a href="index.html">About our APIs</a></div> + <div class="link"><a href="demo-code.html">Demo code</a></div> + + <div class="title">C#</div> + <div class="link"><a href="c-sharp-intro.html">Overview</a></div> + <div class="link"><a href="c-sharp-ghost-api.html">GhostAPI</a></div> + <div class="link"><a href="c-sharp-ghost-net.html">GhostNET</a></div> + <div class="link"><a href="c-sharp-ghost-mono.html">GhostMono</a></div> + + <div class="title">Java</div> + <div class="link"><a href="java-intro.html">Overview</a></div> + <div class="link"><a href="java-gsjavajar.html">gsjava.jar</a></div> + + <div class="title">Python</div> + <div class="link"><a href="python-intro.html">Overview</a></div> + <div class="link"><a href="python-gsapi.html">gsapi.py</a></div> + </div> + </div> + + <div class="main"> + <div class="left"> + <div class="title first">Introduction</div> + <div class="link selected"><a href="index.html">About our APIs</a></div> + <div class="link"><a href="demo-code.html">Demo code</a></div> + + <div class="title">C#</div> + <div class="link"><a href="c-sharp-intro.html">Overview</a></div> + <div class="link"><a href="c-sharp-ghost-api.html">GhostAPI</a></div> + <div class="link"><a href="c-sharp-ghost-net.html">GhostNET</a></div> + <div class="link"><a href="c-sharp-ghost-mono.html">GhostMono</a></div> + + <div class="title">Java</div> + <div class="link"><a href="java-intro.html">Overview</a></div> + <div class="link"><a href="java-gsjavajar.html">gsjava.jar</a></div> + + <div class="title">Python</div> + <div class="link"><a href="python-intro.html">Overview</a></div> + <div class="link"><a href="python-gsapi.html">gsapi.py</a></div> + </div> + + <div class="middle"> + + +<!-- note: don't tab indent <article> as it has <pre> code which will have its layout adversly affected --> +<article class="markdown-body entry-content"><h1 id="introduction">Introduction</h1> +<div class="banner intro"> + <div class="default-text"></div> + <div class="vendor-logo gs-logo"></div> + <div class="vendor-logo c-sharp-logo"></div> + <div class="vendor-logo java-logo"></div> + <div class="vendor-logo python-logo"></div> +</div> + +<h2 id="about-our-apis">About our APIs</h2> +<p>The core of Ghostscript is written in <code>C</code>, but also supports <a href="https://en.wikipedia.org/wiki/Language_binding">language bindings</a> for the following programming languages:</p> +<ul> +<li><code>C#</code></li> +<li><code>Java</code></li> +<li><code>Python</code></li> +</ul> +<p>All of the above languages have equivalent methods as defined in the <a href="https://www.ghostscript.com/doc/current/API.htm">C API</a>. <code>Java</code> and <code>C#</code> provide additional helper methods to make the use of the API easier for certain applications. These languages also provide example viewers that make use of these methods.</p> +<p>This developer documentation is organized by programming language type and includes API reference and sample code.</p> +<h2 id="the-c-api">The C API</h2> +<div class="vendor-logo c-logo"></div> +<p> + +</p><p>Ghostscript has been in development for over thirty years and is written in <code>C</code>. The API has evolved over time and is continually being developed. The language bindings into Ghostscript will attempt to mirror this evolution and match the current <a href="https://www.ghostscript.com/doc/current/API.htm">C API</a> as much as possible.</p> +<h2 id="licensing">Licensing</h2> +<p>Before using Ghostscript, please make sure that you have a valid license to do so. There are two available licenses; make sure you pick the one whose terms you can comply with.</p> +<h3 id="open-source-license">Open Source license</h3> +<p>If your software is open source, you may use Ghostscript under the terms of the GNU Affero General Public License.</p> +<p>This means that all of the source code for your complete app must be released under a compatible open source license!</p> +<p>It also means that you may not use any proprietary closed source libraries or components in your app.</p> +<p>Please read the full text of the AGPL license agreement from the <a href="https://www.gnu.org/licenses/agpl-3.0.html">FSF web site</a></p> +<p>If you cannot or do not want to comply with these restrictions, you must acquire a commercial license instead.</p> +<p><button class="cta orange"><a href="https://artifex.com/licensing/" target="new">FIND OUT MORE</a></button></p> +<h3 id="commercial-license">Commercial license</h3> +<p>If your project does not meet the requirements of the AGPL, please contact our sales team to discuss a commercial license. Each Artifex commercial license is crafted based on your individual use case.</p> +<p><button class="cta orange"><a href="https://artifex.com/contact/" target="new">CONTACT US</a></button></p> +<h2 id="building-ghostscript">Building Ghostscript</h2> +<p>In order to use Ghostscript language bindings firstly Ghostscript must be built as a shared library for your platform.</p> +<p>The following built libraries are required for these respective platforms:</p> +<table> +<thead> +<tr> +<th>Platform</th> +<th>Ghostscript library files</th> +</tr> +</thead> +<tbody><tr> +<td>Windows 32-bit</td> +<td><code>gpdldll32.dll</code> <code>gsdll32.dll</code></td> +</tr> +<tr> +<td>Windows 64-bit</td> +<td><code>gpdldll64.dll</code> <code>gsdll64.dll</code></td> +</tr> +<tr> +<td>MacOS</td> +<td><code>libgpdl.dylib</code> <code>libgs.dylib</code></td> +</tr> +<tr> +<td>Linux / OpenBSD</td> +<td><code>libgpdl.so</code> <code>libgs.so</code></td> +</tr> +</tbody></table> +<blockquote> +<p><strong>NOTE</strong><br> +The actual filenames on MacOS will be appended with the version of Ghostscript with associated symlinks.</p> +</blockquote> +<h3 id="building-on-windows">Building on Windows</h3> +<p>To build the required DLLs, load <code>/windows/ghostpdl.sln</code> into Visual Studio, and select the required architecture from the drop down - then right click on 'ghostpdl' in the solution explorer and choose "Build".</p> +<h3 id="building-on-macos-or-linux-openbsd">Building on MacOS or Linux / OpenBSD</h3> +<p>Firstly run the <code>autogen.sh</code> script from the command line to create the required configuration files followed by <code>make so</code> to build the shared libraries. The scripts also depend on having both <code>autoconf</code> and <code>automake</code> installed on your system. <sup>[1]</sup></p> +<h4 id="autoconf-automake">autoconf & automake</h4> +<p>If this software is not already on your system (usually this can be found in the following location: <code>usr/local/bin</code>, but it could be located elsewhere depending on your setup) then it can be installed from your OS's package system.</p> +<p>Alternatively, it can be installed from <a href="https://www.gnu.org/">GNU</a> here:</p> +<p><a href="https://www.gnu.org/software/autoconf/">https://www.gnu.org/software/autoconf/</a></p> +<p><a href="https://www.gnu.org/software/automake/">https://www.gnu.org/software/automake/</a></p> +<p>Or, it can be installed via <a href="https://brew.sh/">Brew</a> by running:</p> +<pre><code>brew install autoconf automake</code></pre><p>Once built, these libraries can be found in your <code>ghostpdl/sobin/</code> or <code>ghostpdl/sodebugbin</code> location depending on your build command.</p> +<blockquote> +<p><strong>NOTE</strong><br> +For full detailed instructions on how to build your Ghostscript library see <a href="https://ghostscript.com/doc/current/Make.htm">here</a>.</p> +</blockquote> +</article> + + </div> + + <div class="right"> + + <div class="link"><a href="#about-our-apis">About our APIs</a></div> + <div class="link"><a href="#the-c-api">The C API</a></div> + <div class="link"><a href="#licensing">Licensing</a></div> + <div class="sub-link"><a href="#open-source-license">Open Source license</a></div> + <div class="sub-link"><a href="#commercial-license">Commercial license</a></div> + <div class="link"><a href="#building-ghostscript">Building Ghostscript</a></div> + <div class="sub-link"><a href="#building-on-windows">Building on Windows</a></div> + <div class="sub-link"><a href="#building-on-macos-or-linux-openbsd">Building on MacOS or Linux / OpenBSD</a></div> + </div> + + + </div> + + <footer></footer> + + </body> + + +</html> diff --git a/doc/language-bindings/java-gsjavajar.html b/doc/language-bindings/java-gsjavajar.html new file mode 100644 index 00000000..e11337fc --- /dev/null +++ b/doc/language-bindings/java-gsjavajar.html @@ -0,0 +1,783 @@ +<html lang="en"> + <head> + <title>Ghostscript language bindings</title> + <meta http-equiv="content-type" content="text/html; charset=utf-8"> + <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width"> + <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:200,200i,300,300i,400,400i,600,600i,700,700i,900,900i" rel="stylesheet"> + <link rel="shortcut icon" type="image/png" href="../images/favicon.png"> + <link href="css/default.css" rel="stylesheet" type="text/css" /> + <script type="text/javascript" src="js/default.js"></script> + </head> + + <body> + + <header><h1></h1><div class="menu-icon" onclick="javascript:showMenu();"></div></header> + + <div id="burger-menu"> + <div class="navigation"> + <div class="title first">Introduction</div> + <div class="link"><a href="index.html">About our APIs</a></div> + <div class="link"><a href="demo-code.html">Demo code</a></div> + + <div class="title">C#</div> + <div class="link"><a href="c-sharp-intro.html">Overview</a></div> + <div class="link"><a href="c-sharp-ghost-api.html">GhostAPI</a></div> + <div class="link"><a href="c-sharp-ghost-net.html">GhostNET</a></div> + <div class="link"><a href="c-sharp-ghost-mono.html">GhostMono</a></div> + + <div class="title">Java</div> + <div class="link"><a href="java-intro.html">Overview</a></div> + <div class="link selected"><a href="java-gsjavajar.html">gsjava.jar</a></div> + + <div class="title">Python</div> + <div class="link"><a href="python-intro.html">Overview</a></div> + <div class="link"><a href="python-gsapi.html">gsapi.py</a></div> + </div> + </div> + <div class="main"> + + <div class="left"> + <div class="title first">Introduction</div> + <div class="link"><a href="index.html">About our APIs</a></div> + <div class="link"><a href="demo-code.html">Demo code</a></div> + + <div class="title">C#</div> + <div class="link"><a href="c-sharp-intro.html">Overview</a></div> + <div class="link"><a href="c-sharp-ghost-api.html">GhostAPI</a></div> + <div class="link"><a href="c-sharp-ghost-net.html">GhostNET</a></div> + <div class="link"><a href="c-sharp-ghost-mono.html">GhostMono</a></div> + + <div class="title">Java</div> + <div class="link"><a href="java-intro.html">Overview</a></div> + <div class="link selected"><a href="java-gsjavajar.html">gsjava.jar</a></div> + + <div class="title">Python</div> + <div class="link"><a href="python-intro.html">Overview</a></div> + <div class="link"><a href="python-gsapi.html">gsapi.py</a></div> + </div> + + <div class="middle"> + +<!-- note: don't tab indent <article> as it has <pre> code which will have its layout adversly affected --> +<article class="markdown-body entry-content"><h1 id="gsjava-jar">gsjava.jar</h1> +<div class="banner"> +<div class="java-text"></div> +<div class="vendor-logo java-logo"></div> +</div> + + +<h2 id="about">About</h2> +<p><code>gsjava.jar</code> is the Java library which contains classes and interfaces which enable API calls required to use Ghostscript.</p> +<p>Assuming that the JAR for your project has been <a href="java-intro.html#building-the-jar">built</a> and <a href="java-intro.html#linking-the-jar">properly linked</a> with your own project then the Ghostscript API should be available by importing the required classes within your project's <code>.java</code> files.</p> +<h3 id="gsapi-gsinstance">GSAPI & GSInstance</h3> +<ul> +<li><a href="#gsapi">GSAPI</a> is the main Ghostscript API class which bridges into the Ghostscript C library.</li> +<li><a href="#gsinstance">GSInstance</a> is a wrapper class for <a href="#gsapi">GSAPI</a> which encapsulates an instance of Ghostscript and allows for simpler API calls.</li> +</ul> +<div class="tag sampleCode java"></div> + + +<pre><code class="language-clike">// to use GSAPI +import static com.artifex.gsjava.GSAPI.*; + +// to use GSInstance +import com.artifex.gsjava.GSInstance;</code></pre> +<h2 id="gsapi">GSAPI</h2> +<h3 id="gsapi_revision">gsapi_revision</h3> +<p>This method returns the revision numbers and strings of the Ghostscript interpreter library; you should call it before any other interpreter library functions to make sure that the correct version of the Ghostscript interpreter has been loaded.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static native int gsapi_revision(GSAPI.Revision revision, + int len);</code></pre> +<blockquote> +<p><strong>NOTE</strong><br>The method should write to a reference variable which conforms to the class <a href="#gsapi-revision">GSAPI.Revision</a>.</p> +</blockquote> +<h4 id="gsapi-revision">GSAPI.Revision</h4> +<p>This class is used to store information about Ghostscript and provides handy getters for the product and the copyright information.</p> +<div class="tag classDefinition java"></div> + +<pre><code class="language-clike">public static class Revision { + public volatile byte[] product; + public volatile byte[] copyright; + public volatile long revision; + public volatile long revisionDate; + + public Revision() { + this.product = null; + this.copyright = null; + this.revision = 0L; + this.revisionDate = 0L; + } + + /** + * Returns the product information as a String. + * + * @return The product information. + */ + public String getProduct() { + return new String(product); + } + + /** + * Returns the copyright information as a String. + * + * @return The copyright information. + */ + public String getCopyright() { + return new String(copyright); + } +}</code></pre> +<h3 id="gsapi_new_instance">gsapi_new_instance</h3> +<p>Creates a new instance of Ghostscript. This instance is passed to most other <a href="#gsapi">GSAPI</a> methods. Unless Ghostscript has been compiled with the <code>GS_THREADSAFE</code> define, only one instance at a time is supported.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static native int gsapi_new_instance(Reference<Long> instance, + long callerHandle);</code></pre> +<blockquote> +<p><strong>NOTE</strong><br>The method returns a reference which represents your instance of Ghostscript.</p> +</blockquote> +<h3 id="gsapi_delete_instance">gsapi_delete_instance</h3> +<p>Destroy an instance of Ghostscript. Before you call this, Ghostscript must have finished. If Ghostscript has been initialised, you should call <a href="#gsapi_exit">gsapi_exit</a> beforehand.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static native void gsapi_delete_instance(long instance);</code></pre> +<h3 id="gsapi_set_stdio_with_handle">gsapi_set_stdio_with_handle</h3> +<p>Set the callback functions for <code>stdio</code>, together with the handle to use in the callback functions. The <code>stdin</code> callback function should return the number of characters read, 0 for EOF, or -1 for error. The <code>stdout</code> and <code>stderr</code> callback functions should return the number of characters written.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static native int gsapi_set_stdio_with_handle(long instance, + IStdInFunction stdin, + IStdOutFunction stdout, + IStdErrFunction stderr, + long callerHandle);</code></pre> +<h3 id="gsapi_set_stdio">gsapi_set_stdio</h3> +<p>Set the callback functions for <code>stdio</code>. The handle used in the callbacks will be taken from the value passed to <a href="#gsapi_new_instance">gsapi_new_instance</a>. Otherwise the behaviour of this function matches <a href="#gsapi_set_stdio_with_handle">gsapi_set_stdio_with_handle</a>.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static native int gsapi_set_stdio(long instance, + IStdInFunction stdin, + IStdOutFunction stdout, + IStdErrFunction stderr);</code></pre> +<h3 id="gsapi_set_poll_with_handle">gsapi_set_poll_with_handle</h3> +<p>Set the callback function for polling, together with the handle to pass to the callback function. This function will only be called if the Ghostscript interpreter was compiled with <code>CHECK_INTERRUPTS</code> as described in <code>gpcheck.h</code>.</p> +<p>The polling function should return zero if all is well, and return negative if it wants ghostscript to abort. This is often used for checking for a user cancel. This can also be used for handling window events or cooperative multitasking.</p> +<p>The polling function is called very frequently during interpretation and rendering so it must be fast. If the function is slow, then using a counter to <code>return 0</code> immediately some number of times can be used to reduce the performance impact.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static native int gsapi_set_poll_with_handle(long instance, + IPollFunction pollfun, + long callerHandle);</code></pre> +<h3 id="gsapi_set_poll">gsapi_set_poll</h3> +<p>Set the callback function for polling. The handle passed to the callback function will be taken from the handle passed to <a href="#gsapi_new_instance">gsapi_new_instance</a>. Otherwise the behaviour of this function matches <a href="#gsapi_set_poll_with_handle">gsapi_set_poll_with_handle</a>.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static native int gsapi_set_poll(long instance, + IPollFunction pollfun);</code></pre> +<h3 id="gsapi_set_display_callback">gsapi_set_display_callback</h3> +<p>This call is deprecated; please use <a href="#gsapi_register_callout">gsapi_register_callout</a> to register a <a href="#callback-callout-interfaces">callout handler</a> for the display device in preference.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static native int gsapi_set_display_callback(long instance, + DisplayCallback displayCallback);</code></pre> +<h3 id="gsapi_register_callout">gsapi_register_callout</h3> +<p>This call registers a <a href="#callback-callout-interfaces">callout handler</a>.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static native int gsapi_register_callout(long instance, + ICalloutFunction callout, + long calloutHandle);</code></pre> +<h3 id="gsapi_deregister_callout">gsapi_deregister_callout</h3> +<p>This call deregisters a <a href="#callback-callout-interfaces">callout handler</a> previously registered with <a href="#gsapi_register_callout">gsapi_register_callout</a>. All three arguments must match exactly for the <a href="#callback-callout-interfaces">callout handler</a> to be deregistered.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static native void gsapi_deregister_callout(long instance, + ICalloutFunction callout, + long calloutHandle);</code></pre> +<h3 id="gsapi_set_arg_encoding">gsapi_set_arg_encoding</h3> +<p>Set the encoding used for the interpretation of all subsequent arguments supplied via the <code>GSAPI</code> interface on this instance. By default we expect args to be in encoding <code>0</code> (the 'local' encoding for this OS). On Windows this means "the currently selected codepage". This means that omitting to call this function will leave Ghostscript running exactly as it always has. Please note that use of the 'local' encoding is now deprecated and should be avoided in new code. This must be called after <a href="#gsapi_new_instance">gsapi_new_instance</a> and before <a href="#gsapi_init_with_args">gsapi_init_with_args</a>.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static native int gsapi_set_arg_encoding(long instance, + int encoding);</code></pre> +<h3 id="gsapi_set_default_device_list">gsapi_set_default_device_list</h3> +<p>Set the string containing the list of default device names, for example "display x11alpha x11 bbox". Allows the calling application to influence which device(s) Ghostscript will try, in order, in its selection of the default device. This must be called after <a href="#gsapi_new_instance">gsapi_new_instance</a> and before <a href="#gsapi_init_with_args">gsapi_init_with_args</a>.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static native int gsapi_set_default_device_list(long instance, + byte[] list, + int listlen);</code></pre> +<h3 id="gsapi_get_default_device_list">gsapi_get_default_device_list</h3> +<p>Returns a pointer to the current default device string. This must be called after <a href="#gsapi_new_instance">gsapi_new_instance</a> and before <a href="#gsapi_init_with_args">gsapi_init_with_args</a>.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static native int gsapi_get_default_device_list(long instance, + Reference<byte[]> list, + Reference<Integer> listlen);</code></pre> +<h3 id="gsapi_init_with_args">gsapi_init_with_args</h3> +<p>To initialise the interpreter, pass your <code>instance</code> of Ghostscript, your argument count: <code>argc</code>, and your argument variables: <code>argv</code>.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static native int gsapi_init_with_args(long instance, + int argc, + byte[][] argv);</code></pre> +<blockquote> +<p><strong>NOTE</strong><br>There are also simpler utility methods which eliminates the need to send through your argument count and allows for simpler <code>String</code> passing for your argument array.</p> +</blockquote> +<p>Utility methods:</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static int gsapi_init_with_args(long instance, + String[] argv);</code></pre> +<pre><code class="language-clike">public static int gsapi_init_with_args(long instance, + List<String> argv);</code></pre> +<h3 id="gsapi_run_-">gsapi_run_*</h3> +<p>If these functions return <code><= -100</code>, either quit or a fatal error has occured. You must call <a href="#gsapi_exit">gsapi_exit</a> next. The only exception is <a href="#gsapi_run_string_continue">gsapi_run_string_continue</a> which will return <code>gs_error_NeedInput</code> if all is well.</p> +<p>There is a 64 KB length limit on any buffer submitted to a <code>gsapi_run_*</code> function for processing. If you have more than 65535 bytes of input then you must split it into smaller pieces and submit each in a separate <a href="#gsapi_run_string_continue">gsapi_run_string_continue</a> call.</p> +<h3 id="gsapi_run_string_begin">gsapi_run_string_begin</h3> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static native int gsapi_run_string_begin(long instance, + int userErrors, + Reference<Integer> pExitCode);</code></pre> +<h3 id="gsapi_run_string_continue">gsapi_run_string_continue</h3> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static native int gsapi_run_string_continue(long instance, + byte[] str, + int length, + int userErrors, + Reference<Integer> pExitCode);</code></pre> +<blockquote> +<p><strong>NOTE</strong><br>There is a simpler utility method which allows for simpler <code>String</code> passing for the <code>str</code> argument.</p> +</blockquote> +<p>Utility method:</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static int gsapi_run_string_continue(long instance, + String str, + int length, + int userErrors, + Reference<Integer> pExitCode);</code></pre> +<h3 id="gsapi_run_string_with_length">gsapi_run_string_with_length</h3> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static native int gsapi_run_string_with_length(long instance, + byte[] str, + int length, + int userErrors, + Reference<Integer> pExitCode);</code></pre> +<blockquote> +<p><strong>NOTE</strong><br>There is a simpler utility method which allows for simpler <code>String</code> passing for the <code>str</code> argument.</p> +</blockquote> +<p>Utility method:</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static int gsapi_run_string_with_length(long instance, + String str, + int length, + int userErrors, + Reference<Integer> pExitCode);</code></pre> +<h3 id="gsapi_run_string">gsapi_run_string</h3> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static native int gsapi_run_string(long instance, + byte[] str, + int userErrors, + Reference<Integer> pExitCode);</code></pre> +<blockquote> +<p><strong>NOTE</strong><br>There is a simpler utility method which allows for simpler <code>String</code> passing for the <code>str</code> argument.</p> +</blockquote> +<p>Utility method:</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static int gsapi_run_string(long instance, + String str, + int userErrors, + Reference<Integer> pExitCode);</code></pre> +<h3 id="gsapi_run_string_end">gsapi_run_string_end</h3> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static native int gsapi_run_string_end(long instance, + int userErrors, + Reference<Integer> pExitCode);</code></pre> +<h3 id="gsapi_run_file">gsapi_run_file</h3> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static native int gsapi_run_file(long instance, + byte[] fileName, + int userErrors, + Reference<Integer> pExitCode);</code></pre> +<blockquote> +<p><strong>NOTE</strong><br>There is a simpler utility method which allows for simpler <code>String</code> passing for the <code>fileName</code> argument.</p> +</blockquote> +<p>Utility method:</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static int gsapi_run_file(long instance, + String fileName, + int userErrors, + Reference<Integer> pExitCode);</code></pre> +<h3 id="gsapi_exit">gsapi_exit</h3> +<p>Exit the interpreter. This must be called on shutdown if <a href="#gsapi_init_with_args">gsapi_init_with_args</a> has been called, and just before <a href="#gsapi_delete_instance">gsapi_delete_instance</a>.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static native int gsapi_exit(long instance);</code></pre> +<h3 id="gsapi_set_param">gsapi_set_param</h3> +<p>Sets a parameter. Broadly, this is equivalent to setting a parameter using -d, -s or -p on the command line. This call cannot be made during a <a href="#gsapi_run_string">gsapi_run_string</a> operation.</p> +<p>Parameters in this context are not the same as 'arguments' as processed by <a href="#gsapi_init_with_args">gsapi_init_with_args</a>, but often the same thing can be achieved. For example, with <a href="#gsapi_init_with_args">gsapi_init_with_args</a>, we can pass "-r200" to change the resolution. Broadly the same thing can be achieved by using <a href="#gsapi_set_param">gsapi_set_param</a> to set a parsed value of "<</HWResolution [ 200.0 200.0 ]>>".</p> +<p>Internally, when we set a parameter, we perform an <code>initgraphics</code> operation. This means that using <a href="#gsapi_set_param">gsapi_set_param</a> other than at the start of a page is likely to give unexpected results.</p> +<p>Attempting to set a parameter that the device does not recognise will be silently ignored, and that parameter will not be found in subsequent <a href="#gsapi_get_param">gsapi_get_param</a> calls.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static native int gsapi_set_param(long instance, + byte[] param, + Object value, + int paramType);</code></pre> +<blockquote> +<p><strong>NOTE</strong><br>The <code>type</code> argument, as a <a href="#gs_set_param_type">gs_set_param_type</a>, dictates the kind of object that the <code>value</code> argument points to.</p> +</blockquote> +<blockquote> +<p><strong>NOTE</strong><br>For more on the C implementation of parameters see: <a href="https://www.ghostscript.com/doc/current/Use.htm#Parameters">Ghostscript parameters in C</a>.</p> +</blockquote> +<blockquote> +<p><strong>NOTE</strong><br>There are also simpler utility methods which allows for simpler <code>String</code> passing for your arguments.</p> +</blockquote> +<p>Utility methods:</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static int gsapi_set_param(long instance, + String param, + String value, + int paramType);</code></pre> +<pre><code class="language-clike">public static int gsapi_set_param(long instance, + String param, + Object value, + int paramType);</code></pre> +<h3 id="gsapi_get_param">gsapi_get_param</h3> +<p>Retrieve the current value of a parameter.</p> +<p>If an error occurs, the return value is negative. Otherwise the return value is the number of bytes required for storage of the value. Call once with value <code>NULL</code> to get the number of bytes required, then call again with value pointing to at least the required number of bytes where the value will be copied out. Note that the caller is required to know the type of value in order to get it. For all types other than <a href="#gs_set_param_type">gs_spt_string</a>, <a href="#gs_set_param_type">gs_spt_name</a>, and <a href="#gs_set_param_type">gs_spt_parsed</a> knowing the type means you already know the size required.</p> +<p>This call retrieves parameters/values that have made it to the device. Thus, any values set using <a href="#gs_set_param_type">gs_spt_more_to_come</a> without a following call omitting that flag will not be retrieved. Similarly, attempting to get a parameter before <a href="#gsapi_init_with_args">gsapi_init_with_args</a> has been called will not list any, even if <a href="#gsapi_set_param">gsapi_set_param</a> has been used.</p> +<p>Attempting to read a parameter that is not set will return <code>gs_error_undefined</code> (-21). Note that calling <a href="#gsapi_set_param">gsapi_set_param</a> followed by <a href="#gsapi_get_param">gsapi_get_param</a> may not find the value, if the device did not recognise the key as being one of its configuration keys.</p> +<p>For the C documentation please refer to <a href="https://www.ghostscript.com/doc/current/API.htm#get_param">Ghostscript get_param</a>.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static native int gsapi_get_param(long instance, + byte[] param, + long value, + int paramType);</code></pre> +<blockquote> +<p><strong>NOTE</strong><br>There is a simpler utility method which allows for simpler <code>String</code> passing for the <code>param</code> argument.</p> +</blockquote> +<p>Utility method:</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static int gsapi_get_param(long instance, + String param, + long value, + int paramType);</code></pre> +<h3 id="gsapi_enumerate_params">gsapi_enumerate_params</h3> +<p>Enumerate the current parameters. Call repeatedly to list out the current parameters.</p> +<p>The first call should have <code>iter</code> = NULL. Subsequent calls should pass the same pointer in so the iterator can be updated. Negative return codes indicate error, 0 success, and 1 indicates that there are no more keys to read. On success, key will be updated to point to a null terminated string with the key name that is guaranteed to be valid until the next call to <a href="#gsapi_enumerate_params">gsapi_enumerate_params</a>. If <code>type</code> is non NULL then the pointer <code>type</code> will be updated to have the <code>type</code> of the parameter.</p> +<blockquote> +<p><strong>NOTE</strong><br>Only one enumeration can happen at a time. Starting a second enumeration will reset the first.</p> +</blockquote> +<p>The enumeration only returns parameters/values that have made it to the device. Thus, any values set using the <a href="#gs_set_param_type">gs_spt_more_to_come</a> without a following call omitting that flag will not be retrieved. Similarly, attempting to enumerate parameters before <a href="#gsapi_init_with_args">gsapi_init_with_args</a> has been called will not list any, even if <a href="#gsapi_set_param">gsapi_set_param</a> has been used.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static native int gsapi_enumerate_params(long instance, + Reference<Long> iter, + Reference<byte[]> key, + Reference<Integer> paramType);</code></pre> +<h3 id="gsapi_add_control_path">gsapi_add_control_path</h3> +<p>Add a (case sensitive) path to one of the lists of <a href="https://ghostscript.com/doc/current/Use.htm#Safer">permitted paths</a> for file access.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static native int gsapi_add_control_path(long instance, + int type, + byte[] path);</code></pre> +<blockquote> +<p><strong>NOTE</strong><br>There is a simpler utility method which allows for simpler <code>String</code> passing for the <code>path</code> argument.</p> +</blockquote> +<p>Utility method:</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static int gsapi_add_control_path(long instance, + int type, + String path);</code></pre> +<h3 id="gsapi_remove_control_path">gsapi_remove_control_path</h3> +<p>Remove a (case sensitive) path from one of the lists of <a href="https://ghostscript.com/doc/current/Use.htm#Safer">permitted paths</a> for file access.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static native int gsapi_remove_control_path(long instance, + int type, + byte[] path);</code></pre> +<blockquote> +<p><strong>NOTE</strong><br>There is a simpler utility method which allows for simpler <code>String</code> passing for the <code>path</code> argument.</p> +</blockquote> +<p>Utility method:</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static int gsapi_remove_control_path(long instance, + int type, + String path);</code></pre> +<h3 id="gsapi_purge_control_paths">gsapi_purge_control_paths</h3> +<p>Clear all the paths from one of the lists of <a href="https://ghostscript.com/doc/current/Use.htm#Safer">permitted paths</a> for file access.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static native void gsapi_purge_control_paths(long instance, + int type);</code></pre> +<h3 id="gsapi_activate_path_control">gsapi_activate_path_control</h3> +<p>Enable/Disable path control (i.e. whether paths are checked against <a href="https://ghostscript.com/doc/current/Use.htm#Safer">permitted paths</a> before access is granted).</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public static native void gsapi_activate_path_control(long instance, + boolean enable);</code></pre> +<h3 id="gsapi_is_path_control_active">gsapi_is_path_control_active</h3> +<p>Query whether path control is activated or not.</p> +<div class="tag methodDefinition java"></div> + + +<pre><code class="language-clike">public static native boolean gsapi_is_path_control_active(long instance);</code></pre> +<h2 id="callback-callout-interfaces">Callback & Callout interfaces</h2> +<p><code>gsjava.jar</code> also defines some functional interfaces for callbacks & callouts with <code>package com.artifex.gsjava.callback</code> which are defined as follows.</p> +<h3 id="istdinfunction">IStdInFunction</h3> +<div class="tag functionalInterface java"></div> + +<pre><code class="language-clike">public interface IStdInFunction { + /** + * @param callerHandle The caller handle. + * @param buf A string represented by a byte array. + * @param len The number of bytes to read. + * @return The number of bytes read, must be <code>len</code>/ + */ + public int onStdIn(long callerHandle, + byte[] buf, + int len); +}</code></pre> +<h3 id="istdoutfunction">IStdOutFunction</h3> +<div class="tag functionalInterface java"></div> + +<pre><code class="language-clike">public interface IStdOutFunction { + /** + * Called when something should be written to the standard + * output stream. + * + * @param callerHandle The caller handle. + * @param str The string represented by a byte array to write. + * @param len The number of bytes to write. + * @return The number of bytes written, must be <code>len</code>. + */ + public int onStdOut(long callerHandle, + byte[] str, + int len); +}</code></pre> +<h3 id="istderrfunction">IStdErrFunction</h3> +<div class="tag functionalInterface java"></div> + +<pre><code class="language-clike">public interface IStdErrFunction { + /** + * Called when something should be written to the standard error stream. + * + * @param callerHandle The caller handle. + * @param str The string represented by a byte array to write. + * @param len The length of bytes to be written. + * @return The amount of bytes written, must be <code>len</code>. + */ + public int onStdErr(long callerHandle, + byte[] str, + int len); +}</code></pre> +<h3 id="ipollfunction">IPollFunction</h3> +<div class="tag functionalInterface java"></div> + +<pre><code class="language-clike">public interface IPollFunction { + public int onPoll(long callerHandle); +}</code></pre> +<h3 id="icalloutfunction">ICalloutFunction</h3> +<div class="tag functionalInterface java"></div> + +<pre><code class="language-clike">public interface ICalloutFunction { + public int onCallout(long instance, + long calloutHandle, + byte[] deviceName, + int id, + int size, + long data); +}</code></pre> +<h2 id="gsinstance">GSInstance</h2> +<p>This is a utility class which makes Ghostscript calls easier by storing a Ghostscript instance and, optionally, a caller handle. Essentially the class acts as a handy wrapper for the standard <a href="#gsapi">GSAPI</a> methods.</p> +<h3 id="constructors">Constructors</h3> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public GSInstance() throws IllegalStateException;</code></pre> +<pre><code class="language-clike">public GSInstance(long callerHandle) throws IllegalStateException;</code></pre> +<h3 id="delete_instance">delete_instance</h3> +<p>Wraps <a href="#gsapi_delete_instance">gsapi_delete_instance</a>.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public void delete_instance();</code></pre> +<h3 id="set_stdio">set_stdio</h3> +<p>Wraps <a href="#gsapi_set_stdio">gsapi_set_stdio</a>.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public int set_stdio(IStdInFunction stdin, + IStdOutFunction stdout, + IStdErrFunction stderr);</code></pre> +<h3 id="set_poll">set_poll</h3> +<p>Wraps <a href="#gsapi_set_poll">gsapi_set_poll</a>.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public int set_poll(IPollFunction pollfun);</code></pre> +<h3 id="set_display_callback">set_display_callback</h3> +<p>Wraps <a href="#gsapi_set_display_callback">gsapi_set_display_callback</a>.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public int set_display_callback(DisplayCallback displaycallback);</code></pre> +<h3 id="register_callout">register_callout</h3> +<p>Wraps <a href="#gsapi_register_callout">gsapi_register_callout</a>.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public int register_callout(ICalloutFunction callout);</code></pre> +<h3 id="deregister_callout">deregister_callout</h3> +<p>Wraps <a href="#gsapi_deregister_callout">gsapi_deregister_callout</a>.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public void deregister_callout(ICalloutFunction callout);</code></pre> +<h3 id="set_arg_encoding">set_arg_encoding</h3> +<p>Wraps <a href="#gsapi_set_arg_encoding">gsapi_set_arg_encoding</a>.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public int set_arg_encoding(int encoding);</code></pre> +<h3 id="set_default_device_list">set_default_device_list</h3> +<p>Wraps <a href="#gsapi_set_default_device_list">gsapi_set_default_device_list</a>.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public int set_default_device_list(byte[] list, + int listlen);</code></pre> +<h3 id="get_default_device_list">get_default_device_list</h3> +<p>Wraps <a href="#gsapi_get_default_device_list">gsapi_get_default_device_list</a>.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public int get_default_device_list(Reference<byte[]> list, + Reference<Integer> listlen);</code></pre> +<h3 id="init_with_args">init_with_args</h3> +<p>Wraps <a href="#gsapi_init_with_args">gsapi_init_with_args</a>.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public int init_with_args(int argc, + byte[][] argv);</code></pre> +<pre><code class="language-clike">public int init_with_args(String[] argv);</code></pre> +<pre><code class="language-clike">public int init_with_args(List<String> argv);</code></pre> +<h3 id="run_string_begin">run_string_begin</h3> +<p>Wraps <a href="#gsapi_run_string_begin">gsapi_run_string_begin</a>.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public int run_string_begin(int userErrors, + Reference<Integer> pExitCode);</code></pre> +<h3 id="run_string_continue">run_string_continue</h3> +<p>Wraps <a href="#gsapi_run_string_continue">gsapi_run_string_continue</a>.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public int run_string_continue(byte[] str, + int length, + int userErrors, + Reference<Integer> pExitCode);</code></pre> +<pre><code class="language-clike">public int run_string_continue(String str, + int length, + int userErrors, + Reference<Integer> pExitCode);</code></pre> +<h3 id="run_string">run_string</h3> +<p>Wraps <a href="#gsapi_run_string">gsapi_run_string</a>.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public int run_string(byte[] str, + int userErrors, + Reference<Integer> pExitCode);</code></pre> +<pre><code class="language-clike">public int run_string(String str, + int userErrors, + Reference<Integer> pExitCode);</code></pre> +<h3 id="run_file">run_file</h3> +<p>Wraps <a href="#gsapi_run_file">gsapi_run_file</a>.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public int run_file(byte[] fileName, + int userErrors, + Reference<Integer> pExitCode);</code></pre> +<pre><code class="language-clike">public int run_file(String filename, + int userErrors, + Reference<Integer> pExitCode);</code></pre> +<h3 id="exit">exit</h3> +<p>Wraps <a href="#gsapi_exit">gsapi_exit</a>.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public int exit();</code></pre> +<h3 id="set_param">set_param</h3> +<p>Wraps <a href="#gsapi_set_param">gsapi_set_param</a>.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public int set_param(byte[] param, + Object value, + int paramType);</code></pre> +<pre><code class="language-clike">public int set_param(String param, + String value, + int paramType);</code></pre> +<pre><code class="language-clike">public int set_param(String param, + Object value, + int paramType);</code></pre> +<h3 id="get_param">get_param</h3> +<p>Wraps <a href="#gsapi_get_param">gsapi_get_param</a>.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public int get_param(byte[] param, + long value, + int paramType);</code></pre> +<pre><code class="language-clike">public int get_param(String param, + long value, + int paramType);</code></pre> +<h3 id="enumerate_params">enumerate_params</h3> +<p>Wraps <a href="#gsapi_enumerate_params">gsapi_enumerate_params</a>.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public int enumerate_params(Reference<Long> iter, + Reference<byte[]> key, + Reference<Integer> paramType);</code></pre> +<h3 id="add_control_path">add_control_path</h3> +<p>Wraps <a href="#gsapi_add_control_path">gsapi_add_control_path</a>.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public int add_control_path(int type, + byte[] path);</code></pre> +<pre><code class="language-clike">public int add_control_path(int type, + String path);</code></pre> +<h3 id="remove_control_path">remove_control_path</h3> +<p>Wraps <a href="#gsapi_remove_control_path">gsapi_remove_control_path</a>.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public int remove_control_path(int type, + byte[] path);</code></pre> +<pre><code class="language-clike">public int remove_control_path(int type, + String path);</code></pre> +<h3 id="purge_control_paths">purge_control_paths</h3> +<p>Wraps <a href="#gsapi_purge_control_paths">gsapi_purge_control_paths</a>.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public void purge_control_paths(int type);</code></pre> +<h3 id="activate_path_control">activate_path_control</h3> +<p>Wraps <a href="#gsapi_activate_path_control">gsapi_activate_path_control</a>.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public void activate_path_control(boolean enable);</code></pre> +<h3 id="is_path_control_active">is_path_control_active</h3> +<p>Wraps <a href="#gsapi_is_path_control_active">gsapi_is_path_control_active</a>.</p> +<div class="tag methodDefinition java"></div> + +<pre><code class="language-clike">public boolean is_path_control_active();</code></pre> +<h2 id="utility-classes">Utility classes</h2> +<p>The com.artifex.gsjava.util package contains a set of classes and interfaces which are used throughout the API.</p> +<h3 id="com-artifex-gsjava-util-reference">com.artifex.gsjava.util.Reference</h3> +<p><code>Reference<T></code> is used in many of the Ghostscript calls, it stores a reference to a generic value of type <code>T</code>. This class exists to emulate pointers being passed to a native function. Its value can be fetched with <code>getValue()</code> and set with <code>setValue(T value)</code>.</p> +<div class="tag classDefinition java"></div> + +<pre><code class="language-clike">public class Reference<T> { + + private volatile T value; + + public Reference() { + this(null); + } + + public Reference(T value) { + this.value = value; + } + + public void setValue(T value) { + this.value = value; + } + + public T getValue() { + return value; + } + ... +}</code></pre> +</article> + + </div> <!-- /middle --> + + <div class="right"> + + <div class="link"><a href="#about">About</a></div> + <div class="sub-link"><a href="#gsapi-gsinstance">GSAPI & GSInstance</a></div> + <div class="link"><a href="#gsapi">GSAPI</a></div> + <div class="sub-link"><a href="#gsapi_revision">gsapi_revision</a></div> + <div class="sub-link"><a href="#gsapi_new_instance">gsapi_new_instance</a></div> + <div class="sub-link"><a href="#gsapi_delete_instance">gsapi_delete_instance</a></div> + <div class="sub-link"><a href="#gsapi_set_stdio_with_handle">gsapi_set_stdio_with_handle</a></div> + <div class="sub-link"><a href="#gsapi_set_stdio">gsapi_set_stdio</a></div> + <div class="sub-link"><a href="#gsapi_set_poll_with_handle">gsapi_set_poll_with_handle</a></div> + <div class="sub-link"><a href="#gsapi_set_poll">gsapi_set_poll</a></div> + <div class="sub-link"><a href="#gsapi_set_display_callback">gsapi_set_display_callback</a></div> + <div class="sub-link"><a href="#gsapi_register_callout">gsapi_register_callout</a></div> + <div class="sub-link"><a href="#gsapi_deregister_callout">gsapi_deregister_callout</a></div> + <div class="sub-link"><a href="#gsapi_set_arg_encoding">gsapi_set_arg_encoding</a></div> + <div class="sub-link"><a href="#gsapi_set_default_device_list">gsapi_set_default_device_list</a></div> + <div class="sub-link"><a href="#gsapi_get_default_device_list">gsapi_get_default_device_list</a></div> + <div class="sub-link"><a href="#gsapi_init_with_args">gsapi_init_with_args</a></div> + <div class="sub-link"><a href="#gsapi_run_-">gsapi_run_*</a></div> + <div class="sub-link"><a href="#gsapi_run_string_begin">gsapi_run_string_begin</a></div> + <div class="sub-link"><a href="#gsapi_run_string_continue">gsapi_run_string_continue</a></div> + <div class="sub-link"><a href="#gsapi_run_string_with_length">gsapi_run_string_with_length</a></div> + <div class="sub-link"><a href="#gsapi_run_string">gsapi_run_string</a></div> + <div class="sub-link"><a href="#gsapi_run_string_end">gsapi_run_string_end</a></div> + <div class="sub-link"><a href="#gsapi_run_file">gsapi_run_file</a></div> + <div class="sub-link"><a href="#gsapi_exit">gsapi_exit</a></div> + <div class="sub-link"><a href="#gsapi_set_param">gsapi_set_param</a></div> + <div class="sub-link"><a href="#gsapi_get_param">gsapi_get_param</a></div> + <div class="sub-link"><a href="#gsapi_enumerate_params">gsapi_enumerate_params</a></div> + <div class="sub-link"><a href="#gsapi_add_control_path">gsapi_add_control_path</a></div> + <div class="sub-link"><a href="#gsapi_remove_control_path">gsapi_remove_control_path</a></div> + <div class="sub-link"><a href="#gsapi_purge_control_paths">gsapi_purge_control_paths</a></div> + <div class="sub-link"><a href="#gsapi_activate_path_control">gsapi_activate_path_control</a></div> + <div class="sub-link"><a href="#gsapi_is_path_control_active">gsapi_is_path_control_active</a></div> + <div class="link"><a href="#callback-callout-interfaces">Callback & Callout interfaces</a></div> + <div class="sub-link"><a href="#istdinfunction">IStdInFunction</a></div> + <div class="sub-link"><a href="#istdoutfunction">IStdOutFunction</a></div> + <div class="sub-link"><a href="#istderrfunction">IStdErrFunction</a></div> + <div class="sub-link"><a href="#ipollfunction">IPollFunction</a></div> + <div class="sub-link"><a href="#icalloutfunction">ICalloutFunction</a></div> + <div class="link"><a href="#gsinstance">GSInstance</a></div> + <div class="sub-link"><a href="#constructors">Constructors</a></div> + <div class="sub-link"><a href="#delete_instance">delete_instance</a></div> + <div class="sub-link"><a href="#set_stdio">set_stdio</a></div> + <div class="sub-link"><a href="#set_poll">set_poll</a></div> + <div class="sub-link"><a href="#set_display_callback">set_display_callback</a></div> + <div class="sub-link"><a href="#register_callout">register_callout</a></div> + <div class="sub-link"><a href="#deregister_callout">deregister_callout</a></div> + <div class="sub-link"><a href="#set_arg_encoding">set_arg_encoding</a></div> + <div class="sub-link"><a href="#set_default_device_list">set_default_device_list</a></div> + <div class="sub-link"><a href="#get_default_device_list">get_default_device_list</a></div> + <div class="sub-link"><a href="#init_with_args">init_with_args</a></div> + <div class="sub-link"><a href="#run_string_begin">run_string_begin</a></div> + <div class="sub-link"><a href="#run_string_continue">run_string_continue</a></div> + <div class="sub-link"><a href="#run_string">run_string</a></div> + <div class="sub-link"><a href="#run_file">run_file</a></div> + <div class="sub-link"><a href="#exit">exit</a></div> + <div class="sub-link"><a href="#set_param">set_param</a></div> + <div class="sub-link"><a href="#get_param">get_param</a></div> + <div class="sub-link"><a href="#enumerate_params">enumerate_params</a></div> + <div class="sub-link"><a href="#add_control_path">add_control_path</a></div> + <div class="sub-link"><a href="#remove_control_path">remove_control_path</a></div> + <div class="sub-link"><a href="#purge_control_paths">purge_control_paths</a></div> + <div class="sub-link"><a href="#activate_path_control">activate_path_control</a></div> + <div class="sub-link"><a href="#is_path_control_active">is_path_control_active</a></div> + <div class="link"><a href="#utility-classes">Utility classes</a></div> + <div class="sub-link"><a href="#com-artifex-gsjava-util-reference">com.artifex.gsjava.util.Reference</a></div> + + </div> + + </div> + + <footer></footer> + + </body> + +</html> diff --git a/doc/language-bindings/java-intro.html b/doc/language-bindings/java-intro.html new file mode 100644 index 00000000..21098521 --- /dev/null +++ b/doc/language-bindings/java-intro.html @@ -0,0 +1,260 @@ +<html lang="en"> + <head> + <title>Ghostscript language bindings</title> + <meta http-equiv="content-type" content="text/html; charset=utf-8"> + <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width"> + <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:200,200i,300,300i,400,400i,600,600i,700,700i,900,900i" rel="stylesheet"> + <link rel="shortcut icon" type="image/png" href="../images/favicon.png"> + <link href="css/default.css" rel="stylesheet" type="text/css" /> + <script type="text/javascript" src="js/default.js"></script> + </head> + + <body> + + <header><h1></h1><div class="menu-icon" onclick="javascript:showMenu();"></div></header> + + <div id="burger-menu"> + <div class="navigation"> + <div class="title first">Introduction</div> + <div class="link"><a href="index.html">About our APIs</a></div> + <div class="link"><a href="demo-code.html">Demo code</a></div> + + <div class="title">C#</div> + <div class="link"><a href="c-sharp-intro.html">Overview</a></div> + <div class="link"><a href="c-sharp-ghost-api.html">GhostAPI</a></div> + <div class="link"><a href="c-sharp-ghost-net.html">GhostNET</a></div> + <div class="link"><a href="c-sharp-ghost-mono.html">GhostMono</a></div> + + <div class="title">Java</div> + <div class="link selected"><a href="java-intro.html">Overview</a></div> + <div class="link"><a href="java-gsjavajar.html">gsjava.jar</a></div> + + <div class="title">Python</div> + <div class="link"><a href="python-intro.html">Overview</a></div> + <div class="link"><a href="python-gsapi.html">gsapi.py</a></div> + </div> + </div> + <div class="main"> + + <div class="left"> + <div class="title first">Introduction</div> + <div class="link"><a href="index.html">About our APIs</a></div> + <div class="link"><a href="demo-code.html">Demo code</a></div> + + <div class="title">C#</div> + <div class="link"><a href="c-sharp-intro.html">Overview</a></div> + <div class="link"><a href="c-sharp-ghost-api.html">GhostAPI</a></div> + <div class="link"><a href="c-sharp-ghost-net.html">GhostNET</a></div> + <div class="link"><a href="c-sharp-ghost-mono.html">GhostMono</a></div> + + <div class="title">Java</div> + <div class="link selected"><a href="java-intro.html">Overview</a></div> + <div class="link"><a href="java-gsjavajar.html">gsjava.jar</a></div> + + <div class="title">Python</div> + <div class="link"><a href="python-intro.html">Overview</a></div> + <div class="link"><a href="python-gsapi.html">gsapi.py</a></div> + </div> + + <div class="middle"> + +<!-- note: don't tab indent <article> as it has <pre> code which will have its layout adversly affected --> +<article class="markdown-body entry-content"><h1 id="java-overview">Java overview</h1> +<div class="banner"> +<div class="java-text"></div> +<div class="vendor-logo java-logo"></div> +</div> + +<h2 id="about">About</h2> +<p>In the <a href="https://github.com/ArtifexSoftware/ghostpdl">GhostPDL repository</a> sample <code>Java</code> projects can be found in <code>/demos/java</code>.</p> +<p>Within this location the following folders are of relevance:</p> +<ul> +<li><a href="#jni-building-the-java-native-interface">jni</a> <code>jni</code></li> +<li><a href="#gsjava-building-the-jar">gsjava</a> <code>gsjava</code></li> +<li><a href="#gstest">gstest</a> <code>gstest</code></li> +<li><a href="#gsviewer">gsviewer</a> <code>gsviewer</code></li> +</ul> +<h2 id="platform-setup">Platform & setup</h2> +<h3 id="building-ghostscript">Building Ghostscript</h3> +<p>Ghostscript should be built as a shared library for your platform.</p> +<p>See <a href="index.html#building-ghostscript">Building Ghostscript</a>.</p> +<h3 id="jni-building-the-java-native-interface">jni: Building the Java Native Interface</h3> +<p>Before building the JNI ensure that Ghostscript has already been built for your platform and that you have JDK installed.</p> +<p>The JNI is for use in the Java interface, +this object must be placed somewhere on your Java PATH. On Windows, the DLL +can be placed in the working directory, next to <code>gsjava.jar</code>.</p> +<table> +<thead> +<tr> +<th>Platform</th> +<th>JNI file</th> +</tr> +</thead> +<tbody><tr> +<td>Windows</td> +<td><code>gs_jni.dll</code></td> +</tr> +<tr> +<td>MacOS</td> +<td><code>gs_jni.dylib</code></td> +</tr> +<tr> +<td>Linux / OpenBSD</td> +<td><code>gs_jni.so</code></td> +</tr> +</tbody></table> +<h4 id="preparing-your-include-folder">Preparing your include folder</h4> +<p>The build scripts require the header <code>jni.h</code>, which defines +all JNI functions, and <code>jni_md.h</code>, which defines all system-specific +integer types. The build scripts expect an include folder relative to their location which contain these header files from your system.</p> +<p>These headers are typically found in the following directories:</p> +<table> +<thead> +<tr> +<th>Platform</th> +<th>jni.h</th> +<th>jni_md.h</th> +</tr> +</thead> +<tbody><tr> +<td>Windows</td> +<td><code>C:\Program Files\Java\<JDK Install>\include\jni.h</code></td> +<td><code>C:\Program Files\Java\<JDK Install>\include\win32\jni_md.h</code></td> +</tr> +<tr> +<td>MacOS</td> +<td><code>/Library/Java/JavaVirtualMachines/<JDK Install>/Contents/Home/include/jni.h</code></td> +<td><code>/Library/Java/JavaVirtualMachines/<JDK Install>/Contents/Home/include/darwin/jni_md.h</code></td> +</tr> +<tr> +<td>Linux</td> +<td><code>/lib/jvm/<JDK Install>/include/jni.h</code></td> +<td><code>/lib/jvm/<JDK Install>/include/linux/jni_md.h</code></td> +</tr> +</tbody></table> +<p>Once your <code>include</code> folder has been located folder you can copy it and place it in your <code>ghostpdl/demos/java/jni/gs_jni</code> folder.</p> +<p>Your build scripts should now be ready to run as they will be able to find the required JNI header files in their own relative include folder.</p> +<h4 id="building-on-windows">Building on Windows</h4> +<p>The <code>jni</code> folder contains a Visual Studio Solution file <code>/jni/gs_jni/gs_jni.sln</code> which you should use to build the required JNI <code>gs_jni.dll</code> library file.</p> +<p>With the project open in Visual Studio, select the required architecture from the drop down - then right click on 'gs_jni' in the solution explorer and choose "Build".</p> +<h4 id="building-on-macos">Building on MacOS</h4> +<p>On your command line, navigate to <code>ghostpdl/demos/java/jni/gs_jni</code> and ensure that the build script is executable and then run it, with:</p> +<pre><code>chmod +x build_darwin.sh +./build_darwin.sh</code></pre><h4 id="building-on-linux">Building on Linux</h4> +<p>On your command line, navigate to <code>ghostpdl/demos/java/jni/gs_jni</code> and ensure that the build script is executable and then run it, with:</p> +<pre><code>chmod +x build_linux.sh +./build_linux.sh</code></pre><h3 id="gsjava-building-the-jar">gsjava: Building the JAR</h3> +<h4 id="building-with-the-command-line">Building with the command line</h4> +<p>Navigate to <code>ghostpdl/demos/java/gsjava</code> and use the following:</p> +<table> +<thead> +<tr> +<th>Platform</th> +<th>Run file</th> +</tr> +</thead> +<tbody><tr> +<td>Windows</td> +<td><code>build_win32.bat</code></td> +</tr> +<tr> +<td>MacOS</td> +<td><code>build_darwin.sh</code></td> +</tr> +<tr> +<td>Linux</td> +<td><code>build_linux.sh</code></td> +</tr> +</tbody></table> +<blockquote> +<p><strong>NOTE</strong><br> +<code>gsjava</code> has a dependancy on <a href="#jni-building-the-java-native-interface">jni</a>, please ensure that <code>gs_jni</code> is able to be built beforehand.</p> +</blockquote> +<h4 id="building-with-eclipse">Building with Eclipse</h4> +<p>Alternatively you can use <a href="https://www.eclipse.org/eclipseide/">Eclipse</a> to build the JAR file.</p> +<p>Using <a href="https://www.eclipse.org/eclipseide/">Eclipse</a> import the source folder <code>gsjava</code> as a project and select <code>Export > Java > JAR File</code> as shown in the screenshot example below:</p> +<p><img src="images/export-jar.png" alt="Eclipse export JAR"></p> +<h4 id="linking-the-jar">Linking the JAR</h4> +<p>The built JAR should be properly linked within your project Java Build Path as follows:</p> +<p><img src="images/linking-jar.png" alt="Linking the JAR"></p> +<h2 id="demo-projects">Demo projects</h2> +<h3 id="gstest">gstest</h3> +<p>This project can be opened in <a href="https://www.eclipse.org/eclipseide/">Eclipse</a> and used to test the Ghostscript API. The sample here simply sets up an instance of Ghostscript and then sets and gets some parameters accordingly.</p> +<h3 id="gsviewer">gsviewer</h3> +<p>This project can be used to test the Ghostscript API alongside a UI which handles opening PostScript and PDF files. The sample application here allows for file browsing and Ghostscript file viewing.</p> +<p>Below is a screenshot of the sample application with a PDF open:</p> +<p><img src="images/gsviewer.png" alt="gsviewer UI"></p> +<p>To run the project navigate to the <code>demos/java/gsviewer</code> location and ensure that the required libraries are in the directory:</p> +<table> +<thead> +<tr> +<th>Platform</th> +<th>Ghostscript library file</th> +<th>JNI library file</th> +</tr> +</thead> +<tbody><tr> +<td>Windows</td> +<td><code>gpdldll64.dll</code></td> +<td><code>gs_jni.dll</code></td> +</tr> +<tr> +<td>MacOS</td> +<td><code>libgpdl.dylib</code></td> +<td><code>gs_jni.dylib</code></td> +</tr> +<tr> +<td>Linux / OpenBSD</td> +<td><code>libgpdl.so</code> (this may have been built as <code>libgs.so</code>, so it should be copied into this directory and renamed to <code>libgpdl.so</code>)</td> +<td><code>gs_jni.so</code></td> +</tr> +</tbody></table> +<h4 id="building-on-windows">Building on Windows</h4> +<p>Run the <code>build_win32.bat</code> script.</p> +<h4 id="running-on-windows">Running on Windows</h4> +<p>To run, open <code>gsviewer.jar</code> either through File Explorer or in the command line through the following command:</p> +<pre><code>java -jar gsviewer.jar</code></pre><h4 id="building-on-macos">Building on MacOS</h4> +<p>On your command line, navigate to <code>ghostpdl/demos/java/gsviewer</code> and ensure that the build script is executable and then run it, with:</p> +<pre><code>chmod +x build_darwin.sh +./build_darwin.sh</code></pre><p>This will automatically build <code>gs_jni.dylib</code> (in the <code>ghostpdl/demos/java/jni/gs_jni/</code> location) and <code>gsjava.jar</code> <code>gsviewer.jar</code> in the <code>gsviewer</code> directory.</p> +<h4 id="running-on-macos">Running on MacOS</h4> +<p>Ensure that the Ghostscript library exists in the <code>gsviewer</code> directory. (Copy and move the built library from <code>ghostpdl/sobin</code> as required).</p> +<p>Ensure that the run script is executable and then run it, with:</p> +<pre><code>chmod +x start_darwin.sh +./start_darwin.sh</code></pre><h4 id="building-on-linux">Building on Linux</h4> +<p>On your command line, navigate to <code>ghostpdl/demos/java/gsviewer</code> and ensure that the build script is executable and then run it, with:</p> +<pre><code>chmod +x build_linux.sh +./build_linux.sh</code></pre><p>This will automatically build <code>gs_jni.so</code> (in the <code>ghostpdl/demos/java/jni/gs_jni/</code> location) and <code>gsjava.jar</code> <code>gsviewer.jar</code> in the <code>gsviewer</code> directory.</p> +<blockquote> +<p><strong>NOTE</strong><br> +On Linux, when using OpenJDK, the property "assistive_technologies" may +need to be modified for the Java code to build. It can be modified by +editing the "accessibility.properties" file. This is located at:</p> +<p><code>/etc/java-8-openjdk/accessibility.properties</code></p> +</blockquote> +<h4 id="running-on-linux">Running on Linux</h4> +<p>Ensure that the Ghostscript library exists in the <code>gsviewer</code> directory. (Copy and move the built library from <code>ghostpdl/sobin</code> as required).</p> +<p>Ensure that the run script is executable and then run it, with:</p> +<pre><code>chmod +x start_linux.sh +./start_linux.sh</code></pre></article> + + </div><!-- /middle --> + + <div class="right"> + <div class="link"><a href="#about">About</a></div> + <div class="link"><a href="#platform-setup">Platform & setup</a></div> + <div class="sub-link"><a href="#building-ghostscript">Building Ghostscript</a></div> + <div class="sub-link"><a href="#jni-building-the-java-native-interface">jni: Building the Java Native Interface</a></div> + <div class="sub-link"><a href="#gsjava-building-the-jar">gsjava: Building the JAR</a></div> + <div class="link"><a href="#demo-projects">Demo projects</a></div> + <div class="sub-link"><a href="#gstest">gstest</a></div> + <div class="sub-link"><a href="#gsviewer">gsviewer</a></div> + </div> + + </div> + + <footer></footer> + + </body> + +</html> diff --git a/doc/language-bindings/js/default.js b/doc/language-bindings/js/default.js new file mode 100644 index 00000000..3ec04940 --- /dev/null +++ b/doc/language-bindings/js/default.js @@ -0,0 +1,53 @@ +var showingBurgerMenu = false; + +function showMenu() { + showingBurgerMenu = !showingBurgerMenu; + + var mobileMenu = document.getElementById("burger-menu"); + + if (showingBurgerMenu) { + mobileMenu.classList.add("show"); + } else { + mobileMenu.classList.remove("show"); + } + +} + +function copyText(buttonDiv) { + for (var i=0;i<buttonDiv.parentNode.childNodes.length;i++) { + + if (buttonDiv.parentNode.childNodes[i].tagName!=undefined) { + if (buttonDiv.parentNode.childNodes[i].tagName.toLowerCase()=="code") { + var codeBlock = buttonDiv.parentNode.childNodes[i]; + var copyText = codeBlock.innerHTML; + const textArea = document.createElement('textarea'); + textArea.textContent = copyText; + document.body.append(textArea); + textArea.select(); + document.execCommand("copy"); + } + } + } +} + +function showCopyButton(preDiv) { + for (var i=0;i<preDiv.childNodes.length;i++) { + + if (preDiv.childNodes[i].tagName!=undefined) { + if (preDiv.childNodes[i].tagName.toLowerCase()=="button") { + preDiv.childNodes[i].classList.add("show"); + } + } + } +} + +function hideCopyButton(preDiv) { + for (var i=0;i<preDiv.childNodes.length;i++) { + + if (preDiv.childNodes[i].tagName!=undefined) { + if (preDiv.childNodes[i].tagName.toLowerCase()=="button") { + preDiv.childNodes[i].classList.remove("show"); + } + } + } +} diff --git a/doc/language-bindings/md/c-sharp-ghost-api.md b/doc/language-bindings/md/c-sharp-ghost-api.md new file mode 100644 index 00000000..e369cf3a --- /dev/null +++ b/doc/language-bindings/md/c-sharp-ghost-api.md @@ -0,0 +1,603 @@ +# GhostAPI + +<div class="banner"> + <div class="c-sharp-text"></div> + <div class="vendor-logo c-sharp-logo"></div> +</div> + + +## About + +`GhostAPI` is the `C#` bridge into the Ghostscript `C` library. + +`GhostAPI` contains some essential [structs and enums] as well as a static class for some [constants], finally it contains the main [GSAPI] class which holds the key methods which interface with the `C` library. + +## Structs and Enums + + +### gsapi_revision_t + +This `struct` is used to contain information pertinent to the version of Ghostscript. + +<div class="tag structDefinition csharp"></div> + +``` +public struct gsapi_revision_t +{ + public IntPtr product; + public IntPtr copyright; + public int revision; + public int revisiondate; +} +``` + + +### gs_set_param_type + + +<div class="tag enumDefinition csharp"></div> + +``` +public enum gs_set_param_type +{ + gs_spt_invalid = -1, + gs_spt_null = 0, /* void * is NULL */ + gs_spt_bool = 1, /* void * is NULL (false) or non-NULL (true) */ + gs_spt_int = 2, /* void * is a pointer to an int */ + gs_spt_float = 3, /* void * is a float * */ + gs_spt_name = 4, /* void * is a char * */ + gs_spt_string = 5, /* void * is a char * */ + gs_spt_long = 6, /* void * is a long * */ + gs_spt_i64 = 7, /* void * is an int64_t * */ + gs_spt_size_t = 8, /* void * is a size_t * */ + gs_spt_parsed = 9, /* void * is a pointer to a char * to be parsed */ + gs_spt_more_to_come = 1 << 31 +}; +``` + + +### gsEncoding + + +<div class="tag enumDefinition csharp"></div> + + +``` +public enum gsEncoding +{ + GS_ARG_ENCODING_LOCAL = 0, + GS_ARG_ENCODING_UTF8 = 1, + GS_ARG_ENCODING_UTF16LE = 2 +}; +``` + +## Constants + +Constants are stored in the static class `gsConstants` for direct referencing. + +### gsConstants + + +<div class="tag classDefinition csharp"></div> + +``` +static class gsConstants +{ + public const int E_QUIT = -101; + public const int GS_READ_BUFFER = 32768; + public const int DISPLAY_UNUSED_LAST = (1 << 7); + public const int DISPLAY_COLORS_RGB = (1 << 2); + public const int DISPLAY_DEPTH_8 = (1 << 11); + public const int DISPLAY_LITTLEENDIAN = (1 << 16); + public const int DISPLAY_BIGENDIAN = (0 << 16); +} +``` + +## GSAPI + +Methods contained within are explained below. + +`gsapi_run_*` and `gsapi_exit` methods return an `int` code which can be interpreted as follows: + +| code | status | +|---|---| +|`0`| no error | +|`gsConstants.E_QUIT`| "quit" has been executed. This is not an error. [gsapi_exit] must be called next | +|`<0` | error | + +>**NOTE**<br> +> For full detail on these return code please see: +https://www.ghostscript.com/doc/current/API.htm#return_codes +> + +> **NOTE**<br> +> All [GSAPI] methods aside from [gsapi_revision] and [gsapi_new_instance] should pass an instance of Ghostscript as their first parameter with `IntPtr instance` +> + +### gsapi_revision + +This method returns the revision numbers and strings of the Ghostscript interpreter library; you should call it before any other interpreter library functions to make sure that the correct version of the Ghostscript interpreter has been loaded. + + + +<div class="tag methodDefinition csharp"></div> + +``` +public static extern int gsapi_revision(ref gsapi_revision_t vers, + int size); +``` + + +> **NOTE**<br> +> The method should write to a reference variable which conforms to the struct [gsapi_revision_t]. +> + +### gsapi_new_instance + +Creates a new instance of Ghostscript. This instance is passed to most other [GSAPI] methods. Unless Ghostscript has been compiled with the `GS_THREADSAFE` define, only one instance at a time is supported. + +<div class="tag methodDefinition csharp"></div> + +``` +public static extern int gsapi_new_instance(out IntPtr pinstance, + IntPtr caller_handle); +``` + + +> **NOTE**<br> +> The method returns a pointer which represents your instance of Ghostscript. +> + +### gsapi_delete_instance + +Destroy an instance of Ghostscript. Before you call this, Ghostscript must have finished. If Ghostscript has been initialised, you must call [gsapi_exit] beforehand. + +<div class="tag methodDefinition csharp"></div> + +``` +public static extern void gsapi_delete_instance(IntPtr instance); +``` + +<div class="tag sampleCode csharp"></div> + +``` +GSAPI.gsapi_delete_instance(gsInstance); +gsInstance = IntPtr.Zero; +``` + +### gsapi_set_stdio_with_handle + +Set the callback functions for `stdio`, together with the handle to use in the callback functions. The `stdin` callback function should return the number of characters read, 0 for EOF, or -1 for error. The `stdout` and `stderr` callback functions should return the number of characters written. + + + +> **NOTE**<br> +> These callbacks do not affect output device I/O when using "%stdout" as the output file. In that case, device output will still be directed to the process "stdout" file descriptor, not to the `stdio` callback. +> + +<div class="tag methodDefinition csharp"></div> + +``` +public static extern int gsapi_set_stdio_with_handle(IntPtr instance, + gs_stdio_handler stdin, + gs_stdio_handler stdout, + gs_stdio_handler stderr, + IntPtr caller_handle); +``` + + +### gsapi_set_stdio + +Set the callback functions for `stdio`. The handle used in the callbacks will be taken from the value passed to [gsapi_new_instance]. Otherwise the behaviour of this function matches [gsapi_set_stdio_with_handle]. + +<div class="tag methodDefinition csharp"></div> + +``` +public static extern int gsapi_set_stdio_with_handle(IntPtr instance, + gs_stdio_handler stdin, + gs_stdio_handler stdout, + gs_stdio_handler stderr); +``` + + +### gsapi_set_poll_with_handle + +Set the callback function for polling, together with the handle to pass to the callback function. This function will only be called if the Ghostscript interpreter was compiled with `CHECK_INTERRUPTS` as described in `gpcheck.h`. + +The polling function should return zero if all is well, and return negative if it wants ghostscript to abort. This is often used for checking for a user cancel. This can also be used for handling window events or cooperative multitasking. + +The polling function is called very frequently during interpretation and rendering so it must be fast. If the function is slow, then using a counter to `return 0` immediately some number of times can be used to reduce the performance impact. + + +<div class="tag methodDefinition csharp"></div> + +``` +public static extern int gsapi_set_poll_with_handle(IntPtr instance, + gsPollHandler pollfn, + IntPtr caller_handle); +``` + +### gsapi_set_poll + +Set the callback function for polling. The handle passed to the callback function will be taken from the handle passed to [gsapi_new_instance]. Otherwise the behaviour of this function matches [gsapi_set_poll_with_handle]. + +<div class="tag methodDefinition csharp"></div> + +``` +public static extern int gsapi_set_poll(IntPtr instance, + gsPollHandler pollfn); +``` + + +### gsapi_set_display_callback + +This call is deprecated; please use [gsapi_register_callout] to register a [callout handler] for the display device in preference. + +<div class="tag methodDefinition csharp"></div> + +``` +public static extern int gsapi_set_display_callback(IntPtr pinstance, + IntPtr caller_handle); +``` + +### gsapi_register_callout + +This call registers a [callout handler]. + +<div class="tag methodDefinition csharp"></div> + +``` +public static extern int gsapi_register_callout(IntPtr instance, + gsCallOut callout, + IntPtr callout_handle); +``` + +### gsapi_deregister_callout + + +This call deregisters a [callout handler] previously registered with [gsapi_register_callout]. All three arguments must match exactly for the [callout handler] to be deregistered. + + +<div class="tag methodDefinition csharp"></div> + +``` +public static extern int gsapi_deregister_callout(IntPtr instance, + gsCallOut callout, + IntPtr callout_handle); +``` + +### gsapi_set_arg_encoding + +Set the encoding used for the interpretation of all subsequent arguments supplied via the `GhostAPI` interface on this instance. By default we expect args to be in encoding `0` (the 'local' encoding for this OS). On Windows this means "the currently selected codepage". On Linux this typically means `utf8`. This means that omitting to call this function will leave Ghostscript running exactly as it always has. Please note that use of the 'local' encoding is now deprecated and should be avoided in new code. This must be called after [gsapi_new_instance] and before [gsapi_init_with_args]. + +<div class="tag methodDefinition csharp"></div> + +``` +public static extern int gsapi_set_arg_encoding(IntPtr instance, + int encoding); +``` + +### gsapi_set_default_device_list + +Set the string containing the list of default device names, for example "display x11alpha x11 bbox". Allows the calling application to influence which device(s) Ghostscript will try, in order, in its selection of the default device. This must be called after [gsapi_new_instance] and before [gsapi_init_with_args]. + +<div class="tag methodDefinition csharp"></div> + +``` +public static extern int gsapi_set_default_device_list(IntPtr instance, + IntPtr list, + ref int listlen); +``` + +### gsapi_get_default_device_list + +Returns a pointer to the current default device string. This must be called after [gsapi_new_instance] and before [gsapi_init_with_args]. + +<div class="tag methodDefinition csharp"></div> + +``` +public static extern int gsapi_get_default_device_list(IntPtr instance, + ref IntPtr list, + ref int listlen); +``` + +### gsapi_init_with_args + +To initialise the interpreter, pass your `instance` of Ghostscript, your argument count, `argc`, and your argument variables, `argv`. + +<div class="tag methodDefinition csharp"></div> + +``` +public static extern int gsapi_init_with_args(IntPtr instance, + int argc, + IntPtr argv); +``` + +### gsapi\_run\_\* + +If these functions return `<= -100`, either quit or a fatal error has occured. You must call [gsapi_exit] next. The only exception is [gsapi_run_string_continue] which will return `gs_error_NeedInput` if all is well. + +There is a 64 KB length limit on any buffer submitted to a `gsapi_run_*` function for processing. If you have more than 65535 bytes of input then you must split it into smaller pieces and submit each in a separate [gsapi_run_string_continue] call. + +### gsapi_run_string_begin + +<div class="tag methodDefinition csharp"></div> + +``` +public static extern int gsapi_run_string_begin(IntPtr instance, + int usererr, + ref int exitcode); +``` + +### gsapi_run_string_continue + +<div class="tag methodDefinition csharp"></div> + +``` +public static extern int gsapi_run_string_continue(IntPtr instance, + IntPtr command, + int count, + int usererr, + ref int exitcode); +``` + +### gsapi_run_string_with_length + +<div class="tag methodDefinition csharp"></div> + +``` +public static extern int gsapi_run_string_with_length(IntPtr instance, + IntPtr command, + uint length, + int usererr, + ref int exitcode); +``` + +### gsapi_run_string + + +<div class="tag methodDefinition csharp"></div> + +``` +public static extern int gsapi_run_string(IntPtr instance, + IntPtr command, + int usererr, + ref int exitcode); +``` + +### gsapi_run_string_end + +<div class="tag methodDefinition csharp"></div> + +``` +public static extern int gsapi_run_string_end(IntPtr instance, + int usererr, + ref int exitcode); +``` + +### gsapi_run_file + +<div class="tag methodDefinition csharp"></div> + +``` +public static extern int gsapi_run_file(IntPtr instance, + IntPtr filename, + int usererr, + ref int exitcode); +``` + +### 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]. + +<div class="tag methodDefinition csharp"></div> + +``` +public static extern int gsapi_exit(IntPtr instance); +``` + +### gsapi_set_param + +Sets a parameter. + +Broadly, this is equivalent to setting a parameter using -d, -s or -p on the command line. This call cannot be made during a [gsapi_run_string] operation. + +Parameters in this context are not the same as 'arguments' as processed by [gsapi_init_with_args], but often the same thing can be achieved. For example, with [gsapi_init_with_args], we can pass "-r200" to change the resolution. Broadly the same thing can be achieved by using [gsapi_set_param] to set a parsed value of "<</HWResolution [ 200.0 200.0 ]>>". + +Internally, when we set a parameter, we perform an `initgraphics` operation. This means that using [gsapi_set_param] other than at the start of a page is likely to give unexpected results. + +Attempting to set a parameter that the device does not recognise will be silently ignored, and that parameter will not be found in subsequent [gsapi_get_param] calls. + + +<div class="tag methodDefinition csharp"></div> + +``` +public static extern int gsapi_set_param(IntPtr instance, + IntPtr param, + IntPtr value, + gs_set_param_type type); +``` + + +> **NOTE**<br> +> The `type` argument, as a [gs_set_param_type], dictates the kind of object that the `value` argument points to. +> + +> **NOTE**<br> +> For more on the C implementation of parameters see: [Ghostscript parameters in C]. +> + +### gsapi_get_param + +Retrieve the current value of a parameter. + +If an error occurs, the return value is negative. Otherwise the return value is the number of bytes required for storage of the value. Call once with value `NULL` to get the number of bytes required, then call again with value pointing to at least the required number of bytes where the value will be copied out. Note that the caller is required to know the type of value in order to get it. For all types other than [gs_spt_string], [gs_spt_name], and [gs_spt_parsed] knowing the type means you already know the size required. + +This call retrieves parameters/values that have made it to the device. Thus, any values set using [gs_spt_more_to_come] without a following call omitting that flag will not be retrieved. Similarly, attempting to get a parameter before [gsapi_init_with_args] has been called will not list any, even if [gsapi_set_param] has been used. + +Attempting to read a parameter that is not set will return `gs_error_undefined` (-21). Note that calling [gsapi_set_param] followed by [gsapi_get_param] may not find the value, if the device did not recognise the key as being one of its configuration keys. + +For the C documentation please refer to [Ghostscript get_param]. + + +<div class="tag methodDefinition csharp"></div> + +``` +public static extern int gsapi_get_param(IntPtr instance, + IntPtr param, + IntPtr value, + gs_set_param_type type); +``` + +### gsapi_enumerate_params + +Enumerate the current parameters. Call repeatedly to list out the current parameters. + +The first call should have `iter` = NULL. Subsequent calls should pass the same pointer in so the iterator can be updated. Negative return codes indicate error, 0 success, and 1 indicates that there are no more keys to read. On success, key will be updated to point to a null terminated string with the key name that is guaranteed to be valid until the next call to [gsapi_enumerate_params]. If `type` is non NULL then the pointer `type` will be updated to have the `type` of the parameter. + +> **NOTE**<br> +> Only one enumeration can happen at a time. Starting a second enumeration will reset the first. +> + +The enumeration only returns parameters/values that have made it to the device. Thus, any values set using the [gs_spt_more_to_come] without a following call omitting that flag will not be retrieved. Similarly, attempting to enumerate parameters before [gsapi_init_with_args] has been called will not list any, even if [gsapi_set_param] has been used. + +<div class="tag methodDefinition csharp"></div> + +``` +public static extern int gsapi_enumerate_params(IntPtr instance, + out IntPtr iter, + out IntPtr key, + IntPtr type); +``` + +### gsapi_add_control_path + +Add a (case sensitive) path to one of the lists of [permitted paths] for file access. + +<div class="tag methodDefinition csharp"></div> + +``` +public static extern int gsapi_add_control_path(IntPtr instance, + int type, + IntPtr path); +``` + +### gsapi_remove_control_path + +Remove a (case sensitive) path from one of the lists of [permitted paths] for file access. + +<div class="tag methodDefinition csharp"></div> + +``` +public static extern int gsapi_remove_control_path(IntPtr instance, + int type, + IntPtr path); +``` + +### gsapi_purge_control_paths + +Clear all the paths from one of the lists of [permitted paths] for file access. +<div class="tag methodDefinition csharp"></div> + +``` +public static extern void gsapi_purge_control_paths(IntPtr instance, + int type); +``` + +### gsapi_activate_path_control + +Enable/Disable path control (i.e. whether paths are checked against [permitted paths] before access is granted). + +<div class="tag methodDefinition csharp"></div> + +``` +public static extern void gsapi_activate_path_control(IntPtr instance, + int enable); +``` + +### gsapi_is_path_control_active + + +Query whether path control is activated or not. + +<div class="tag methodDefinition csharp"></div> + + +``` +public static extern int gsapi_is_path_control_active(IntPtr instance); +``` + + + +## Callback and Callout prototypes + +[GSAPI] also defines some prototype pointers which are defined as follows. + +### gs_stdio_handler + +<div class="tag callbackDefinition csharp"></div> + +``` +/* Callback proto for stdio */ +public delegate int gs_stdio_handler(IntPtr caller_handle, + IntPtr buffer, + int len); +``` + + +### gsPollHandler + +<div class="tag callbackDefinition csharp"></div> + +``` +/* Callback proto for poll function */ +public delegate int gsPollHandler(IntPtr caller_handle); +``` + + +### gsCallOut + +<div class="tag callbackDefinition csharp"></div> + +``` +/* Callout proto */ +public delegate int gsCallOut(IntPtr callout_handle, + IntPtr device_name, + int id, + int size, + IntPtr data); + +``` + + +[structs and enums]: #structs-and-enums +[constants]: #constants +[GSAPI]: #gsapi + +[Ghostscript parameters in C]: https://www.ghostscript.com/doc/current/Use.htm#Parameters +[Ghostscript get_param]: https://www.ghostscript.com/doc/current/API.htm#get_param +[gsapi_revision_t]: #gsapi_revision_t + +[gsapi_revision]: #gsapi_revision +[gsapi_exit]: #gsapi_exit +[gsapi_new_instance]: #gsapi_new_instance +[gsapi_set_stdio_with_handle]: #gsapi_set_stdio_with_handle +[gsapi_set_poll_with_handle]: #gsapi_set_poll_with_handle +[gsapi_register_callout]: #gsapi_register_callout +[gsapi_init_with_args]: #gsapi_init_with_args +[gsapi_delete_instance]: #gsapi_delete_instance +[gsapi_exit]: #gsapi_exit +[gsapi_run_string]: #gsapi_run_string +[gsapi_run_string_continue]: #gsapi_run_string_continue +[gs_set_param_type]: #gs_set_param_type +[gs_spt_more_to_come]: #gs_set_param_type +[gs_spt_string]: #gs_set_param_type +[gs_spt_name]: #gs_set_param_type +[gs_spt_parsed]: #gs_set_param_type +[gsapi_set_param]: #gsapi_set_param +[gsapi_get_param]: #gsapi_get_param +[gsapi_enumerate_params]: #gsapi_enumerate_params + +[permitted paths]: https://ghostscript.com/doc/current/Use.htm#Safer + +[callout handler]: #gscallout diff --git a/doc/language-bindings/md/c-sharp-ghost-mono.md b/doc/language-bindings/md/c-sharp-ghost-mono.md new file mode 100644 index 00000000..edc7925b --- /dev/null +++ b/doc/language-bindings/md/c-sharp-ghost-mono.md @@ -0,0 +1,633 @@ +# GhostMono + +<div class="banner"> + <div class="c-sharp-text"></div> + <div class="vendor-logo c-sharp-logo"></div> +</div> + + +## About + +`GhostMono` is the `C#` interface into the `GhostAPI` library developed for Linux systems. + +## Enums + +### Tasks + +The Ghostscript task type `enum` is used to inform `GhostAPI` of the type of operation which is being requested. + + +| Task | Description | +|---|---| +|PS_DISTILL|Task associated with converting a PostScript stream to a PDF document| +|CREATE_XPS|Task associated with outputting a copy of a document to XPS| +|SAVE_RESULT|Task associated with saving documents| +|GET_PAGE_COUNT|Task associated with getting the page count of a document| +|GENERIC|Generic task identifier| +|DISPLAY_DEV_THUMBS|Display Device task associated with rendering thumbnails| +|DISPLAY_DEV_NON_PDF|Display Device task associated with non-PDF or non-XPS rendering <sup>[1]</sup>| +|DISPLAY_DEV_PDF|Display Device task associated with PDF & XPS rendering <sup>[1]</sup>| +|DISPLAY_DEV_RUN_FILE|Display Device task associated with running files| + +Task types are defined as `GS_Task_t`. + +<div class="tag enumDefinition csharp"></div> + +``` +public enum GS_Task_t +{ + PS_DISTILL, + CREATE_XPS, + SAVE_RESULT, + GET_PAGE_COUNT, + GENERIC, + DISPLAY_DEV_THUMBS, + DISPLAY_DEV_NON_PDF, + DISPLAY_DEV_PDF, + DISPLAY_DEV_RUN_FILE +} +``` + +### Results + +Result types are defined as `GS_Result_t`. + +<div class="tag enumDefinition csharp"></div> + +``` +public enum GS_Result_t +{ + gsOK, + gsFAILED, + gsCANCELLED +} +``` + +### Status + +Status is defined as `gsStatus`. + +<div class="tag enumDefinition csharp"></div> + +``` +public enum gsStatus +{ + GS_READY, + GS_BUSY, + GS_ERROR +}; +``` + +## The Parameter Struct + +The parameter struct `gsParamState_t` allows for bundles of information to be processed by Ghostscript to complete overall requests. + +<div class="tag structDefinition csharp"></div> + +``` +public struct gsParamState_t +{ + public String outputfile; + public String inputfile; + public GS_Task_t task; + public GS_Result_t result; + public int num_pages; + public List<int> pages; + public int firstpage; + public int lastpage; + public int currpage; + public List<String> args; + public int return_code; + public double zoom; +}; +``` + + +### Parameters explained + +Setting up your parameters (with any dedicated bespoke method(s) which your application requires) is needed when communicating directly with `GhostAPI`. + +When requesting Ghostscript to process an operation an application developer should send a parameter payload which defines the details for the operation. + +For example in `GhostMono` we can see the public method as follows: + +<div class="tag sampleCode csharp"></div> + +``` +public gsStatus DistillPS(String fileName, int resolution) +{ + gsParamState_t gsparams = new gsParamState_t(); + gsparams.args = new List<string>(); + + gsparams.inputfile = fileName; + gsparams.args.Add("gs"); + gsparams.args.Add("-dNOPAUSE"); + gsparams.args.Add("-dBATCH"); + gsparams.args.Add("-I%rom%Resource/Init/"); + gsparams.args.Add("-dSAFER"); + gsparams.args.Add("-sDEVICE=pdfwrite"); + gsparams.outputfile = Path.GetTempFileName(); + gsparams.args.Add("-o" + gsparams.outputfile); + gsparams.task = GS_Task_t.PS_DISTILL; + + return RunGhostscriptAsync(gsparams); +} +``` + +Here we can see a parameter payload being setup before being passed on to the asynchronous method `RunGhostscriptAsync` which sets up a worker thread to run according to the task type in the payload. + +`GhostMono` handles many common operations on an application developer's behalf, however if you require to write your own methods to interface with `GhostAPI` then referring to the public methods in `GhostMono` is a good starting point. + +For full documentation on parameters refer to [Ghostscript parameters]. + + +## The Event class + +`GhostMono` contains a public class `gsThreadCallBack`. This class is used to set and get callback information as they occur. `GhostMono` will create these payloads and deliver them back to the application layer's `ProgressCallBack` method [asynchronously]. + + +<div class="tag classDefinition csharp"></div> + +``` +public class gsThreadCallBack +{ + private bool m_completed; + private int m_progress; + private gsParamState_t m_param; + public bool Completed + { + get { return m_completed; } + } + public gsParamState_t Params + { + get { return m_param; } + } + public int Progress + { + get { return m_progress; } + } + public gsThreadCallBack(bool completed, int progress, gsParamState_t param) + { + m_completed = completed; + m_progress = progress; + m_param = param; + } +} +``` + + +## GSMONO + +This class should be instantiated as a member variable in your application with callback definitions setup as required. + +Handlers for asynchronous operations can injected by providing your own bespoke callback methods to your instance's `ProgressCallBack` function. + +<div class="tag sampleCode csharp"></div> + +``` +/* Set up ghostscript with callbacks for system updates */ +m_ghostscript = new GSMONO(); +m_ghostscript.ProgressCallBack += new GSMONO.Progress(gsProgress); +m_ghostscript.StdIOCallBack += new GSMONO.StdIO(gsIO); +m_ghostscript.DLLProblemCallBack += new GSMONO.DLLProblem(gsDLL); +m_ghostscript.PageRenderedCallBack += new GSMONO.PageRendered(gsPageRendered); +m_ghostscript.DisplayDeviceOpen(); + +/* example callback stubs for asynchronous operations */ +private void gsProgress(gsThreadCallBack asyncInformation) +{ + Console.WriteLine($"gsProgress().progress:{asyncInformation.Progress}"); + + if (asyncInformation.Completed) // task complete + { + // what was the task? + switch (asyncInformation.Params.task) + { + case GS_Task_t.CREATE_XPS: + Console.WriteLine($"CREATE_XPS.outputfile:"); + Console.WriteLine($"{asyncInformation.Params.result.outputfile}"); + break; + + case GS_Task_t.PS_DISTILL: + Console.WriteLine($"PS_DISTILL.outputfile:"); + Console.WriteLine($"{asyncInformation.Params.result.outputfile}"); + break; + + case GS_Task_t.SAVE_RESULT: + + break; + + case GS_Task_t.DISPLAY_DEV_THUMBS: + + break; + + case GS_Task_t.DISPLAY_DEV_RUN_FILE: + + break; + + case GS_Task_t.DISPLAY_DEV_PDF: + + break; + + case GS_Task_t.DISPLAY_DEV_NON_PDF: + + break; + + default: + + break; + } + + // task failed + if (asyncInformation.Params.result == GS_Result_t.gsFAILED) + { + switch (asyncInformation.Params.task) + { + case GS_Task_t.CREATE_XPS: + + break; + + case GS_Task_t.PS_DISTILL: + + break; + + case GS_Task_t.SAVE_RESULT: + + break; + + default: + + break; + } + return; + } + + // task cancelled + if (asyncInformation.Params.result == GS_Result_t.gsCANCELLED) + { + + } + } + else // task is still running + { + switch (asyncInformation.Params.task) + { + case GS_Task_t.CREATE_XPS: + + break; + + case GS_Task_t.PS_DISTILL: + + break; + + case GS_Task_t.SAVE_RESULT: + + break; + } + } +} + +private void gsIO(String message, int len) +{ + Console.WriteLine($"gsIO().message:{message}, length:{len}"); +} + +private void gsDLL(String message) +{ + Console.WriteLine($"gsDLL().message:{message}"); +} + +private void gsPageRendered(int width, + int height, + int raster, + IntPtr data, + gsParamState_t state) +{ + +}; +``` + +> **NOTE**<br> +> Once a Ghostscript operation is in progress any defined callback functions will be called as the operation runs up unto completion. These callback methods are essential for your application to interpret activity events and react accordingly. +> + +An explanation of callbacks and the available public methods within `GSMONO` are explained below. + + +### Delegates + +To handle asynchronous events `GhostMONO` has four delegates which define callback methods that an application can assign to. + + +| Callback | Description | +|---|---| +|`DLLProblemCallBack`|Occurs if there is some issue with the Ghostscript Shared Object (`libgpdl.so`)| +|`StdIOCallBack`|Occurs if Ghostscript outputs something to `stderr` or `stdout`| +|`ProgressCallBack`|Occurs as Ghostscript makes its way through a file| +|`PageRenderedCallBack`|Occurs when a page has been rendered and the data from the display device is ready| + + +#### DLLProblemCallBack + +<div class="tag callbackDefinition csharp"></div> + +``` +internal delegate void DLLProblem(String mess); +internal event DLLProblem DLLProblemCallBack; +``` + +#### StdIOCallBack + +<div class="tag callbackDefinition csharp"></div> + +``` +internal delegate void StdIO(String mess, + int len); +internal event StdIO StdIOCallBack; +``` + +#### ProgressCallBack + +<div class="tag callbackDefinition csharp"></div> + +``` +internal delegate void Progress(gsEventArgs info); +internal event Progress ProgressCallBack; +``` + +#### PageRenderedCallBack + +<div class="tag callbackDefinition csharp"></div> + +``` +internal delegate void PageRendered(int width, + int height, + int raster, + IntPtr data, + gsParamState_t state); +internal event PageRendered PageRenderedCallBack; +``` + + +### GetVersion + +Use this method to get Ghostscript version info as a handy `String`. + +<div class="tag methodDefinition csharp"></div> + +``` +public String GetVersion() +``` + +<div class="tag sampleCode csharp"></div> + +``` +String gs_vers = m_ghostscript.GetVersion(); +``` + +> **NOTE**<br> +> An exception will be thrown if there is any issue with the Ghostscript DLL. +> + + +### DisplayDeviceOpen + +Sets up the [display device] ahead of time. + + +<div class="tag methodDefinition csharp"></div> + +``` +public gsParamState_t DisplayDeviceOpen() +``` + +<div class="tag sampleCode csharp"></div> + +``` +m_ghostscript.DisplayDeviceOpen(); +``` + +> **NOTE**<br> +> Calling this method [instantiates ghostscript] and configures the encoding and the callbacks for the display device. +> + + +### DisplayDeviceClose + +Closes the [display device] and deletes the instance. + + + +<div class="tag methodDefinition csharp"></div> + +``` +public gsParamState_t DisplayDeviceClose() +``` + +<div class="tag sampleCode csharp"></div> + +``` +m_ghostscript.DisplayDeviceClose(); +``` + +> **NOTE**<br> +> Calling this method [deletes ghostscript]. +> + + +### GetPageCount + +Use this method to get the number of pages in a supplied document. + +<div class="tag methodDefinition csharp"></div> + +``` +public int GetPageCount(String fileName) +``` + + +<div class="tag sampleCode csharp"></div> + +``` +int page_number = m_ghostscript.GetPageCount("my_document.pdf"); +``` + + +> **NOTE**<br> +> If Ghostscript is unable to determine the page count then this method will return `-1`. +> + + +### DistillPS + +Launches a thread rendering all the pages of a supplied PostScript file to a PDF. + +<div class="tag methodDefinition csharp async"></div> + +``` +public gsStatus DistillPS(String fileName, int resolution) +``` + +<div class="tag sampleCode csharp"></div> + +``` +m_ghostscript.DistillPS("my_postscript_document.ps", 300); +``` + +<span class="smallText alignRight"> + +_[asynchronous]_ + +</span> + + + +### DisplayDeviceRenderAll + + +Launches a thread rendering all the document pages with the [display device]. For use with languages that can be indexed via pages which include PDF and XPS. [1] + +<div class="tag methodDefinition csharp async"></div> + +``` +public gsStatus DisplayDeviceRenderAll(String fileName, double zoom, bool aa, GS_Task_t task) +``` + +<div class="tag sampleCode csharp"></div> + +``` +m_ghostscript.DisplayDeviceRenderAll("my_document.pdf", + 0.1, + false, + GS_Task_t.DISPLAY_DEV_THUMBS_NON_PDF); +``` + +<span class="smallText alignRight"> + +_[asynchronous]_ + +</span> + + +### DisplayDeviceRenderThumbs + +Launches a thread rendering all the pages with the [display device] to collect thumbnail images. + +Recommended zoom level for thumbnails is between 0.05 and 0.2, additionally anti-aliasing is probably not required. + +<div class="tag methodDefinition csharp async"></div> + +``` +public gsStatus DisplayDeviceRenderThumbs(String fileName, + double zoom, + bool aa) +``` + +<div class="tag sampleCode csharp"></div> + +``` +m_ghostscript.DisplayDeviceRenderThumbs("my_document.pdf", + 0.1, + false); +``` + +<span class="smallText alignRight"> + +_[asynchronous]_ + +</span> + + +### DisplayDeviceRenderPages + + +Launches a thread rendering a set of pages with the [display device]. For use with languages that can be indexed via pages which include PDF and XPS. <sup>[1]</sup> + + + + +<div class="tag methodDefinition csharp async"></div> + +``` +public gsStatus DisplayDeviceRenderPages(String fileName, + int first_page, + int last_page, + double zoom) +``` + +<div class="tag sampleCode csharp"></div> + +``` +m_ghostscript.DisplayDeviceRenderPages("my_document.pdf", + 0, + 9, + 1.0); +``` + +<span class="smallText alignRight"> + +_[asynchronous]_ + +</span> + + +### GetStatus + +Returns the current [status] of `Ghostscript`. + +<div class="tag methodDefinition csharp"></div> + +``` +public gsStatus GetStatus() +``` + +<div class="tag sampleCode csharp"></div> + +``` +gsStatus status = m_ghostscript.GetStatus(); +``` + + +### GhostscriptException + +An application developer can log any exceptions in this public class as required by editing the constructor. + + +<div class="tag classDefinition csharp"></div> + +``` +public class GhostscriptException : Exception +{ + public GhostscriptException(string message) : base(message) + { + // Report exceptions as required + } +} +``` + + +## Notes + +#### 1: Ghostscript & Page Description Languages + +Ghostscript handles the following [PDLs]: `PCL` `PDF` `PS` `XPS`. + +`PCL` and `PS` do not allow random access, meaning that, to print page 2 in a 100 page document, Ghostscript has to read the entire document stream of 100 pages. + +On the other hand, `PDF` and `XPS` allow for going directly to page 2 and then only dealing with that content. The tasks `DISPLAY_DEV_NON_PDF` and `DISPLAY_DEV_PDF` keep track of what sort of input Ghostscript is dealing with and enables the application to direct progress or completion callbacks accordingly. + + +[PDLs]: https://en.wikipedia.org/wiki/Page_description_language +[GhostAPI]: c-sharp-ghost-api.html +[gsapi_revision]: c-sharp-ghost-api.html#gsapi_revision +[Ghostscript parameters]: https://www.ghostscript.com/doc/current/Use.htm#Parameters +[display device]: https://ghostscript.com/doc/current/Devices.htm#Display_devices +[instantiates ghostscript]: c-sharp-ghost-api.html#gsapi_new_instance +[deletes ghostscript]: c-sharp-ghost-api.html#gsapi_delete_instance +[status]: #status +[notes]: #notes +[1]: #1-ghostscript-page-description-languages + +[GSMono instantiation]: #gsmono +[asynchronous]: #delegates +[asynchronously]: #delegates diff --git a/doc/language-bindings/md/c-sharp-ghost-net.md b/doc/language-bindings/md/c-sharp-ghost-net.md new file mode 100644 index 00000000..7e2a9375 --- /dev/null +++ b/doc/language-bindings/md/c-sharp-ghost-net.md @@ -0,0 +1,681 @@ +# GhostNET + +<div class="banner"> + <div class="c-sharp-text"></div> + <div class="vendor-logo c-sharp-logo"></div> +</div> + + + +## About + +`GhostNET` is the `C#` interface into the `GhostAPI` library developed for Windows systems. + +## Enums + + +### Tasks + +The Ghostscript task type `enum` is used to inform `GhostAPI` of the type of operation which is being requested. + + +| Task | Description | +|---|---| +|PS_DISTILL|Task associated with converting a PostScript stream to a PDF document| +|CREATE_XPS|Task associated with outputting a copy of a document to XPS| +|SAVE_RESULT|Task associated with saving documents| +|GET_PAGE_COUNT|Task associated with getting the page count of a document| +|GENERIC|Generic task identifier| +|DISPLAY_DEV_THUMBS|Display Device task associated with rendering thumbnails| +|DISPLAY_DEV_NON_PDF|Display Device task associated with non-PDF or non-XPS rendering <sup>[1]</sup>| +|DISPLAY_DEV_PDF|Display Device task associated with PDF & XPS rendering <sup>[1]</sup>| +|DISPLAY_DEV_RUN_FILE|Display Device task associated with running files| + +Task types are defined as `GS_Task_t`. + +<div class="tag enumDefinition csharp"></div> + +``` +public enum GS_Task_t +{ + PS_DISTILL, + CREATE_XPS, + SAVE_RESULT, + GET_PAGE_COUNT, + GENERIC, + DISPLAY_DEV_THUMBS, + DISPLAY_DEV_NON_PDF, + DISPLAY_DEV_PDF, + DISPLAY_DEV_RUN_FILE +} +``` + +### Results + +Result types are defined as `GS_Result_t`. + +<div class="tag enumDefinition csharp"></div> + +``` +public enum GS_Result_t +{ + gsOK, + gsFAILED, + gsCANCELLED +} +``` + +### Status + +Status is defined as `gsStatus`. + +<div class="tag enumDefinition csharp"></div> + +``` +public enum gsStatus +{ + GS_READY, + GS_BUSY, + GS_ERROR +}; +``` + +## The Parameter Struct + +The parameter struct `gsParamState_t` allows for bundles of information to be processed by Ghostscript to complete overall requests. + +<div class="tag structDefinition csharp"></div> + +``` +public struct gsParamState_t +{ + public String outputfile; + public String inputfile; + public GS_Task_t task; + public GS_Result_t result; + public int num_pages; + public List<int> pages; + public int firstpage; + public int lastpage; + public int currpage; + public List<String> args; + public int return_code; + public double zoom; + public bool aa; + public bool is_valid; +}; +``` + +### Parameters explained + +Setting up your parameters (with any dedicated bespoke method(s) which your application requires) is needed when communicating directly with `GhostAPI`. + +When requesting Ghostscript to process an operation an application developer should send a parameter payload which defines the details for the operation. + +For example in `GhostNET` we can see the public method as follows: + + +<div class="tag sampleCode csharp"></div> + +``` +public gsStatus DistillPS(String fileName, int resolution) +{ + gsParamState_t gsparams = new gsParamState_t(); + gsparams.args = new List<string>(); + + gsparams.inputfile = fileName; + gsparams.args.Add("gs"); + gsparams.args.Add("-sDEVICE=pdfwrite"); + gsparams.outputfile = Path.GetTempFileName(); + gsparams.args.Add("-o" + gsparams.outputfile); + gsparams.task = GS_Task_t.PS_DISTILL; + + return RunGhostscriptAsync(gsparams); +} +``` + +Here we can see a parameter payload being setup before being passed on to the asynchronous method `RunGhostscriptAsync` which sets up a worker thread to run according to the task type in the payload. + +`GhostNET` handles many common operations on an application developer's behalf, however if you require to write your own methods to interface with `GhostAPI` then referring to the public methods in `GhostNET` is a good starting point. + +For full documentation on parameters refer to [Ghostscript parameters]. + +## The Event class + +`GhostNET` contains a public class `gsEventArgs` which is an extension of the C# class [EventArgs]. This class is used to set and get events as they occur. `GhostNET` will create these payloads and deliver them back to the application layer's `ProgressCallBack` method [asynchronously]. + +<div class="tag classDefinition csharp"></div> + +``` +public class gsEventArgs : EventArgs +{ + private bool m_completed; + private int m_progress; + private gsParamState_t m_param; + public bool Completed + { + get { return m_completed; } + } + public gsParamState_t Params + { + get { return m_param; } + } + public int Progress + { + get { return m_progress; } + } + public gsEventArgs(bool completed, int progress, gsParamState_t param) + { + m_completed = completed; + m_progress = progress; + m_param = param; + } +} +``` + + + + +## GSNET + +This class should be instantiated as a member variable in your application with callback definitions setup as required. + +Handlers for asynchronous operations can injected by providing your own bespoke callback methods to your instance's `ProgressCallBack` function. + +<div class="tag sampleCode csharp"></div> + +``` +/* Set up ghostscript with callbacks for system updates */ +m_ghostscript = new GSNET(); +m_ghostscript.ProgressCallBack += new GSNET.Progress(gsProgress); +m_ghostscript.StdIOCallBack += new GSNET.StdIO(gsIO); +m_ghostscript.DLLProblemCallBack += new GSNET.DLLProblem(gsDLL); +m_ghostscript.PageRenderedCallBack += new GSNET.PageRendered(gsPageRendered); +m_ghostscript.DisplayDeviceOpen(); + +/* example callback stubs for asynchronous operations */ +private void gsProgress(gsEventArgs asyncInformation) +{ + Console.WriteLine($"gsProgress().progress:{asyncInformation.Progress}"); + + if (asyncInformation.Completed) // task complete + { + // what was the task? + switch (asyncInformation.Params.task) + { + case GS_Task_t.CREATE_XPS: + Console.WriteLine($"CREATE_XPS.outputfile:"); + Console.WriteLine($"{asyncInformation.Params.result.outputfile}"); + break; + + case GS_Task_t.PS_DISTILL: + Console.WriteLine($"PS_DISTILL.outputfile:"); + Console.WriteLine($"{asyncInformation.Params.result.outputfile}"); + break; + + case GS_Task_t.SAVE_RESULT: + + break; + + case GS_Task_t.DISPLAY_DEV_THUMBS: + + break; + + case GS_Task_t.DISPLAY_DEV_RUN_FILE: + + break; + + case GS_Task_t.DISPLAY_DEV_PDF: + + break; + + case GS_Task_t.DISPLAY_DEV_NON_PDF: + + break; + + default: + + break; + } + + // task failed + if (asyncInformation.Params.result == GS_Result_t.gsFAILED) + { + switch (asyncInformation.Params.task) + { + case GS_Task_t.CREATE_XPS: + + break; + + case GS_Task_t.PS_DISTILL: + + break; + + case GS_Task_t.SAVE_RESULT: + + break; + + default: + + break; + } + return; + } + + // task cancelled + if (asyncInformation.Params.result == GS_Result_t.gsCANCELLED) + { + + } + } + else // task is still running + { + switch (asyncInformation.Params.task) + { + case GS_Task_t.CREATE_XPS: + + break; + + case GS_Task_t.PS_DISTILL: + + break; + + case GS_Task_t.SAVE_RESULT: + + break; + } + } +} + +private void gsIO(String message, int len) +{ + Console.WriteLine($"gsIO().message:{message}, length:{len}"); +} + +private void gsDLL(String message) +{ + Console.WriteLine($"gsDLL().message:{message}"); +} + +private void gsPageRendered(int width, + int height, + int raster, + IntPtr data, + gsParamState_t state) +{ + +}; +``` + +> **NOTE**<br> +> Once a Ghostscript operation is in progress any defined callback functions will be called as the operation runs up unto completion. These callback methods are essential for your application to interpret activity events and react accordingly. +> + +An explanation of callbacks and the available public methods within `GSNET` are explained below. + + +### Delegates + +To handle asynchronous events `GhostNET` has four delegates which define callback methods that an application can assign to. + + +| Callback | Description | +|---|---| +|`DLLProblemCallBack`|Occurs if there is some issue with the Ghostscript DLL| +|`StdIOCallBack`|Occurs if Ghostscript outputs something to `stderr` or `stdout`| +|`ProgressCallBack`|Occurs as Ghostscript makes its way through a file| +|`PageRenderedCallBack`|Occurs when a page has been rendered and the data from the display device is ready| + + +#### DLLProblemCallBack + +<div class="tag callbackDefinition csharp"></div> + +``` +internal delegate void DLLProblem(String mess); +internal event DLLProblem DLLProblemCallBack; +``` + +#### StdIOCallBack + +<div class="tag callbackDefinition csharp"></div> + +``` +internal delegate void StdIO(String mess, + int len); +internal event StdIO StdIOCallBack; +``` + +#### ProgressCallBack + +<div class="tag callbackDefinition csharp"></div> + +``` +internal delegate void Progress(gsEventArgs info); +internal event Progress ProgressCallBack; +``` + +#### PageRenderedCallBack + +<div class="tag callbackDefinition csharp"></div> + +``` +internal delegate void PageRendered(int width, + int height, + int raster, + IntPtr data, + gsParamState_t state); +internal event PageRendered PageRenderedCallBack; +``` + +### GetVersion + +Use this method to get Ghostscript version info as a handy `String`. + +<div class="tag methodDefinition csharp"></div> + +``` +public String GetVersion() +``` + +<div class="tag sampleCode csharp"></div> + +``` +String gs_vers = m_ghostscript.GetVersion(); +``` + +> **NOTE**<br> +> An exception will be thrown if there is any issue with the Ghostscript DLL. +> + + +### DisplayDeviceOpen + +Sets up the [display device] ahead of time. + + +<div class="tag methodDefinition csharp"></div> + +``` +public gsParamState_t DisplayDeviceOpen() +``` + +<div class="tag sampleCode csharp"></div> + +``` +m_ghostscript.DisplayDeviceOpen(); +``` + +> **NOTE**<br> +> Calling this method [instantiates ghostscript] and configures the encoding and the callbacks for the display device. +> + +### DisplayDeviceClose + +Closes the [display device] and deletes the instance. + +<div class="tag methodDefinition csharp"></div> + +``` +public gsParamState_t DisplayDeviceClose() +``` + +<div class="tag sampleCode csharp"></div> + +``` +m_ghostscript.DisplayDeviceClose(); +``` + +> **NOTE**<br> +> Calling this method [deletes ghostscript]. +> + +### GetPageCount + +Use this method to get the number of pages in a supplied document. + +<div class="tag methodDefinition csharp"></div> + +``` +public int GetPageCount(String fileName) +``` + + +<div class="tag sampleCode csharp"></div> + +``` +int page_number = m_ghostscript.GetPageCount("my_document.pdf"); +``` + +> **NOTE**<br> +> If Ghostscript is unable to determine the page count then this method will return `-1`. +> + + +### CreateXPS + +Launches a thread to create an XPS document for Windows printing. This method is [asynchronous] and logic should be hooked into your application upon [GSNET instantiation] to interpret progress. + + +<div class="tag methodDefinition csharp async"></div> + +``` +public gsStatus CreateXPS(String fileName, + int resolution, + int num_pages, + double width, + double height, + bool fit_page, + int firstpage, + int lastpage) +``` + +<div class="tag sampleCode csharp"></div> + +``` +m_ghostscript.CreateXPS("my_document.pdf", + 300, + 10, + 1000, + 1000, + true, + 0, + 9); +``` + +<span class="smallText alignRight"> + +_[asynchronous]_ + +</span> + +### DistillPS + +Launches a thread rendering all the pages of a supplied PostScript file to a PDF. + +<div class="tag methodDefinition csharp async"></div> + +``` +public gsStatus DistillPS(String fileName, int resolution) +``` + +<div class="tag sampleCode csharp"></div> + +``` +m_ghostscript.DistillPS("my_postscript_document.ps", 300); +``` + +<span class="smallText alignRight"> + +_[asynchronous]_ + +</span> + + +### DisplayDeviceRunFile + +Launches a thread to run a file with the [display device]. + + +<div class="tag methodDefinition csharp async"></div> + +``` +public gsStatus DisplayDeviceRunFile(String fileName, + double zoom, + bool aa, // anti-aliasing value + int firstpage, + int lastpage) +``` + + + +<div class="tag sampleCode csharp"></div> + +``` +m_ghostscript.DisplayDeviceRunFile("my_document.pdf", + 1.0, + true, + 0, + 9); +``` + +<span class="smallText alignRight"> + +_[asynchronous]_ + +</span> + +### DisplayDeviceRenderThumbs + +Launches a thread rendering all the pages with the [display device] to collect thumbnail images. + +Recommended zoom level for thumbnails is between 0.05 and 0.2, additionally anti-aliasing is probably not required. + +<div class="tag methodDefinition csharp async"></div> + +``` +public gsStatus DisplayDeviceRenderThumbs(String fileName, + double zoom, + bool aa) +``` + +<div class="tag sampleCode csharp"></div> + +``` +m_ghostscript.DisplayDeviceRenderThumbs("my_document.pdf", + 0.1, + false); +``` + +<span class="smallText alignRight"> + +_[asynchronous]_ + +</span> + +### DisplayDeviceRenderPages + +Launches a thread rendering a set of pages with the [display device]. For use with languages that can be indexed via pages which include PDF and XPS. <sup>[1]</sup> + +<div class="tag methodDefinition csharp async"></div> + +``` +public gsStatus DisplayDeviceRenderPages(String fileName, + int first_page, + int last_page, + double zoom) +``` + +<div class="tag sampleCode csharp"></div> + +``` +m_ghostscript.DisplayDeviceRenderPages("my_document.pdf", + 0, + 9, + 1.0); +``` + +<span class="smallText alignRight"> + +_[asynchronous]_ + +</span> + + + + +### GetStatus + +Returns the current [status] of `Ghostscript`. + +<div class="tag methodDefinition csharp"></div> + +``` +public gsStatus GetStatus() +``` + +<div class="tag sampleCode csharp"></div> + +``` +gsStatus status = m_ghostscript.GetStatus(); +``` + +### Cancel + +Cancels [asynchronous] operations. + +<div class="tag methodDefinition csharp"></div> + +``` +public void Cancel() +``` + +<div class="tag sampleCode csharp"></div> + +``` +m_ghostscript.Cancel(); +``` + +### GhostscriptException + +An application developer can log any exceptions in this public class as required by editing the constructor. + + +<div class="tag classDefinition csharp"></div> + +``` +public class GhostscriptException : Exception +{ + public GhostscriptException(string message) : base(message) + { + // Report exceptions as required + } +} +``` + +## Notes + +#### 1: Ghostscript & Page Description Languages + +Ghostscript handles the following [PDLs]: `PCL` `PDF` `PS` `XPS`. + +`PCL` and `PS` do not allow random access, meaning that, to print page 2 in a 100 page document, Ghostscript has to read the entire document stream of 100 pages. + +On the other hand, `PDF` and `XPS` allow for going directly to page 2 and then only dealing with that content. The tasks `DISPLAY_DEV_NON_PDF` and `DISPLAY_DEV_PDF` keep track of what sort of input Ghostscript is dealing with and enables the application to direct progress or completion callbacks accordingly. + + +[PDLs]: https://en.wikipedia.org/wiki/Page_description_language +[GhostAPI]: c-sharp-ghost-api.html +[EventArgs]: https://docs.microsoft.com/en-us/dotnet/api/system.eventargs?view=net-5.0 +[gsapi_revision]: c-sharp-ghost-api.html#gsapi_revision +[Ghostscript parameters]: https://www.ghostscript.com/doc/current/Use.htm#Parameters +[display device]: https://ghostscript.com/doc/current/Devices.htm#Display_devices +[instantiates ghostscript]: c-sharp-ghost-api.html#gsapi_new_instance +[deletes ghostscript]: c-sharp-ghost-api.html#gsapi_delete_instance +[status]: #status +[notes]: #notes +[1]: #1-ghostscript-page-description-languages + +[GSNET instantiation]: #gsnet +[asynchronous]: #delegates +[asynchronously]: #delegates diff --git a/doc/language-bindings/md/c-sharp-intro.md b/doc/language-bindings/md/c-sharp-intro.md new file mode 100644 index 00000000..87722021 --- /dev/null +++ b/doc/language-bindings/md/c-sharp-intro.md @@ -0,0 +1,120 @@ +# C# overview + +<div class="banner"> + <div class="c-sharp-text"></div> + <div class="vendor-logo c-sharp-logo"></div> +</div> + +## About + +In the [GhostPDL repository] a sample `C#` project can be found in `/demos/csharp`. + +Within this project the following namespaces and corresponding `C#` files are of relevance: + +- [GhostAPI] `ghostapi.cs` +- [GhostNET] `ghostnet.cs` +- [GhostMono] `ghostmono.cs` + +## Platform & setup + +### Building Ghostscript + +Ghostscript should be built as a shared library for your platform. + +See [Building Ghostscript]. + +## GhostAPI + +`GhostAPI` is the main wrapper responsible for bridging over to the `C` library and ensuring that the correct DLLs are imported. + +`GhostAPI` contains the `ghostapi` class which _does not_ need to be instantiated as it provides `public static` methods. These methods, which mirror their `C` counterparts, are as follows: + + +| Method | Description | +|---|---| +| [gsapi_revision] | Returns the revision numbers and strings of the Ghostscript interpreter library | +| [gsapi_new_instance] | Create a new instance of Ghostscript | +| [gsapi_delete_instance] | Destroy an instance of Ghostscript | +| [gsapi_set_stdio_with_handle] | Set the callback functions for `stdio`, together with the handle to use in the callback functions | +| [gsapi_set_stdio] | Set the callback functions for `stdio` | +| [gsapi_set_poll_with_handle] | Set the callback function for polling, together with the handle to pass to the callback function | +| [gsapi_set_poll] | Set the callback function for polling | +| [gsapi_set_display_callback] | _deprecated_ | +| [gsapi_register_callout] | This call registers a callout handler | +| [gsapi_deregister_callout] | This call deregisters a previously registered callout handler | +| [gsapi_set_arg_encoding] | Set the encoding used for the interpretation of all subsequent args supplied via the gsapi interface on this instance | +| [gsapi_set_default_device_list] | Set the string containing the list of default device names | +| [gsapi_get_default_device_list] | Returns a pointer to the current default device string | +| [gsapi_init_with_args] | Initialise the interpreter | +| [gsapi\_run\_\*][gsapi_run_wildcard] | Wildcard for various "run" methods | +| [gsapi_exit] | Exit the interpreter | +| [gsapi_set_param] | Set a parameter | +| [gsapi_get_param] | Get a parameter | +| [gsapi_enumerate_params] | Enumerate the current parameters | +| [gsapi_add_control_path] | Add a (case sensitive) path to one of the lists of permitted paths for file access | +| [gsapi_remove_control_path] | Remove a (case sensitive) path from one of the lists of permitted paths for file access | +| [gsapi_purge_control_paths] | Clear all the paths from one of the lists of permitted paths for file access | +| [gsapi_activate_path_control] | Enable/Disable path control | +| [gsapi_is_path_control_active] | Query whether path control is activated or not | + + + +## GhostNET + +`GhostNET` is the [.NET] interface into `GhostAPI`. It exemplifies how to do more complex operations involving multiple API calls and sequences. + + +### GhostNET WPF example + +In `demos/csharp/windows/ghostnet.sln` there is a sample C# demo project. + + +This project can be opened in [Visual Studio] and used to test the Ghostscript API alongside a UI which handles opening PostScript and PDF files. The sample application here allows for file browsing and Ghostscript file viewing. + +Below is a screenshot of the sample application with a PDF open: + +![ghostnet wpf example UI](images/ghostnet-wpf-example.png) + + + +## GhostMono + +`GhostMono` is the [Mono] equivalent of `GhostNET` and as such has no dependancy on a Windows environment. + + +[Visual Studio]: https://visualstudio.microsoft.com +[GhostPDL repository]: https://github.com/ArtifexSoftware/ghostpdl +[GhostAPI]: #ghostapi +[GhostNET]: #ghostnet +[GhostMono]: #ghostmono +[Mono]: https://www.mono-project.com/ +[.NET]: https://dotnet.microsoft.com/ +[Building Ghostscript]: index.html#building-ghostscript + +[gsapi_revision]: c-sharp-ghost-api#gsapi_revision +[gsapi_new_instance]: c-sharp-ghost-api#gsapi_new_instance +[gsapi_delete_instance]: c-sharp-ghost-api#gsapi_delete_instance +[gsapi_set_stdio_with_handle]: c-sharp-ghost-api#gsapi_set_stdio_with_handle +[gsapi_set_stdio]: c-sharp-ghost-api#gsapi_set_stdio +[gsapi_set_poll_with_handle]: c-sharp-ghost-api#gsapi_set_poll_with_handle +[gsapi_set_poll]: c-sharp-ghost-api#gsapi_set_poll +[gsapi_set_display_callback]: c-sharp-ghost-api#gsapi_set_display_callback +[gsapi_register_callout]: c-sharp-ghost-api#gsapi_register_callout +[gsapi_deregister_callout]: c-sharp-ghost-api#gsapi_deregister_callout +[gsapi_set_arg_encoding]: c-sharp-ghost-api#gsapi_set_arg_encoding +[gsapi_set_default_device_list]: c-sharp-ghost-api#gsapi_set_default_device_list +[gsapi_get_default_device_list]: c-sharp-ghost-api#gsapi_get_default_device_list +[gsapi_init_with_args]: c-sharp-ghost-api#gsapi_init_with_args +[gsapi_run_wildcard]: c-sharp-ghost-api#gsapi_run_wildcard +[gsapi_init_with_args]: c-sharp-ghost-api#gsapi_init_with_args +[gsapi_exit]: c-sharp-ghost-api#gsapi_exit +[gsapi_set_param]: c-sharp-ghost-api#gsapi_set_param +[gsapi_get_param]: c-sharp-ghost-api#gsapi_get_param +[gsapi_enumerate_params]: c-sharp-ghost-api#gsapi_enumerate_params +[gsapi_add_control_path]: c-sharp-ghost-api#gsapi_add_control_path +[gsapi_remove_control_path]: c-sharp-ghost-api#gsapi_remove_control_path +[gsapi_purge_control_paths]: c-sharp-ghost-api#gsapi_purge_control_paths +[gsapi_activate_path_control]: c-sharp-ghost-api#gsapi_activate_path_control +[gsapi_is_path_control_active]: c-sharp-ghost-api#gsapi_is_path_control_active +[gsapi_add_fs]: c-sharp-ghost-api#gsapi_add_fs +[gsapi_remove_fs]: c-sharp-ghost-api#gsapi_remove_fs diff --git a/doc/language-bindings/md/demo-code.md b/doc/language-bindings/md/demo-code.md new file mode 100644 index 00000000..cb8db2a6 --- /dev/null +++ b/doc/language-bindings/md/demo-code.md @@ -0,0 +1,17 @@ +# Demo code + +<div class="banner intro"> + <div class="default-text"></div> + <div class="vendor-logo gs-logo"></div> + <div class="vendor-logo c-sharp-logo"></div> + <div class="vendor-logo java-logo"></div> + <div class="vendor-logo python-logo"></div> +</div> + +## About + +Please locate the `demos` folder in your `ghostpdl` source code download from the [GhostPDL repository] to find sample code demonstrating the language bindings in action. + + +[Ghostscript releases]: https://ghostscript.com/download/gpdldnld.html +[GhostPDL repository]: https://github.com/ArtifexSoftware/ghostpdl diff --git a/doc/language-bindings/md/images/export-jar.png b/doc/language-bindings/md/images/export-jar.png Binary files differnew file mode 100644 index 00000000..9922043a --- /dev/null +++ b/doc/language-bindings/md/images/export-jar.png diff --git a/doc/language-bindings/md/images/ghostnet-wpf-example.png b/doc/language-bindings/md/images/ghostnet-wpf-example.png Binary files differnew file mode 100644 index 00000000..df94b86c --- /dev/null +++ b/doc/language-bindings/md/images/ghostnet-wpf-example.png diff --git a/doc/language-bindings/md/images/gsviewer.png b/doc/language-bindings/md/images/gsviewer.png Binary files differnew file mode 100644 index 00000000..52e0f19a --- /dev/null +++ b/doc/language-bindings/md/images/gsviewer.png diff --git a/doc/language-bindings/md/images/linking-jar.png b/doc/language-bindings/md/images/linking-jar.png Binary files differnew file mode 100644 index 00000000..a91da771 --- /dev/null +++ b/doc/language-bindings/md/images/linking-jar.png diff --git a/doc/language-bindings/md/introduction.md b/doc/language-bindings/md/introduction.md new file mode 100755 index 00000000..33b6856d --- /dev/null +++ b/doc/language-bindings/md/introduction.md @@ -0,0 +1,113 @@ +# Introduction + +<div class="banner intro"> + <div class="default-text"></div> + <div class="vendor-logo gs-logo"></div> + <div class="vendor-logo c-sharp-logo"></div> + <div class="vendor-logo java-logo"></div> + <div class="vendor-logo python-logo"></div> +</div> + +## About our APIs + +The core of Ghostscript is written in `C`, but also supports [language bindings] for the following programming languages: + +* `C#` +* `Java` +* `Python` + +All of the above languages have equivalent methods as defined in the [C API]. `Java` and `C#` provide additional helper methods to make the use of the API easier for certain applications. These languages also provide example viewers that make use of these methods. + +This developer documentation is organized by programming language type and includes API reference and sample code. + +## The C API + +<div class="vendor-logo c-logo"></div> +<p/> + +Ghostscript has been in development for over thirty years and is written in `C`. The API has evolved over time and is continually being developed. The language bindings into Ghostscript will attempt to mirror this evolution and match the current [C API] as much as possible. + +## Licensing + +Before using Ghostscript, please make sure that you have a valid license to do so. There are two available licenses; make sure you pick the one whose terms you can comply with. + +### Open Source license + +If your software is open source, you may use Ghostscript under the terms of the GNU Affero General Public License. + +This means that all of the source code for your complete app must be released under a compatible open source license! + +It also means that you may not use any proprietary closed source libraries or components in your app. + +Please read the full text of the AGPL license agreement from the [FSF web site] + +If you cannot or do not want to comply with these restrictions, you must acquire a commercial license instead. + +<button class="cta orange"><a href="https://artifex.com/licensing/" target="new">FIND OUT MORE</a></button> + +### Commercial license + +If your project does not meet the requirements of the AGPL, please contact our sales team to discuss a commercial license. Each Artifex commercial license is crafted based on your individual use case. + +<button class="cta orange"><a href="https://artifex.com/contact/" target="new">CONTACT US</a></button> + + +## Building Ghostscript + +In order to use Ghostscript language bindings firstly Ghostscript must be built as a shared library for your platform. + +The following built libraries are required for these respective platforms: + +| Platform | Ghostscript library files | +|---|---| +|Windows 32-bit|`gpdldll32.dll` `gsdll32.dll`| +|Windows 64-bit|`gpdldll64.dll` `gsdll64.dll`| +|MacOS|`libgpdl.dylib` `libgs.dylib`| +|Linux / OpenBSD|`libgpdl.so` `libgs.so`| + + +> **NOTE**<br> +> The actual filenames on MacOS will be appended with the version of Ghostscript with associated symlinks. + +### Building on Windows + +To build the required DLLs, load `/windows/ghostpdl.sln` into Visual Studio, and select the required architecture from the drop down - then right click on 'ghostpdl' in the solution explorer and choose "Build". + + +### Building on MacOS or Linux / OpenBSD + +Firstly run the `autogen.sh` script from the command line to create the required configuration files followed by `make so` to build the shared libraries. The scripts also depend on having both `autoconf` and `automake` installed on your system. <sup>[1]</sup> + +#### autoconf & automake + +If this software is not already on your system (usually this can be found in the following location: `usr/local/bin`, but it could be located elsewhere depending on your setup) then it can be installed from your OS's package system. + + +Alternatively, it can be installed from [GNU] here: + +https://www.gnu.org/software/autoconf/ + +https://www.gnu.org/software/automake/ + +Or, it can be installed via [Brew] by running: + +``` +brew install autoconf automake +``` + +Once built, these libraries can be found in your `ghostpdl/sobin/` or `ghostpdl/sodebugbin` location depending on your build command. + + + +> **NOTE**<br> +> For full detailed instructions on how to build your Ghostscript library see [here]. +> + +[Python]: https://www.python.org/ +[Brew]: https://brew.sh/ +[GNU]: https://www.gnu.org/ + +[C API]: https://www.ghostscript.com/doc/current/API.htm +[FSF web site]: https://www.gnu.org/licenses/agpl-3.0.html +[here]: https://ghostscript.com/doc/current/Make.htm +[language bindings]: https://en.wikipedia.org/wiki/Language_binding diff --git a/doc/language-bindings/md/java-gsjavajar.md b/doc/language-bindings/md/java-gsjavajar.md new file mode 100644 index 00000000..650bb11f --- /dev/null +++ b/doc/language-bindings/md/java-gsjavajar.md @@ -0,0 +1,1179 @@ +# gsjava.jar + +<div class="banner"> +<div class="java-text"></div> +<div class="vendor-logo java-logo"></div> +</div> + + +## About + +`gsjava.jar` is the Java library which contains classes and interfaces which enable API calls required to use Ghostscript. + +Assuming that the JAR for your project has been [built] and [properly linked] with your own project then the Ghostscript API should be available by importing the required classes within your project's `.java` files. + + +### GSAPI & GSInstance + +- [GSAPI] is the main Ghostscript API class which bridges into the Ghostscript C library. +- [GSInstance] is a wrapper class for [GSAPI] which encapsulates an instance of Ghostscript and allows for simpler API calls. + + +<div class="tag sampleCode java"></div> + + +``` +// to use GSAPI +import static com.artifex.gsjava.GSAPI.*; + +// to use GSInstance +import com.artifex.gsjava.GSInstance; +``` + + +## GSAPI + + +### gsapi_revision + +This method returns the revision numbers and strings of the Ghostscript interpreter library; you should call it before any other interpreter library functions to make sure that the correct version of the Ghostscript interpreter has been loaded. + + +<div class="tag methodDefinition java"></div> + +``` +public static native int gsapi_revision(GSAPI.Revision revision, + int len); +``` + + +> **NOTE**<br> +> The method should write to a reference variable which conforms to the class [GSAPI.Revision]. +> + + +#### GSAPI.Revision + +This class is used to store information about Ghostscript and provides handy getters for the product and the copyright information. + + +<div class="tag classDefinition java"></div> + +``` +public static class Revision { + public volatile byte[] product; + public volatile byte[] copyright; + public volatile long revision; + public volatile long revisionDate; + + public Revision() { + this.product = null; + this.copyright = null; + this.revision = 0L; + this.revisionDate = 0L; + } + + /** + * Returns the product information as a String. + * + * @return The product information. + */ + public String getProduct() { + return new String(product); + } + + /** + * Returns the copyright information as a String. + * + * @return The copyright information. + */ + public String getCopyright() { + return new String(copyright); + } +} +``` + + +### gsapi_new_instance + +Creates a new instance of Ghostscript. This instance is passed to most other [GSAPI] methods. Unless Ghostscript has been compiled with the `GS_THREADSAFE` define, only one instance at a time is supported. + +<div class="tag methodDefinition java"></div> + +``` +public static native int gsapi_new_instance(Reference<Long> instance, + long callerHandle); +``` + + + +> **NOTE**<br> +> The method returns a reference which represents your instance of Ghostscript. +> + + +### gsapi_delete_instance + +Destroy an instance of Ghostscript. Before you call this, Ghostscript must have finished. If Ghostscript has been initialised, you should call [gsapi_exit] beforehand. + +<div class="tag methodDefinition java"></div> + +``` +public static native void gsapi_delete_instance(long instance); +``` + + +### gsapi_set_stdio_with_handle + +Set the callback functions for `stdio`, together with the handle to use in the callback functions. The `stdin` callback function should return the number of characters read, 0 for EOF, or -1 for error. The `stdout` and `stderr` callback functions should return the number of characters written. + +<div class="tag methodDefinition java"></div> + +``` +public static native int gsapi_set_stdio_with_handle(long instance, + IStdInFunction stdin, + IStdOutFunction stdout, + IStdErrFunction stderr, + long callerHandle); +``` + + +### gsapi_set_stdio + +Set the callback functions for `stdio`. The handle used in the callbacks will be taken from the value passed to [gsapi_new_instance]. Otherwise the behaviour of this function matches [gsapi_set_stdio_with_handle]. + +<div class="tag methodDefinition java"></div> + +``` +public static native int gsapi_set_stdio(long instance, + IStdInFunction stdin, + IStdOutFunction stdout, + IStdErrFunction stderr); +``` + + +### gsapi_set_poll_with_handle + +Set the callback function for polling, together with the handle to pass to the callback function. This function will only be called if the Ghostscript interpreter was compiled with `CHECK_INTERRUPTS` as described in `gpcheck.h`. + +The polling function should return zero if all is well, and return negative if it wants ghostscript to abort. This is often used for checking for a user cancel. This can also be used for handling window events or cooperative multitasking. + +The polling function is called very frequently during interpretation and rendering so it must be fast. If the function is slow, then using a counter to `return 0` immediately some number of times can be used to reduce the performance impact. + + +<div class="tag methodDefinition java"></div> + +``` +public static native int gsapi_set_poll_with_handle(long instance, + IPollFunction pollfun, + long callerHandle); +``` + +### gsapi_set_poll + +Set the callback function for polling. The handle passed to the callback function will be taken from the handle passed to [gsapi_new_instance]. Otherwise the behaviour of this function matches [gsapi_set_poll_with_handle]. + +<div class="tag methodDefinition java"></div> + +``` +public static native int gsapi_set_poll(long instance, + IPollFunction pollfun); +``` + +### gsapi_set_display_callback + +This call is deprecated; please use [gsapi_register_callout] to register a [callout handler] for the display device in preference. + +<div class="tag methodDefinition java"></div> + +``` +public static native int gsapi_set_display_callback(long instance, + DisplayCallback displayCallback); +``` + + +### gsapi_register_callout + +This call registers a [callout handler]. + +<div class="tag methodDefinition java"></div> + +``` +public static native int gsapi_register_callout(long instance, + ICalloutFunction callout, + long calloutHandle); +``` + + +### gsapi_deregister_callout + + +This call deregisters a [callout handler] previously registered with [gsapi_register_callout]. All three arguments must match exactly for the [callout handler] to be deregistered. + + +<div class="tag methodDefinition java"></div> + +``` +public static native void gsapi_deregister_callout(long instance, + ICalloutFunction callout, + long calloutHandle); +``` + +### gsapi_set_arg_encoding + +Set the encoding used for the interpretation of all subsequent arguments supplied via the `GSAPI` interface on this instance. By default we expect args to be in encoding `0` (the 'local' encoding for this OS). On Windows this means "the currently selected codepage". This means that omitting to call this function will leave Ghostscript running exactly as it always has. Please note that use of the 'local' encoding is now deprecated and should be avoided in new code. This must be called after [gsapi_new_instance] and before [gsapi_init_with_args]. + +<div class="tag methodDefinition java"></div> + +``` +public static native int gsapi_set_arg_encoding(long instance, + int encoding); +``` + +### gsapi_set_default_device_list + +Set the string containing the list of default device names, for example "display x11alpha x11 bbox". Allows the calling application to influence which device(s) Ghostscript will try, in order, in its selection of the default device. This must be called after [gsapi_new_instance] and before [gsapi_init_with_args]. + +<div class="tag methodDefinition java"></div> + +``` +public static native int gsapi_set_default_device_list(long instance, + byte[] list, + int listlen); +``` + +### gsapi_get_default_device_list + +Returns a pointer to the current default device string. This must be called after [gsapi_new_instance] and before [gsapi_init_with_args]. + +<div class="tag methodDefinition java"></div> + +``` +public static native int gsapi_get_default_device_list(long instance, + Reference<byte[]> list, + Reference<Integer> listlen); +``` + +### gsapi_init_with_args + +To initialise the interpreter, pass your `instance` of Ghostscript, your argument count: `argc`, and your argument variables: `argv`. + +<div class="tag methodDefinition java"></div> + +``` +public static native int gsapi_init_with_args(long instance, + int argc, + byte[][] argv); +``` + + +> **NOTE**<br> +> There are also simpler utility methods which eliminates the need to send through your argument count and allows for simpler `String` passing for your argument array. +> + +Utility methods: + +<div class="tag methodDefinition java"></div> + +``` +public static int gsapi_init_with_args(long instance, + String[] argv); +``` + +``` +public static int gsapi_init_with_args(long instance, + List<String> argv); +``` + +### gsapi\_run\_\* + +If these functions return `<= -100`, either quit or a fatal error has occured. You must call [gsapi_exit] next. The only exception is [gsapi_run_string_continue] which will return `gs_error_NeedInput` if all is well. + +There is a 64 KB length limit on any buffer submitted to a `gsapi_run_*` function for processing. If you have more than 65535 bytes of input then you must split it into smaller pieces and submit each in a separate [gsapi_run_string_continue] call. + +### gsapi_run_string_begin + +<div class="tag methodDefinition java"></div> + +``` +public static native int gsapi_run_string_begin(long instance, + int userErrors, + Reference<Integer> pExitCode); +``` + + + +### gsapi_run_string_continue + +<div class="tag methodDefinition java"></div> + +``` +public static native int gsapi_run_string_continue(long instance, + byte[] str, + int length, + int userErrors, + Reference<Integer> pExitCode); +``` + + +> **NOTE**<br> +> There is a simpler utility method which allows for simpler `String` passing for the `str` argument. +> + + +Utility method: + +<div class="tag methodDefinition java"></div> + +``` +public static int gsapi_run_string_continue(long instance, + String str, + int length, + int userErrors, + Reference<Integer> pExitCode); +``` + + +### gsapi_run_string_with_length + +<div class="tag methodDefinition java"></div> + +``` +public static native int gsapi_run_string_with_length(long instance, + byte[] str, + int length, + int userErrors, + Reference<Integer> pExitCode); +``` + + +> **NOTE**<br> +> There is a simpler utility method which allows for simpler `String` passing for the `str` argument. +> + + +Utility method: + + +<div class="tag methodDefinition java"></div> + +``` +public static int gsapi_run_string_with_length(long instance, + String str, + int length, + int userErrors, + Reference<Integer> pExitCode); +``` + + +### gsapi_run_string + + +<div class="tag methodDefinition java"></div> + +``` +public static native int gsapi_run_string(long instance, + byte[] str, + int userErrors, + Reference<Integer> pExitCode); +``` + + + + +> **NOTE**<br> +> There is a simpler utility method which allows for simpler `String` passing for the `str` argument. +> + + +Utility method: + + +<div class="tag methodDefinition java"></div> + +``` +public static int gsapi_run_string(long instance, + String str, + int userErrors, + Reference<Integer> pExitCode); +``` + + + +### gsapi_run_string_end + +<div class="tag methodDefinition java"></div> + +``` +public static native int gsapi_run_string_end(long instance, + int userErrors, + Reference<Integer> pExitCode); +``` + +### gsapi_run_file + +<div class="tag methodDefinition java"></div> + +``` +public static native int gsapi_run_file(long instance, + byte[] fileName, + int userErrors, + Reference<Integer> pExitCode); +``` + + + +> **NOTE**<br> +> There is a simpler utility method which allows for simpler `String` passing for the `fileName` argument. +> + + +Utility method: + + +<div class="tag methodDefinition java"></div> + +``` +public static int gsapi_run_file(long instance, + String fileName, + int userErrors, + Reference<Integer> pExitCode); +``` + + + + +### 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]. + +<div class="tag methodDefinition java"></div> + +``` +public static native int gsapi_exit(long instance); +``` + + + +### gsapi_set_param + +Sets a parameter. Broadly, this is equivalent to setting a parameter using -d, -s or -p on the command line. This call cannot be made during a [gsapi_run_string] operation. + +Parameters in this context are not the same as 'arguments' as processed by [gsapi_init_with_args], but often the same thing can be achieved. For example, with [gsapi_init_with_args], we can pass "-r200" to change the resolution. Broadly the same thing can be achieved by using [gsapi_set_param] to set a parsed value of "<</HWResolution [ 200.0 200.0 ]>>". + +Internally, when we set a parameter, we perform an `initgraphics` operation. This means that using [gsapi_set_param] other than at the start of a page is likely to give unexpected results. + +Attempting to set a parameter that the device does not recognise will be silently ignored, and that parameter will not be found in subsequent [gsapi_get_param] calls. + + +<div class="tag methodDefinition java"></div> + +``` +public static native int gsapi_set_param(long instance, + byte[] param, + Object value, + int paramType); +``` + +> **NOTE**<br> +> The `type` argument, as a [gs_set_param_type], dictates the kind of object that the `value` argument points to. +> + +> **NOTE**<br> +> For more on the C implementation of parameters see: [Ghostscript parameters in C]. +> + +> **NOTE**<br> +> There are also simpler utility methods which allows for simpler `String` passing for your arguments. +> + + +Utility methods: + +<div class="tag methodDefinition java"></div> + +``` +public static int gsapi_set_param(long instance, + String param, + String value, + int paramType); +``` + +``` +public static int gsapi_set_param(long instance, + String param, + Object value, + int paramType); +``` + + +### gsapi_get_param + +Retrieve the current value of a parameter. + +If an error occurs, the return value is negative. Otherwise the return value is the number of bytes required for storage of the value. Call once with value `NULL` to get the number of bytes required, then call again with value pointing to at least the required number of bytes where the value will be copied out. Note that the caller is required to know the type of value in order to get it. For all types other than [gs_spt_string], [gs_spt_name], and [gs_spt_parsed] knowing the type means you already know the size required. + +This call retrieves parameters/values that have made it to the device. Thus, any values set using [gs_spt_more_to_come] without a following call omitting that flag will not be retrieved. Similarly, attempting to get a parameter before [gsapi_init_with_args] has been called will not list any, even if [gsapi_set_param] has been used. + +Attempting to read a parameter that is not set will return `gs_error_undefined` (-21). Note that calling [gsapi_set_param] followed by [gsapi_get_param] may not find the value, if the device did not recognise the key as being one of its configuration keys. + +For the C documentation please refer to [Ghostscript get_param]. + + +<div class="tag methodDefinition java"></div> + +``` +public static native int gsapi_get_param(long instance, + byte[] param, + long value, + int paramType); +``` + + + +> **NOTE**<br> +> There is a simpler utility method which allows for simpler `String` passing for the `param` argument. +> + + +Utility method: + + +<div class="tag methodDefinition java"></div> + +``` +public static int gsapi_get_param(long instance, + String param, + long value, + int paramType); +``` + + + +### gsapi_enumerate_params + +Enumerate the current parameters. Call repeatedly to list out the current parameters. + +The first call should have `iter` = NULL. Subsequent calls should pass the same pointer in so the iterator can be updated. Negative return codes indicate error, 0 success, and 1 indicates that there are no more keys to read. On success, key will be updated to point to a null terminated string with the key name that is guaranteed to be valid until the next call to [gsapi_enumerate_params]. If `type` is non NULL then the pointer `type` will be updated to have the `type` of the parameter. + + +> **NOTE**<br> +> Only one enumeration can happen at a time. Starting a second enumeration will reset the first. +> + +The enumeration only returns parameters/values that have made it to the device. Thus, any values set using the [gs_spt_more_to_come] without a following call omitting that flag will not be retrieved. Similarly, attempting to enumerate parameters before [gsapi_init_with_args] has been called will not list any, even if [gsapi_set_param] has been used. + +<div class="tag methodDefinition java"></div> + +``` +public static native int gsapi_enumerate_params(long instance, + Reference<Long> iter, + Reference<byte[]> key, + Reference<Integer> paramType); +``` + + +### gsapi_add_control_path + +Add a (case sensitive) path to one of the lists of [permitted paths] for file access. + +<div class="tag methodDefinition java"></div> + +``` +public static native int gsapi_add_control_path(long instance, + int type, + byte[] path); +``` + +> **NOTE**<br> +> There is a simpler utility method which allows for simpler `String` passing for the `path` argument. +> + +Utility method: + + +<div class="tag methodDefinition java"></div> + +``` +public static int gsapi_add_control_path(long instance, + int type, + String path); +``` + +### gsapi_remove_control_path + +Remove a (case sensitive) path from one of the lists of [permitted paths] for file access. + +<div class="tag methodDefinition java"></div> + +``` +public static native int gsapi_remove_control_path(long instance, + int type, + byte[] path); +``` + +> **NOTE**<br> +> There is a simpler utility method which allows for simpler `String` passing for the `path` argument. +> + +Utility method: + + +<div class="tag methodDefinition java"></div> + +``` +public static int gsapi_remove_control_path(long instance, + int type, + String path); +``` + + +### gsapi_purge_control_paths + +Clear all the paths from one of the lists of [permitted paths] for file access. +<div class="tag methodDefinition java"></div> + +``` +public static native void gsapi_purge_control_paths(long instance, + int type); +``` + + +### gsapi_activate_path_control + +Enable/Disable path control (i.e. whether paths are checked against [permitted paths] before access is granted). + +<div class="tag methodDefinition java"></div> + +``` +public static native void gsapi_activate_path_control(long instance, + boolean enable); +``` + + +### gsapi_is_path_control_active + + +Query whether path control is activated or not. + +<div class="tag methodDefinition java"></div> + + +``` +public static native boolean gsapi_is_path_control_active(long instance); +``` + + + + +## Callback & Callout interfaces + +`gsjava.jar` also defines some functional interfaces for callbacks & callouts with `package com.artifex.gsjava.callback` which are defined as follows. + +### IStdInFunction + +<div class="tag functionalInterface java"></div> + +``` +public interface IStdInFunction { + /** + * @param callerHandle The caller handle. + * @param buf A string represented by a byte array. + * @param len The number of bytes to read. + * @return The number of bytes read, must be <code>len</code>/ + */ + public int onStdIn(long callerHandle, + byte[] buf, + int len); +} +``` + + +### IStdOutFunction + +<div class="tag functionalInterface java"></div> + +``` +public interface IStdOutFunction { + /** + * Called when something should be written to the standard + * output stream. + * + * @param callerHandle The caller handle. + * @param str The string represented by a byte array to write. + * @param len The number of bytes to write. + * @return The number of bytes written, must be <code>len</code>. + */ + public int onStdOut(long callerHandle, + byte[] str, + int len); +} +``` + + +### IStdErrFunction + +<div class="tag functionalInterface java"></div> + +``` +public interface IStdErrFunction { + /** + * Called when something should be written to the standard error stream. + * + * @param callerHandle The caller handle. + * @param str The string represented by a byte array to write. + * @param len The length of bytes to be written. + * @return The amount of bytes written, must be <code>len</code>. + */ + public int onStdErr(long callerHandle, + byte[] str, + int len); +} +``` + + +### IPollFunction + +<div class="tag functionalInterface java"></div> + +``` +public interface IPollFunction { + public int onPoll(long callerHandle); +} +``` + + +### ICalloutFunction + +<div class="tag functionalInterface java"></div> + +``` +public interface ICalloutFunction { + public int onCallout(long instance, + long calloutHandle, + byte[] deviceName, + int id, + int size, + long data); +} +``` + + +## GSInstance + +This is a utility class which makes Ghostscript calls easier by storing a Ghostscript instance and, optionally, a caller handle. Essentially the class acts as a handy wrapper for the standard [GSAPI] methods. + + +### Constructors + +<div class="tag methodDefinition java"></div> + +``` +public GSInstance() throws IllegalStateException; +``` + +``` +public GSInstance(long callerHandle) throws IllegalStateException; +``` + +### delete_instance + +Wraps [gsapi_delete_instance]. + +<div class="tag methodDefinition java"></div> + +``` +public void delete_instance(); +``` + +### set_stdio + + +Wraps [gsapi_set_stdio]. + +<div class="tag methodDefinition java"></div> + +``` +public int set_stdio(IStdInFunction stdin, + IStdOutFunction stdout, + IStdErrFunction stderr); +``` + +### set_poll + +Wraps [gsapi_set_poll]. + +<div class="tag methodDefinition java"></div> + +``` +public int set_poll(IPollFunction pollfun); +``` + +### set_display_callback + +Wraps [gsapi_set_display_callback]. + +<div class="tag methodDefinition java"></div> + +``` +public int set_display_callback(DisplayCallback displaycallback); +``` + +### register_callout + +Wraps [gsapi_register_callout]. + +<div class="tag methodDefinition java"></div> + +``` +public int register_callout(ICalloutFunction callout); +``` + + +### deregister_callout + +Wraps [gsapi_deregister_callout]. + +<div class="tag methodDefinition java"></div> + +``` +public void deregister_callout(ICalloutFunction callout); +``` + + +### set_arg_encoding + +Wraps [gsapi_set_arg_encoding]. + +<div class="tag methodDefinition java"></div> + +``` +public int set_arg_encoding(int encoding); +``` + + +### set_default_device_list + +Wraps [gsapi_set_default_device_list]. + +<div class="tag methodDefinition java"></div> + +``` +public int set_default_device_list(byte[] list, + int listlen); +``` + +### get_default_device_list + +Wraps [gsapi_get_default_device_list]. + +<div class="tag methodDefinition java"></div> + +``` +public int get_default_device_list(Reference<byte[]> list, + Reference<Integer> listlen); +``` + + +### init_with_args + +Wraps [gsapi_init_with_args]. + +<div class="tag methodDefinition java"></div> + +``` +public int init_with_args(int argc, + byte[][] argv); +``` + +``` +public int init_with_args(String[] argv); +``` + +``` +public int init_with_args(List<String> argv); +``` + + +### run_string_begin + +Wraps [gsapi_run_string_begin]. + +<div class="tag methodDefinition java"></div> + +``` +public int run_string_begin(int userErrors, + Reference<Integer> pExitCode); +``` + + +### run_string_continue + +Wraps [gsapi_run_string_continue]. + +<div class="tag methodDefinition java"></div> + +``` +public int run_string_continue(byte[] str, + int length, + int userErrors, + Reference<Integer> pExitCode); +``` + +``` +public int run_string_continue(String str, + int length, + int userErrors, + Reference<Integer> pExitCode); +``` + +### run_string + +Wraps [gsapi_run_string]. + +<div class="tag methodDefinition java"></div> + +``` +public int run_string(byte[] str, + int userErrors, + Reference<Integer> pExitCode); +``` + +``` +public int run_string(String str, + int userErrors, + Reference<Integer> pExitCode); +``` + + +### run_file + +Wraps [gsapi_run_file]. + +<div class="tag methodDefinition java"></div> + +``` +public int run_file(byte[] fileName, + int userErrors, + Reference<Integer> pExitCode); +``` + +``` +public int run_file(String filename, + int userErrors, + Reference<Integer> pExitCode); +``` + +### exit + +Wraps [gsapi_exit]. + +<div class="tag methodDefinition java"></div> + +``` +public int exit(); +``` + + +### set_param + +Wraps [gsapi_set_param]. + +<div class="tag methodDefinition java"></div> + +``` +public int set_param(byte[] param, + Object value, + int paramType); +``` + +``` +public int set_param(String param, + String value, + int paramType); +``` + +``` +public int set_param(String param, + Object value, + int paramType); +``` + + +### get_param + +Wraps [gsapi_get_param]. + +<div class="tag methodDefinition java"></div> + +``` +public int get_param(byte[] param, + long value, + int paramType); +``` + +``` +public int get_param(String param, + long value, + int paramType); +``` + +### enumerate_params + +Wraps [gsapi_enumerate_params]. + +<div class="tag methodDefinition java"></div> + +``` +public int enumerate_params(Reference<Long> iter, + Reference<byte[]> key, + Reference<Integer> paramType); +``` + + +### add_control_path + +Wraps [gsapi_add_control_path]. + +<div class="tag methodDefinition java"></div> + +``` +public int add_control_path(int type, + byte[] path); +``` + +``` +public int add_control_path(int type, + String path); +``` + +### remove_control_path + +Wraps [gsapi_remove_control_path]. + +<div class="tag methodDefinition java"></div> + +``` +public int remove_control_path(int type, + byte[] path); +``` + +``` +public int remove_control_path(int type, + String path); +``` + + +### purge_control_paths + +Wraps [gsapi_purge_control_paths]. + +<div class="tag methodDefinition java"></div> + +``` +public void purge_control_paths(int type); +``` + + +### activate_path_control + +Wraps [gsapi_activate_path_control]. + +<div class="tag methodDefinition java"></div> + +``` +public void activate_path_control(boolean enable); +``` + + +### is_path_control_active + +Wraps [gsapi_is_path_control_active]. + +<div class="tag methodDefinition java"></div> + +``` +public boolean is_path_control_active(); +``` + +## Utility classes + +The com.artifex.gsjava.util package contains a set of classes and interfaces which are used throughout the API. + +### com.artifex.gsjava.util.Reference + +`Reference<T>` is used in many of the Ghostscript calls, it stores a reference to a generic value of type `T`. This class exists to emulate pointers being passed to a native function. Its value can be fetched with `getValue()` and set with `setValue(T value)`. + +<div class="tag classDefinition java"></div> + +``` +public class Reference<T> { + + private volatile T value; + + public Reference() { + this(null); + } + + public Reference(T value) { + this.value = value; + } + + public void setValue(T value) { + this.value = value; + } + + public T getValue() { + return value; + } + ... +} +``` + +[Ghostscript parameters in C]: https://www.ghostscript.com/doc/current/Use.htm#Parameters +[Ghostscript get_param]: https://www.ghostscript.com/doc/current/API.htm#get_param +[permitted paths]: https://ghostscript.com/doc/current/Use.htm#Safer + +[GSAPI]: #gsapi +[GSInstance]: #gsinstance +[built]: java-intro.html#building-the-jar +[properly linked]: java-intro.html#linking-the-jar +[GSAPI.Revision]: #gsapi-revision + + +[gsapi_set_stdio]: #gsapi_set_stdio +[gsapi_set_poll]: #gsapi_set_poll +[gsapi_set_display_callback]: #gsapi_set_display_callback +[gsapi_deregister_callout]: #gsapi_deregister_callout +[gsapi_run_string_begin]: #gsapi_run_string_begin +[gsapi_run_file]: #gsapi_run_file +[gsapi_add_control_path]: #gsapi_add_control_path +[gsapi_remove_control_path]: #gsapi_remove_control_path +[gsapi_purge_control_paths]: #gsapi_purge_control_paths +[gsapi_activate_path_control]: #gsapi_activate_path_control +[gsapi_is_path_control_active]: #gsapi_is_path_control_active +[gsapi_revision]: #gsapi_revision +[gsapi_exit]: #gsapi_exit +[gsapi_new_instance]: #gsapi_new_instance +[gsapi_set_stdio_with_handle]: #gsapi_set_stdio_with_handle +[gsapi_set_poll_with_handle]: #gsapi_set_poll_with_handle +[gsapi_register_callout]: #gsapi_register_callout +[gsapi_init_with_args]: #gsapi_init_with_args +[gsapi_delete_instance]: #gsapi_delete_instance +[gsapi_exit]: #gsapi_exit +[gsapi_run_string]: #gsapi_run_string +[gsapi_run_string_continue]: #gsapi_run_string_continue +[gs_set_param_type]: #gs_set_param_type +[gs_spt_more_to_come]: #gs_set_param_type +[gs_spt_string]: #gs_set_param_type +[gs_spt_name]: #gs_set_param_type +[gs_spt_parsed]: #gs_set_param_type +[gsapi_set_param]: #gsapi_set_param +[gsapi_get_param]: #gsapi_get_param +[gsapi_enumerate_params]: #gsapi_enumerate_params +[gsapi_set_arg_encoding]: #gsapi_set_arg_encoding +[gsapi_set_default_device_list]: #gsapi_set_default_device_list +[gsapi_get_default_device_list]: #gsapi_get_default_device_list + + +[callout handler]: #callback-callout-interfaces diff --git a/doc/language-bindings/md/java-intro.md b/doc/language-bindings/md/java-intro.md new file mode 100644 index 00000000..fe6422fa --- /dev/null +++ b/doc/language-bindings/md/java-intro.md @@ -0,0 +1,221 @@ +# Java overview + +<div class="banner"> +<div class="java-text"></div> +<div class="vendor-logo java-logo"></div> +</div> + +## About + + +In the [GhostPDL repository] sample `Java` projects can be found in `/demos/java`. + +Within this location the following folders are of relevance: + +- [jni] `jni` +- [gsjava] `gsjava` +- [gstest] `gstest` +- [gsviewer] `gsviewer` + + +## Platform & setup + + +### Building Ghostscript + +Ghostscript should be built as a shared library for your platform. + +See [Building Ghostscript]. + +### jni: Building the Java Native Interface + +Before building the JNI ensure that Ghostscript has already been built for your platform and that you have JDK installed. + +The JNI is for use in the Java interface, +this object must be placed somewhere on your Java PATH. On Windows, the DLL +can be placed in the working directory, next to `gsjava.jar`. + +| Platform | JNI file | +|---|---| +|Windows|`gs_jni.dll`| +|MacOS|`gs_jni.dylib`| +|Linux / OpenBSD|`gs_jni.so`| + + +#### Preparing your include folder + +The build scripts require the header `jni.h`, which defines +all JNI functions, and `jni_md.h`, which defines all system-specific +integer types. The build scripts expect an include folder relative to their location which contain these header files from your system. + +These headers are typically found in the following directories: + + +| Platform | jni.h | jni_md.h | +|---|---|---| +|Windows|`C:\Program Files\Java\<JDK Install>\include\jni.h`|`C:\Program Files\Java\<JDK Install>\include\win32\jni_md.h`| +|MacOS|`/Library/Java/JavaVirtualMachines/<JDK Install>/Contents/Home/include/jni.h`|`/Library/Java/JavaVirtualMachines/<JDK Install>/Contents/Home/include/darwin/jni_md.h`| +|Linux|`/lib/jvm/<JDK Install>/include/jni.h`|`/lib/jvm/<JDK Install>/include/linux/jni_md.h`| + + +Once your `include` folder has been located folder you can copy it and place it in your `ghostpdl/demos/java/jni/gs_jni` folder. + +Your build scripts should now be ready to run as they will be able to find the required JNI header files in their own relative include folder. + + +#### Building on Windows + +The `jni` folder contains a Visual Studio Solution file `/jni/gs_jni/gs_jni.sln` which you should use to build the required JNI `gs_jni.dll` library file. + +With the project open in Visual Studio, select the required architecture from the drop down - then right click on 'gs_jni' in the solution explorer and choose "Build". + +#### Building on MacOS + +On your command line, navigate to `ghostpdl/demos/java/jni/gs_jni` and ensure that the build script is executable and then run it, with: + +``` +chmod +x build_darwin.sh +./build_darwin.sh +``` + +#### Building on Linux + +On your command line, navigate to `ghostpdl/demos/java/jni/gs_jni` and ensure that the build script is executable and then run it, with: + +``` +chmod +x build_linux.sh +./build_linux.sh +``` + +### gsjava: Building the JAR + + +#### Building with the command line + +Navigate to `ghostpdl/demos/java/gsjava` and use the following: + +| Platform | Run file| +|---|---| +|Windows| `build_win32.bat` | +|MacOS| `build_darwin.sh` | +|Linux| `build_linux.sh` | + +> **NOTE**<br> +> `gsjava` has a dependancy on [jni], please ensure that `gs_jni` is able to be built beforehand. + +#### Building with Eclipse + +Alternatively you can use [Eclipse] to build the JAR file. + +Using [Eclipse] import the source folder `gsjava` as a project and select `Export > Java > JAR File` as shown in the screenshot example below: + +![Eclipse export JAR](images/export-jar.png) + +#### Linking the JAR + +The built JAR should be properly linked within your project Java Build Path as follows: + +![Linking the JAR](images/linking-jar.png) + +## Demo projects + +### gstest + +This project can be opened in [Eclipse] and used to test the Ghostscript API. The sample here simply sets up an instance of Ghostscript and then sets and gets some parameters accordingly. + + +### gsviewer + +This project can be used to test the Ghostscript API alongside a UI which handles opening PostScript and PDF files. The sample application here allows for file browsing and Ghostscript file viewing. + +Below is a screenshot of the sample application with a PDF open: + +![gsviewer UI](images/gsviewer.png) + + +To run the project navigate to the `demos/java/gsviewer` location and ensure that the required libraries are in the directory: + + +| Platform | Ghostscript library file | JNI library file | +|---|---|---| +|Windows|`gpdldll64.dll`|`gs_jni.dll`| +|MacOS|`libgpdl.dylib`|`gs_jni.dylib`| +|Linux / OpenBSD|`libgpdl.so` (this may have been built as `libgs.so`, so it should be copied into this directory and renamed to `libgpdl.so`) |`gs_jni.so`| + + +#### Building on Windows + +Run the `build_win32.bat` script. + +#### Running on Windows + +To run, open `gsviewer.jar` either through File Explorer or in the command line through the following command: + +``` +java -jar gsviewer.jar +``` + +#### Building on MacOS + +On your command line, navigate to `ghostpdl/demos/java/gsviewer` and ensure that the build script is executable and then run it, with: + +``` +chmod +x build_darwin.sh +./build_darwin.sh +``` + +This will automatically build `gs_jni.dylib` (in the `ghostpdl/demos/java/jni/gs_jni/` location) and `gsjava.jar` `gsviewer.jar` in the `gsviewer` directory. + +#### Running on MacOS + +Ensure that the Ghostscript library exists in the `gsviewer` directory. (Copy and move the built library from `ghostpdl/sobin` as required). + +Ensure that the run script is executable and then run it, with: + +``` +chmod +x start_darwin.sh +./start_darwin.sh +``` + +#### Building on Linux + +On your command line, navigate to `ghostpdl/demos/java/gsviewer` and ensure that the build script is executable and then run it, with: + +``` +chmod +x build_linux.sh +./build_linux.sh +``` + +This will automatically build `gs_jni.so` (in the `ghostpdl/demos/java/jni/gs_jni/` location) and `gsjava.jar` `gsviewer.jar` in the `gsviewer` directory. + +> **NOTE**<br> +> On Linux, when using OpenJDK, the property "assistive_technologies" may +need to be modified for the Java code to build. It can be modified by +editing the "accessibility.properties" file. This is located at: +> +> `/etc/java-8-openjdk/accessibility.properties` +> + +#### Running on Linux + +Ensure that the Ghostscript library exists in the `gsviewer` directory. (Copy and move the built library from `ghostpdl/sobin` as required). + +Ensure that the run script is executable and then run it, with: + +``` +chmod +x start_linux.sh +./start_linux.sh +``` + + + + + +[jni]: #jni-building-the-java-native-interface +[gsjava]: #gsjava-building-the-jar +[gstest]: #gstest +[gsviewer]: #gsviewer +[Building Ghostscript]: index.html#building-ghostscript +[GhostPDL repository]: https://github.com/ArtifexSoftware/ghostpdl + +[Eclipse]: https://www.eclipse.org/eclipseide/ diff --git a/doc/language-bindings/md/python-gsapi.md b/doc/language-bindings/md/python-gsapi.md new file mode 100644 index 00000000..7a11da5d --- /dev/null +++ b/doc/language-bindings/md/python-gsapi.md @@ -0,0 +1,813 @@ +# gsapi.py + +<div class="banner"> +<div class="python-text"></div> +<div class="vendor-logo python-logo"></div> +</div> + + +## About + +`gsapi.py` is the `Python` binding into the Ghostscript `C` library. + +Assuming that the [Ghostscript library has been built] for your project then `gsapi` should be imported into your own `Python` scripts for API usage. + +<div class="tag sampleCode python"></div> + +``` +import gsapi +``` + + + +## gsapi + +### Overview + +Implemented using Python's ctypes module. + +All functions have the same name as the `C` function that they wrap. + +Functions raise a `GSError` exception if the underlying function returned a +negative [error code]. + +Functions that don't have out-params return `None`. Out-params are returned +directly (using tuples if there are more than one). + + +### Return codes + +`gsapi_run_*` and `gsapi_exit` methods return an `int` code which can be interpreted as follows: + +| code | status | +|---|---| +|`0`| no error | +|`gsConstants.E_QUIT`| "quit" has been executed. This is not an error. [gsapi_exit] must be called next | +|`<0` | error | + +>**NOTE**<br> +> For full detail on these return code please see: +https://www.ghostscript.com/doc/current/API.htm#return_codes +> + + +### gsapi_revision + +Returns a `gsapi_revision_t`. + +This method returns the revision numbers and strings of the Ghostscript interpreter library; you should call it before any other interpreter library functions to make sure that the correct version of the Ghostscript interpreter has been loaded. + +<div class="tag methodDefinition python"></div> + +``` +def gsapi_revision() +``` + +<div class="tag sampleCode python"></div> + +``` +version_info = gsapi.gsapi_revision() +print (version_info) +``` + +### gsapi_new_instance + +Returns a new instance of Ghostscript to be used with other `gsapi_*()` functions. + +<div class="tag methodDefinition python"></div> + +``` +def gsapi_new_instance(caller_handle) +``` + +#### Parameters + +`caller_handle`: Typically unused, but is passed to callbacks e.g. via `gsapi_set_stdio()`. Must be convertible to a `C void*`, so `None` or an + integer is ok but other types such as strings will fail. + + +<div class="tag sampleCode python"></div> + +``` +instance = gsapi.gsapi_new_instance(1) +``` + + +### gsapi_delete_instance + +Destroy an instance of Ghostscript. Before you call this, Ghostscript should ensure to have finished any processes. + +<div class="tag methodDefinition python"></div> + +``` +def gsapi_delete_instance(instance) +``` +#### Parameters + +`instance`: Your instance of Ghostscript. + +<div class="tag sampleCode python"></div> + +``` +gsapi.gsapi_delete_instance(instance) +``` + + + +### gsapi_set_stdio + +Set the callback functions for `stdio`, together with the handle to use in the callback functions. + +<div class="tag methodDefinition python"></div> + +``` +def gsapi_set_stdio(instance, stdin_fn, stdout_fn, stderr_fn) +``` +#### Parameters + +`instance`: Your instance of Ghostscript. + +`stdin_fn`: If not `None`, will be called with: +- `(caller_handle, text, len_)`: + - `caller_handle`: As passed originally to `gsapi_new_instance()`. + - `text`: A `ctypes.LP_c_char` of length `len_`. + +`stdout_fn` and `stderr_fn`:If not `None`, called with: +- `(caller_handle, text)`: + - `caller_handle`: As passed originally to `gsapi_new_instance()`. + - `text`: A Python bytes object. + +Should return the number of bytes of `text` that they handled; for convenience `None` is converted to `len(text)`. + +<div class="tag sampleCode python"></div> + +``` +def stdout_fn(caller_handle, bytes_): + sys.stdout.write(bytes_.decode('latin-1')) + +gsapi.gsapi_set_stdio(instance, None, stdout_fn, None) +print('gsapi_set_stdio() ok.') +``` + + +### gsapi_set_poll + +Set the callback function for polling. + +<div class="tag methodDefinition python"></div> + +``` +def gsapi_set_poll(instance, poll_fn) +``` +#### Parameters + +`instance`: Your instance of Ghostscript. + +`poll_fn`: Will be called with `caller_handle` as passed + to `gsapi_new_instance()`. + +<div class="tag sampleCode python"></div> + +``` +def poll_fn(caller_handle, bytes_): + sys.stdout.write(bytes_.decode('latin-1')) + +gsapi.gsapi_set_poll(instance, poll_fn) +print('gsapi_set_poll() ok.') +``` + +### gsapi_set_display_callback + +Sets the [display] callback. + +<div class="tag methodDefinition python"></div> + +``` +def gsapi_set_display_callback(instance, callback) +``` + +#### Parameters + +`instance`: Your instance of Ghostscript. + +`callback`: Must be a `display_callback` instance. + +<div class="tag sampleCode python"></div> + +``` +d = display_callback() +gsapi.gsapi_set_display_callback(instance, d) +print('gsapi_set_display_callback() ok.') +``` + +### gsapi_set_arg_encoding + +Set the encoding used for the interpretation of all subsequent arguments supplied via the `GhostAPI` interface on this instance. By default we expect args to be in encoding `0` (the 'local' encoding for this OS). On Windows this means "the currently selected codepage". On Linux this typically means `utf8`. This means that omitting to call this function will leave Ghostscript running exactly as it always has. + +This must be called after [gsapi_new_instance] and before [gsapi_init_with_args]. + + +<div class="tag methodDefinition python"></div> + +``` +def gsapi_set_arg_encoding(instance, encoding) +``` + +#### Parameters + +`instance`: Your instance of Ghostscript. + +`encoding`: Encoding must be one of: + +|Encoding enum|Value| +|---|---| +|`GS_ARG_ENCODING_LOCAL`|0| +|`GS_ARG_ENCODING_UTF8`|1| +|`GS_ARG_ENCODING_UTF16LE`|2| + +<div class="tag sampleCode python"></div> + +``` +gsapi.gsapi_set_arg_encoding(instance, gsapi.GS_ARG_ENCODING_UTF8) +``` + +>**NOTE**<br> +> Please note that use of the 'local' encoding (`GS_ARG_ENCODING_LOCAL`) is now deprecated and should be avoided in new code. + +### gsapi_set_default_device_list + +Set the string containing the list of default device names, for example "display x11alpha x11 bbox". Allows the calling application to influence which device(s) Ghostscript will try, in order, in its selection of the default device. This must be called after [gsapi_new_instance] and before [gsapi_init_with_args]. + + +<div class="tag methodDefinition python"></div> + +``` +def gsapi_set_default_device_list(instance, list_) +``` + +#### Parameters + +`instance`: Your instance of Ghostscript. + +`list_`: A string of device names. + +<div class="tag sampleCode python"></div> + +``` +gsapi.gsapi_set_default_device_list(instance, 'bmp256 bmp32b bmpgray cdeskjet cdj1600 cdj500') +``` + + +### gsapi_get_default_device_list + +Returns a string containing the list of default device names. This must be called after [gsapi_new_instance] and before [gsapi_init_with_args]. + +<div class="tag methodDefinition python"></div> + +``` +def gsapi_get_default_device_list(instance) +``` + +#### Parameters + +`instance`: Your instance of Ghostscript. + +<div class="tag sampleCode python"></div> + +``` +device_list = gsapi.gsapi_get_default_device_list(instance) +print(device_list) +``` + + +### gsapi_init_with_args + +To initialise the interpreter, pass your `instance` of Ghostscript and your argument variables with `args`. + +<div class="tag methodDefinition python"></div> + +``` +def gsapi_init_with_args(instance, args) +``` + +#### Parameters + +`instance`: Your instance of Ghostscript. + +`args`: A list/tuple of strings. + +<div class="tag sampleCode python"></div> + +``` +in_filename = 'tiger.eps' +out_filename = 'tiger.pdf' +params = ['gs', '-dNOPAUSE', '-dBATCH', '-sDEVICE=pdfwrite', + '-o', out_filename, '-f', in_filename] +gsapi.gsapi_init_with_args(instance, params) +``` + +### gsapi_run_* + +Returns an [exit code] or an exception on error. + +There is a 64 KB length limit on any buffer submitted to a `gsapi_run_*` function for processing. If you have more than 65535 bytes of input then you must split it into smaller pieces and submit each in a separate [gsapi_run_string_continue] call. + +> **NOTE**<br> +> All these functions return an [exit code] + +### gsapi_run_string_begin + +Starts a `run_string_` operation. + +<div class="tag methodDefinition python"></div> + +``` +def gsapi_run_string_begin(instance, user_errors) +``` + +#### Parameters + +`instance`: Your instance of Ghostscript. + +`user_errors`: An `int`, for more see [user errors parameter explained]. + + +<div class="tag sampleCode python"></div> + +``` +exitcode = gsapi.gsapi_run_string_begin(instance, 0) +``` + +### gsapi_run_string_continue + +Processes file byte data (`str_`) to feed as chunks into Ghostscript. This method should typically be called within a buffer context. + +> **NOTE**<br> +> An exception is _not_ raised for the `gs_error_NeedInput` return code. + +<div class="tag methodDefinition python"></div> + +``` +def gsapi_run_string_continue(instance, str_, user_errors) +``` + +#### Parameters + +`instance`: Your instance of Ghostscript. + +`str_`: Should be either a Python string or a bytes object. If the former, +it is converted into a bytes object using `utf-8` encoding. + +`user_errors`: An `int`, for more see [user errors parameter explained]. + +<div class="tag sampleCode python"></div> + +``` +exitcode = gsapi.gsapi_run_string_continue(instance, data, 0) +``` + +> **NOTE**<br> +> For the return code, we don't raise an exception for `gs_error_NeedInput`. + +### gsapi_run_string_with_length + +Processes file byte data (`str_`) to feed into Ghostscript when the `length` is known and the file byte data is immediately available. + +<div class="tag methodDefinition python"></div> + +``` +def gsapi_run_string_with_length(instance, str_, length, user_errors) +``` + +#### Parameters + +`instance`: Your instance of Ghostscript. + +`str_`: Should be either a Python string or a bytes object. If the former, +it is converted into a bytes object using `utf-8` encoding. + +`length`: An `int` representing the length of `gsapi_run_string_with_length`. + +`user_errors`: An `int`, for more see [user errors parameter explained]. + +<div class="tag sampleCode python"></div> + +``` +gsapi.gsapi_run_string_with_length(instance,"hello",5,0) +``` + + +> **NOTE**<br> +> If using this method then ensure that the file byte data will fit into a single (<64k) buffer. +> + + +### gsapi_run_string + +Processes file byte data (`str_`) to feed into Ghostscript. + +<div class="tag methodDefinition python"></div> + +``` +def gsapi_run_string(instance, str_, user_errors) +``` + +#### Parameters + +`instance`: Your instance of Ghostscript. + +`str_`: Should be either a Python string or a bytes object. If the former, +it is converted into a bytes object using `utf-8` encoding. + +`user_errors`: An `int`, for more see [user errors parameter explained]. + +<div class="tag sampleCode python"></div> + +``` +gsapi.gsapi_run_string(instance,"hello",0) +``` + + +> **NOTE**<br> +> This method can only work on a standard, null terminated C string. +> + + +### gsapi_run_string_end + +Ends a `run_string_` operation. + +<div class="tag methodDefinition python"></div> + +``` +def gsapi_run_string_end(instance, user_errors) +``` + +#### Parameters + +`instance`: Your instance of Ghostscript. + +`user_errors`: An `int`, for more see [user errors parameter explained]. + +<div class="tag sampleCode python"></div> + +``` +exitcode = gsapi.gsapi_run_string_end(instance, 0) +``` + + + +### gsapi_run_file + +Runs a file through Ghostscript. + +<div class="tag methodDefinition python"></div> + +``` +def gsapi_run_file(instance, filename, user_errors) +``` + +#### Parameters + +`instance`: Your instance of Ghostscript. + +`filename`: String representing file name. + +`user_errors`: An `int`, for more see [user errors parameter explained]. + +<div class="tag sampleCode python"></div> + +``` +in_filename = 'tiger.eps' +gsapi.gsapi_run_file(instance, in_filename, 0) +``` + + +> **NOTE**<br> +> This will process the supplied input file with any previously supplied [argument parameters]. +> + + +### 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]. + +<div class="tag methodDefinition python"></div> + + +``` +def gsapi_exit(instance) +``` + +<div class="tag sampleCode python"></div> + +``` +gsapi.gsapi_exit(instance) +``` + + +### gsapi_set_param + +Sets a parameter. Broadly, this is equivalent to setting a parameter using -d, -s or -p on the command line. This call cannot be made during a [gsapi_run_string] operation. + +Parameters in this context are not the same as 'arguments' as processed by [gsapi_init_with_args], but often the same thing can be achieved. For example, with [gsapi_init_with_args], we can pass "-r200" to change the resolution. Broadly the same thing can be achieved by using [gsapi_set_param] to set a parsed value of "<</HWResolution [ 200.0 200.0 ]>>". + +Internally, when we set a parameter, we perform an `initgraphics` operation. This means that using [gsapi_set_param] other than at the start of a page is likely to give unexpected results. + +Attempting to set a parameter that the device does not recognise will be silently ignored, and that parameter will not be found in subsequent [gsapi_get_param] calls. + +<div class="tag methodDefinition python"></div> + +``` +def gsapi_set_param(instance, param, value, type_=None) +``` + +#### Parameters + +`instance`: Your instance of Ghostscript. + +`param`: Name of parameter, either a bytes or a str; if str it is encoded using latin-1. + +`value`: A bool, int, float, bytes or str. If str, it is encoded into a bytes using utf-8. + + +`type_`: If `type_` is not `None`, `value` must be convertible to the Python type implied by `type_`: + +#### Parameter list + +| `type_` | Python type(s) | +|---|---| +|gs_spt_null | [Ignored] | +|gs_spt_bool | bool | +|gs_spt_int | int | +|gs_spt_float | float | +|gs_spt_name | [Error] | +|gs_spt_string | (bytes, str) | +|gs_spt_long | int | +|gs_spt_i64 | int | +|gs_spt_size_t | int | +|gs_spt_parsed | (bytes, str) | +|gs_spt_more_to_come | (bytes, str) | + + +An exception is raised if `type_` is an integer type and `value` is outside its range. + +If `type_` is `None`, we choose something suitable for type of `value`: + +| Python type of `value` | `type_` | +|---|---| +| bool | gs_spt_bool | +| int | gs_spt_i64 | +| float | gs_spt_float | +| bytes | gs_spt_parsed | +| str | gs_spt_parsed (encoded with utf-8) | + +If `value` is `None`, we use `gs_spt_null`. + +Otherwise `type_` must be a `gs_spt_*` except for `gs_spt_invalid` and `gs_spt_name`. + +> **NOTE**<br> +> This implementation supports automatic inference of type by looking at the type of `value`. +> + +<div class="tag sampleCode python"></div> + +``` +set_margins = gsapi.gsapi_set_param(instance, "Margins", "[10 10]") +``` + + +> **NOTE**<br> +> For more on the `C` implementation of parameters see: [Ghostscript parameters in C]. +> + + +### gsapi_get_param + +Retrieve the current value of a parameter. + +If an error occurs, the return value is negative. Otherwise the return value is the number of bytes required for storage of the value. Call once with value `NULL` to get the number of bytes required, then call again with value pointing to at least the required number of bytes where the value will be copied out. Note that the caller is required to know the type of value in order to get it. For all types other than [gs_spt_string], [gs_spt_name], and [gs_spt_parsed] knowing the type means you already know the size required. + +This call retrieves parameters/values that have made it to the device. Thus, any values set using [gs_spt_more_to_come] without a following call omitting that flag will not be retrieved. Similarly, attempting to get a parameter before [gsapi_init_with_args] has been called will not list any, even if [gsapi_set_param] has been used. + +Attempting to read a parameter that is not set will return `gs_error_undefined` (-21). Note that calling [gsapi_set_param] followed by [gsapi_get_param] may not find the value, if the device did not recognise the key as being one of its configuration keys. + +For the `C` documentation please refer to [Ghostscript get_param]. + +<div class="tag methodDefinition python"></div> + +``` +def gsapi_get_param(instance, param, type_=None, encoding=None) +``` + +#### Parameters + +`instance`: Your instance of Ghostscript. + +`param`: Name of parameter, either a `bytes` or `str`; if a `str` it is encoded using `latin-1`. + +`type_`: A `gs_spt_*` constant or `None`. If `None` we try each `gs_spt_*` until one succeeds; if none succeeds we raise the last error. + +`encoding`: Only affects string values. If `None` we return a `bytes` object, otherwise it should be the encoding to use to decode into a string, e.g. 'utf-8'. + +<div class="tag sampleCode python"></div> + +``` +get_margins = gsapi.gsapi_get_param(instance, "Margins") +``` + + +### gsapi_enumerate_params + + +Enumerate the current parameters on the instance of Ghostscript. + +Returns an array of `(key, value)` for each parameter. `key` is decoded as `latin-1`. + +<div class="tag methodDefinition python"></div> + +``` +def gsapi_enumerate_params(instance) +``` + +#### Parameters + +`instance`: Your instance of Ghostscript. + +<div class="tag sampleCode python"></div> + +``` +for param, type_ in gsapi.gsapi_enumerate_params(instance): + val = gsapi.gsapi_get_param(instance,param, encoding='utf-8') + print('%-24s : %s' % (param, val)) +``` + + + + + +### gsapi_add_control_path + + +Add a (case sensitive) path to one of the lists of [permitted paths] for file access. + +<div class="tag methodDefinition python"></div> + +``` +def gsapi_add_control_path(instance, type_, path) +``` + +#### Parameters + +`instance`: Your instance of Ghostscript. + +`type_`: An `int` which must be one of: + +|Enum|Value| +|---|---| +|GS_PERMIT_FILE_READING|0| +|GS_PERMIT_FILE_WRITING|1| +|GS_PERMIT_FILE_CONTROL|2| + +`path`: A `string` representing the file path. + +<div class="tag sampleCode python"></div> + +``` +gsapi.gsapi_add_control_path(instance, gsapi.GS_PERMIT_FILE_READING, "/docs/secure/") +``` + + + +### gsapi_remove_control_path + +Remove a (case sensitive) path from one of the lists of [permitted paths] for file access. + +<div class="tag methodDefinition python"></div> + +``` +def gsapi_remove_control_path(instance, type_, path) +``` + +#### Parameters + +`instance`: Your instance of Ghostscript. + +`type_`: An `int` representing the permission type. + +`path`: A `string` representing the file path. + +<div class="tag sampleCode python"></div> + +``` +gsapi.gsapi_remove_control_path(instance, gsapi.GS_PERMIT_FILE_READING, "/docs/secure/") +``` + + + + +### gsapi_purge_control_paths + +Clear all the paths from one of the lists of [permitted paths] for file access. + +<div class="tag methodDefinition python"></div> + +``` +def gsapi_purge_control_paths(instance, type_) +``` + +#### Parameters + +`instance`: Your instance of Ghostscript. + +`type_`: An `int` representing the permission type. + + +<div class="tag sampleCode python"></div> + +``` +gsapi.gsapi_purge_control_paths(instance, gsapi.GS_PERMIT_FILE_READING) +``` + + +### gsapi_activate_path_control + +Enable/Disable path control (i.e. whether paths are checked against [permitted paths] before access is granted). + +<div class="tag methodDefinition python"></div> + +``` +def gsapi_activate_path_control(instance, enable) +``` + +#### Parameters + +`instance`: Your instance of Ghostscript. + +`enable`: `bool` to enable/disable path control. + +<div class="tag sampleCode python"></div> + +``` +gsapi.gsapi_activate_path_control(instance, true) +``` + +### gsapi_is_path_control_active + +Query whether path control is activated or not. + + +<div class="tag methodDefinition python"></div> + +``` +def gsapi_is_path_control_active(instance) +``` + +#### Parameters + +`instance`: Your instance of Ghostscript. + +<div class="tag sampleCode python"></div> + +``` +isActive = gsapi.gsapi_is_path_control_active(instance) +``` + +## Notes + +#### 1: User errors parameter + +The `user_errors` argument is normally set to zero to indicate that errors should be handled through the normal mechanisms within the interpreted code. If set to a negative value, the functions will return an error code directly to the caller, bypassing the interpreted language. The interpreted language's error handler is bypassed, regardless of `user_errors` parameter, for the `gs_error_interrupt` generated when the polling callback returns a negative value. A positive `user_errors` is treated the same as zero. + +[Ghostscript library has been built]: python-intro.html#platform-setup + +[display]: https://ghostscript.com/doc/current/API.htm#display +[Ghostscript parameters in C]: https://www.ghostscript.com/doc/current/Use.htm#Parameters +[Ghostscript get_param]: https://www.ghostscript.com/doc/current/API.htm#get_param + + +[error code]: #return-codes +[exit code]: #return-codes +[return code]: #return-codes +[user errors parameter explained]: #1-user-errors-parameter + +[argument parameters]: #gsapi_init_with_args +[gsapi_new_instance]: #gsapi_new_instance +[gsapi_delete_instance]: #gsapi_delete_instance +[gsapi_init_with_args]: #gsapi_init_with_args +[gsapi_run_string_continue]: #gsapi_run_string_continue +[gsapi_run_string_begin]: #gsapi_run_string_begin +[gsapi_run_string]: #gsapi_run_string +[gsapi_exit]: #gsapi_exit + +[permitted paths]: https://ghostscript.com/doc/current/Use.htm#Safer + + +[gsapi_set_param]: #gsapi_set_param +[gsapi_get_param]: #gsapi_get_param +[gsapi_enumerate_params]: #gsapi_enumerate_params + +[gs_spt_string]: #parameter-list +[gs_spt_name]: #parameter-list +[gs_spt_parsed]: #parameter-list +[gs_spt_more_to_come]: #parameter-list diff --git a/doc/language-bindings/md/python-intro.md b/doc/language-bindings/md/python-intro.md new file mode 100644 index 00000000..5ec452ff --- /dev/null +++ b/doc/language-bindings/md/python-intro.md @@ -0,0 +1,76 @@ +# Python overview + +<div class="banner"> +<div class="python-text"></div> +<div class="vendor-logo python-logo"></div> +</div> + +## About + +The `Python` API is provided by the file [gsapi.py] - this is the binding to the Ghostscript `C` library. + +In the [GhostPDL repository] sample `Python` examples can be found in `/demos/python/examples.py`. + +## Platform & setup + +### Building Ghostscript + +Ghostscript should be built as a shared library for your platform. + +See [Building Ghostscript]. + +## Specifying the Ghostscript shared library + +Two environmental variables can be used to specify where to find the Ghostscript shared library. + +`GSAPI_LIB` sets the exact path of the Ghostscript shared library, otherwise, `GSAPI_LIBDIR` sets the directory containing the Ghostscript shared library. + +If neither is defined we will use the OS's default location(s) for shared libraries. + +If `GSAPI_LIB` is not defined, the leafname of the shared library is inferred +from the OS type - `libgs.so` on Unix, `libgs.dylib` on MacOS, `gsdll64.dll` on Windows 64. + + +## API test + +The `gsapi.py` file that provides the `Python` bindings can also be used to test the bindings, by running it directly. + +Assuming that your Ghostscript library has successfully been created, then from the root of your `ghostpdl` checkout run: + + +#### Windows + +<div class="tag shellCommand"> from ghostpdl</div> + +``` +// Run gsapi.py as a test script in a cmd.exe window: +set GSAPI_LIBDIR=debugbin&& python ./demos/python/gsapi.py + +// Run gsapi.py as a test script in a PowerShell window: +cmd /C "set GSAPI_LIBDIR=debugbin&& python ./demos/python/gsapi.py" +``` + +#### Linux/OpenBSD/MacOS + +<div class="tag shellCommand"> from ghostpdl</div> + +``` +// Run gsapi.py as a test script: +GSAPI_LIBDIR=sodebugbin ./demos/python/gsapi.py +``` + + +If there are no errors then this will have validated that the Ghostscript library is present & operational. + + + + +[Python]: https://www.python.org/ +[Brew]: https://brew.sh/ +[GNU]: https://www.gnu.org/ +[gsapi.py]: python-gsapi +[Building Ghostscript]: index.html#building-ghostscript +[display]: https://ghostscript.com/doc/current/API.htm#display + + +[GhostPDL repository]: https://github.com/ArtifexSoftware/ghostpdl diff --git a/doc/language-bindings/python-gsapi.html b/doc/language-bindings/python-gsapi.html new file mode 100644 index 00000000..d6d97ec3 --- /dev/null +++ b/doc/language-bindings/python-gsapi.html @@ -0,0 +1,598 @@ +<html lang="en"> + <head> + <title>Ghostscript language bindings</title> + <meta http-equiv="content-type" content="text/html; charset=utf-8"> + <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width"> + <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:200,200i,300,300i,400,400i,600,600i,700,700i,900,900i" rel="stylesheet"> + <link rel="shortcut icon" type="image/png" href="../images/favicon.png"> + <link href="css/default.css" rel="stylesheet" type="text/css" /> + <script type="text/javascript" src="js/default.js"></script> + </head> + + <body> + + <header><h1></h1><div class="menu-icon" onclick="javascript:showMenu();"></div></header> + + <div id="burger-menu"> + <div class="navigation"> + <div class="title first">Introduction</div> + <div class="link"><a href="index.html">About our APIs</a></div> + <div class="link"><a href="demo-code.html">Demo code</a></div> + + <div class="title">C#</div> + <div class="link"><a href="c-sharp-intro.html">Overview</a></div> + <div class="link"><a href="c-sharp-ghost-api.html">GhostAPI</a></div> + <div class="link"><a href="c-sharp-ghost-net.html">GhostNET</a></div> + <div class="link"><a href="c-sharp-ghost-mono.html">GhostMono</a></div> + + <div class="title">Java</div> + <div class="link"><a href="java-intro.html">Overview</a></div> + <div class="link"><a href="java-gsjavajar.html">gsjava.jar</a></div> + + <div class="title">Python</div> + <div class="link"><a href="python-intro.html">Overview</a></div> + <div class="link selected"><a href="python-gsapi.html">gsapi.py</a></div> + </div> + </div> + <div class="main"> + + <div class="left"> + <div class="title first">Introduction</div> + <div class="link"><a href="index.html">About our APIs</a></div> + <div class="link"><a href="demo-code.html">Demo code</a></div> + + <div class="title">C#</div> + <div class="link"><a href="c-sharp-intro.html">Overview</a></div> + <div class="link"><a href="c-sharp-ghost-api.html">GhostAPI</a></div> + <div class="link"><a href="c-sharp-ghost-net.html">GhostNET</a></div> + <div class="link"><a href="c-sharp-ghost-mono.html">GhostMono</a></div> + + <div class="title">Java</div> + <div class="link"><a href="java-intro.html">Overview</a></div> + <div class="link"><a href="java-gsjavajar.html">gsjava.jar</a></div> + + <div class="title">Python</div> + <div class="link"><a href="python-intro.html">Overview</a></div> + <div class="link selected"><a href="python-gsapi.html">gsapi.py</a></div> + </div> + + <div class="middle"> + +<!-- note: don't tab indent <article> as it has <pre> code which will have its layout adversly affected --> +<article class="markdown-body entry-content"><h1 id="gsapi-py">gsapi.py</h1> +<div class="banner"> +<div class="python-text"></div> +<div class="vendor-logo python-logo"></div> +</div> + + +<h2 id="about">About</h2> +<p><code>gsapi.py</code> is the <code>Python</code> binding into the Ghostscript <code>C</code> library.</p> +<p>Assuming that the <a href="python-intro.html#platform-setup">Ghostscript library has been built</a> for your project then <code>gsapi</code> should be imported into your own <code>Python</code> scripts for API usage.</p> +<div class="tag sampleCode python"></div> + +<pre><code>import gsapi</code></pre><h2 id="gsapi">gsapi</h2> +<h3 id="overview">Overview</h3> +<p>Implemented using Python's ctypes module.</p> +<p>All functions have the same name as the <code>C</code> function that they wrap.</p> +<p>Functions raise a <code>GSError</code> exception if the underlying function returned a +negative <a href="#return-codes">error code</a>.</p> +<p>Functions that don't have out-params return <code>None</code>. Out-params are returned +directly (using tuples if there are more than one).</p> +<h3 id="return-codes">Return codes</h3> +<p><code>gsapi_run_*</code> and <code>gsapi_exit</code> methods return an <code>int</code> code which can be interpreted as follows:</p> +<table> +<thead> +<tr> +<th>code</th> +<th>status</th> +</tr> +</thead> +<tbody><tr> +<td><code>0</code></td> +<td>no error</td> +</tr> +<tr> +<td><code>gsConstants.E_QUIT</code></td> +<td>"quit" has been executed. This is not an error. <a href="#gsapi_exit">gsapi_exit</a> must be called next</td> +</tr> +<tr> +<td><code><0</code></td> +<td>error</td> +</tr> +</tbody></table> +<blockquote> +<p><strong>NOTE</strong><br> +For full detail on these return code please see: +<a href="https://www.ghostscript.com/doc/current/API.htm#return_codes">https://www.ghostscript.com/doc/current/API.htm#return_codes</a></p> +</blockquote> +<h3 id="gsapi_revision">gsapi_revision</h3> +<p>Returns a <code>gsapi_revision_t</code>.</p> +<p>This method returns the revision numbers and strings of the Ghostscript interpreter library; you should call it before any other interpreter library functions to make sure that the correct version of the Ghostscript interpreter has been loaded.</p> +<div class="tag methodDefinition python"></div> + +<pre><code>def gsapi_revision()</code></pre><div class="tag sampleCode python"></div> + +<pre><code>version_info = gsapi.gsapi_revision() +print (version_info)</code></pre><h3 id="gsapi_new_instance">gsapi_new_instance</h3> +<p>Returns a new instance of Ghostscript to be used with other <code>gsapi_*()</code> functions.</p> +<div class="tag methodDefinition python"></div> + +<pre><code>def gsapi_new_instance(caller_handle)</code></pre><h4 id="parameters">Parameters</h4> +<p><code>caller_handle</code>: Typically unused, but is passed to callbacks e.g. via <code>gsapi_set_stdio()</code>. Must be convertible to a <code>C void*</code>, so <code>None</code> or an + integer is ok but other types such as strings will fail.</p> +<div class="tag sampleCode python"></div> + +<pre><code>instance = gsapi.gsapi_new_instance(1)</code></pre><h3 id="gsapi_delete_instance">gsapi_delete_instance</h3> +<p>Destroy an instance of Ghostscript. Before you call this, Ghostscript should ensure to have finished any processes.</p> +<div class="tag methodDefinition python"></div> + +<pre><code>def gsapi_delete_instance(instance)</code></pre><h4 id="parameters">Parameters</h4> +<p><code>instance</code>: Your instance of Ghostscript.</p> +<div class="tag sampleCode python"></div> + +<pre><code>gsapi.gsapi_delete_instance(instance)</code></pre><h3 id="gsapi_set_stdio">gsapi_set_stdio</h3> +<p>Set the callback functions for <code>stdio</code>, together with the handle to use in the callback functions.</p> +<div class="tag methodDefinition python"></div> + +<pre><code>def gsapi_set_stdio(instance, stdin_fn, stdout_fn, stderr_fn)</code></pre><h4 id="parameters">Parameters</h4> +<p><code>instance</code>: Your instance of Ghostscript.</p> +<p><code>stdin_fn</code>: If not <code>None</code>, will be called with:</p> +<ul> +<li><code>(caller_handle, text, len_)</code>:<ul> +<li><code>caller_handle</code>: As passed originally to <code>gsapi_new_instance()</code>.</li> +<li><code>text</code>: A <code>ctypes.LP_c_char</code> of length <code>len_</code>.</li> +</ul> +</li> +</ul> +<p><code>stdout_fn</code> and <code>stderr_fn</code>:If not <code>None</code>, called with:</p> +<ul> +<li><code>(caller_handle, text)</code>:<ul> +<li><code>caller_handle</code>: As passed originally to <code>gsapi_new_instance()</code>.</li> +<li><code>text</code>: A Python bytes object.</li> +</ul> +</li> +</ul> +<p>Should return the number of bytes of <code>text</code> that they handled; for convenience <code>None</code> is converted to <code>len(text)</code>.</p> +<div class="tag sampleCode python"></div> + +<pre><code>def stdout_fn(caller_handle, bytes_): + sys.stdout.write(bytes_.decode('latin-1')) + +gsapi.gsapi_set_stdio(instance, None, stdout_fn, None) +print('gsapi_set_stdio() ok.')</code></pre><h3 id="gsapi_set_poll">gsapi_set_poll</h3> +<p>Set the callback function for polling.</p> +<div class="tag methodDefinition python"></div> + +<pre><code>def gsapi_set_poll(instance, poll_fn)</code></pre><h4 id="parameters">Parameters</h4> +<p><code>instance</code>: Your instance of Ghostscript.</p> +<p><code>poll_fn</code>: Will be called with <code>caller_handle</code> as passed + to <code>gsapi_new_instance()</code>.</p> +<div class="tag sampleCode python"></div> + +<pre><code>def poll_fn(caller_handle, bytes_): + sys.stdout.write(bytes_.decode('latin-1')) + +gsapi.gsapi_set_poll(instance, poll_fn) +print('gsapi_set_poll() ok.')</code></pre><h3 id="gsapi_set_display_callback">gsapi_set_display_callback</h3> +<p>Sets the <a href="https://ghostscript.com/doc/current/API.htm#display">display</a> callback.</p> +<div class="tag methodDefinition python"></div> + +<pre><code>def gsapi_set_display_callback(instance, callback)</code></pre><h4 id="parameters">Parameters</h4> +<p><code>instance</code>: Your instance of Ghostscript.</p> +<p><code>callback</code>: Must be a <code>display_callback</code> instance.</p> +<div class="tag sampleCode python"></div> + +<pre><code>d = display_callback() +gsapi.gsapi_set_display_callback(instance, d) +print('gsapi_set_display_callback() ok.')</code></pre><h3 id="gsapi_set_arg_encoding">gsapi_set_arg_encoding</h3> +<p>Set the encoding used for the interpretation of all subsequent arguments supplied via the <code>GhostAPI</code> interface on this instance. By default we expect args to be in encoding <code>0</code> (the 'local' encoding for this OS). On Windows this means "the currently selected codepage". On Linux this typically means <code>utf8</code>. This means that omitting to call this function will leave Ghostscript running exactly as it always has.</p> +<p>This must be called after <a href="#gsapi_new_instance">gsapi_new_instance</a> and before <a href="#gsapi_init_with_args">gsapi_init_with_args</a>.</p> +<div class="tag methodDefinition python"></div> + +<pre><code>def gsapi_set_arg_encoding(instance, encoding)</code></pre><h4 id="parameters">Parameters</h4> +<p><code>instance</code>: Your instance of Ghostscript.</p> +<p><code>encoding</code>: Encoding must be one of:</p> +<table> +<thead> +<tr> +<th>Encoding enum</th> +<th>Value</th> +</tr> +</thead> +<tbody><tr> +<td><code>GS_ARG_ENCODING_LOCAL</code></td> +<td>0</td> +</tr> +<tr> +<td><code>GS_ARG_ENCODING_UTF8</code></td> +<td>1</td> +</tr> +<tr> +<td><code>GS_ARG_ENCODING_UTF16LE</code></td> +<td>2</td> +</tr> +</tbody></table> +<div class="tag sampleCode python"></div> + +<pre><code>gsapi.gsapi_set_arg_encoding(instance, gsapi.GS_ARG_ENCODING_UTF8)</code></pre><blockquote> +<p><strong>NOTE</strong><br> +Please note that use of the 'local' encoding (<code>GS_ARG_ENCODING_LOCAL</code>) is now deprecated and should be avoided in new code.</p> +</blockquote> +<h3 id="gsapi_set_default_device_list">gsapi_set_default_device_list</h3> +<p>Set the string containing the list of default device names, for example "display x11alpha x11 bbox". Allows the calling application to influence which device(s) Ghostscript will try, in order, in its selection of the default device. This must be called after <a href="#gsapi_new_instance">gsapi_new_instance</a> and before <a href="#gsapi_init_with_args">gsapi_init_with_args</a>.</p> +<div class="tag methodDefinition python"></div> + +<pre><code>def gsapi_set_default_device_list(instance, list_)</code></pre><h4 id="parameters">Parameters</h4> +<p><code>instance</code>: Your instance of Ghostscript.</p> +<p><code>list_</code>: A string of device names.</p> +<div class="tag sampleCode python"></div> + +<pre><code>gsapi.gsapi_set_default_device_list(instance, 'bmp256 bmp32b bmpgray cdeskjet cdj1600 cdj500')</code></pre><h3 id="gsapi_get_default_device_list">gsapi_get_default_device_list</h3> +<p>Returns a string containing the list of default device names. This must be called after <a href="#gsapi_new_instance">gsapi_new_instance</a> and before <a href="#gsapi_init_with_args">gsapi_init_with_args</a>.</p> +<div class="tag methodDefinition python"></div> + +<pre><code>def gsapi_get_default_device_list(instance)</code></pre><h4 id="parameters">Parameters</h4> +<p><code>instance</code>: Your instance of Ghostscript.</p> +<div class="tag sampleCode python"></div> + +<pre><code>device_list = gsapi.gsapi_get_default_device_list(instance) +print(device_list)</code></pre><h3 id="gsapi_init_with_args">gsapi_init_with_args</h3> +<p>To initialise the interpreter, pass your <code>instance</code> of Ghostscript and your argument variables with <code>args</code>.</p> +<div class="tag methodDefinition python"></div> + +<pre><code>def gsapi_init_with_args(instance, args)</code></pre><h4 id="parameters">Parameters</h4> +<p><code>instance</code>: Your instance of Ghostscript.</p> +<p><code>args</code>: A list/tuple of strings.</p> +<div class="tag sampleCode python"></div> + +<pre><code>in_filename = 'tiger.eps' +out_filename = 'tiger.pdf' +params = ['gs', '-dNOPAUSE', '-dBATCH', '-sDEVICE=pdfwrite', + '-o', out_filename, '-f', in_filename] +gsapi.gsapi_init_with_args(instance, params)</code></pre><h3 id="gsapi_run_-">gsapi_run_*</h3> +<p>Returns an <a href="#return-codes">exit code</a> or an exception on error.</p> +<p>There is a 64 KB length limit on any buffer submitted to a <code>gsapi_run_*</code> function for processing. If you have more than 65535 bytes of input then you must split it into smaller pieces and submit each in a separate <a href="#gsapi_run_string_continue">gsapi_run_string_continue</a> call.</p> +<blockquote> +<p><strong>NOTE</strong><br> +All these functions return an <a href="#return-codes">exit code</a></p> +</blockquote> +<h3 id="gsapi_run_string_begin">gsapi_run_string_begin</h3> +<p>Starts a <code>run_string_</code> operation.</p> +<div class="tag methodDefinition python"></div> + +<pre><code>def gsapi_run_string_begin(instance, user_errors)</code></pre><h4 id="parameters">Parameters</h4> +<p><code>instance</code>: Your instance of Ghostscript.</p> +<p><code>user_errors</code>: An <code>int</code>, for more see <a href="#1-user-errors-parameter">user errors parameter explained</a>.</p> +<div class="tag sampleCode python"></div> + +<pre><code>exitcode = gsapi.gsapi_run_string_begin(instance, 0)</code></pre><h3 id="gsapi_run_string_continue">gsapi_run_string_continue</h3> +<p>Processes file byte data (<code>str_</code>) to feed as chunks into Ghostscript. This method should typically be called within a buffer context.</p> +<blockquote> +<p><strong>NOTE</strong><br> +An exception is <em>not</em> raised for the <code>gs_error_NeedInput</code> return code.</p> +</blockquote> +<div class="tag methodDefinition python"></div> + +<pre><code>def gsapi_run_string_continue(instance, str_, user_errors)</code></pre><h4 id="parameters">Parameters</h4> +<p><code>instance</code>: Your instance of Ghostscript.</p> +<p><code>str_</code>: Should be either a Python string or a bytes object. If the former, +it is converted into a bytes object using <code>utf-8</code> encoding.</p> +<p><code>user_errors</code>: An <code>int</code>, for more see <a href="#1-user-errors-parameter">user errors parameter explained</a>.</p> +<div class="tag sampleCode python"></div> + +<pre><code>exitcode = gsapi.gsapi_run_string_continue(instance, data, 0)</code></pre><blockquote> +<p><strong>NOTE</strong><br> +For the return code, we don't raise an exception for <code>gs_error_NeedInput</code>.</p> +</blockquote> +<h3 id="gsapi_run_string_with_length">gsapi_run_string_with_length</h3> +<p>Processes file byte data (<code>str_</code>) to feed into Ghostscript when the <code>length</code> is known and the file byte data is immediately available.</p> +<div class="tag methodDefinition python"></div> + +<pre><code>def gsapi_run_string_with_length(instance, str_, length, user_errors)</code></pre><h4 id="parameters">Parameters</h4> +<p><code>instance</code>: Your instance of Ghostscript.</p> +<p><code>str_</code>: Should be either a Python string or a bytes object. If the former, +it is converted into a bytes object using <code>utf-8</code> encoding.</p> +<p><code>length</code>: An <code>int</code> representing the length of <code>gsapi_run_string_with_length</code>.</p> +<p><code>user_errors</code>: An <code>int</code>, for more see <a href="#1-user-errors-parameter">user errors parameter explained</a>.</p> +<div class="tag sampleCode python"></div> + +<pre><code>gsapi.gsapi_run_string_with_length(instance,"hello",5,0)</code></pre><blockquote> +<p><strong>NOTE</strong><br> +If using this method then ensure that the file byte data will fit into a single (<64k) buffer.</p> +</blockquote> +<h3 id="gsapi_run_string">gsapi_run_string</h3> +<p>Processes file byte data (<code>str_</code>) to feed into Ghostscript.</p> +<div class="tag methodDefinition python"></div> + +<pre><code>def gsapi_run_string(instance, str_, user_errors)</code></pre><h4 id="parameters">Parameters</h4> +<p><code>instance</code>: Your instance of Ghostscript.</p> +<p><code>str_</code>: Should be either a Python string or a bytes object. If the former, +it is converted into a bytes object using <code>utf-8</code> encoding.</p> +<p><code>user_errors</code>: An <code>int</code>, for more see <a href="#1-user-errors-parameter">user errors parameter explained</a>.</p> +<div class="tag sampleCode python"></div> + +<pre><code>gsapi.gsapi_run_string(instance,"hello",0)</code></pre><blockquote> +<p><strong>NOTE</strong><br> +This method can only work on a standard, null terminated C string.</p> +</blockquote> +<h3 id="gsapi_run_string_end">gsapi_run_string_end</h3> +<p>Ends a <code>run_string_</code> operation.</p> +<div class="tag methodDefinition python"></div> + +<pre><code>def gsapi_run_string_end(instance, user_errors)</code></pre><h4 id="parameters">Parameters</h4> +<p><code>instance</code>: Your instance of Ghostscript.</p> +<p><code>user_errors</code>: An <code>int</code>, for more see <a href="#1-user-errors-parameter">user errors parameter explained</a>.</p> +<div class="tag sampleCode python"></div> + +<pre><code>exitcode = gsapi.gsapi_run_string_end(instance, 0)</code></pre><h3 id="gsapi_run_file">gsapi_run_file</h3> +<p>Runs a file through Ghostscript.</p> +<div class="tag methodDefinition python"></div> + +<pre><code>def gsapi_run_file(instance, filename, user_errors)</code></pre><h4 id="parameters">Parameters</h4> +<p><code>instance</code>: Your instance of Ghostscript.</p> +<p><code>filename</code>: String representing file name.</p> +<p><code>user_errors</code>: An <code>int</code>, for more see <a href="#1-user-errors-parameter">user errors parameter explained</a>.</p> +<div class="tag sampleCode python"></div> + +<pre><code>in_filename = 'tiger.eps' +gsapi.gsapi_run_file(instance, in_filename, 0)</code></pre><blockquote> +<p><strong>NOTE</strong><br> +This will process the supplied input file with any previously supplied <a href="#gsapi_init_with_args">argument parameters</a>.</p> +</blockquote> +<h3 id="gsapi_exit">gsapi_exit</h3> +<p>Exit the interpreter. This must be called on shutdown if <a href="#gsapi_init_with_args">gsapi_init_with_args</a> has been called, and just before <a href="#gsapi_delete_instance">gsapi_delete_instance</a>.</p> +<div class="tag methodDefinition python"></div> + + +<pre><code>def gsapi_exit(instance)</code></pre><div class="tag sampleCode python"></div> + +<pre><code>gsapi.gsapi_exit(instance)</code></pre><h3 id="gsapi_set_param">gsapi_set_param</h3> +<p>Sets a parameter. Broadly, this is equivalent to setting a parameter using -d, -s or -p on the command line. This call cannot be made during a <a href="#gsapi_run_string">gsapi_run_string</a> operation.</p> +<p>Parameters in this context are not the same as 'arguments' as processed by <a href="#gsapi_init_with_args">gsapi_init_with_args</a>, but often the same thing can be achieved. For example, with <a href="#gsapi_init_with_args">gsapi_init_with_args</a>, we can pass "-r200" to change the resolution. Broadly the same thing can be achieved by using <a href="#gsapi_set_param">gsapi_set_param</a> to set a parsed value of "<</HWResolution [ 200.0 200.0 ]>>".</p> +<p>Internally, when we set a parameter, we perform an <code>initgraphics</code> operation. This means that using <a href="#gsapi_set_param">gsapi_set_param</a> other than at the start of a page is likely to give unexpected results.</p> +<p>Attempting to set a parameter that the device does not recognise will be silently ignored, and that parameter will not be found in subsequent <a href="#gsapi_get_param">gsapi_get_param</a> calls.</p> +<div class="tag methodDefinition python"></div> + +<pre><code>def gsapi_set_param(instance, param, value, type_=None)</code></pre><h4 id="parameters">Parameters</h4> +<p><code>instance</code>: Your instance of Ghostscript.</p> +<p><code>param</code>: Name of parameter, either a bytes or a str; if str it is encoded using latin-1.</p> +<p><code>value</code>: A bool, int, float, bytes or str. If str, it is encoded into a bytes using utf-8.</p> +<p><code>type_</code>: If <code>type_</code> is not <code>None</code>, <code>value</code> must be convertible to the Python type implied by <code>type_</code>:</p> +<h4 id="parameter-list">Parameter list</h4> +<table> +<thead> +<tr> +<th><code>type_</code></th> +<th>Python type(s)</th> +</tr> +</thead> +<tbody><tr> +<td>gs_spt_null</td> +<td>[Ignored]</td> +</tr> +<tr> +<td>gs_spt_bool</td> +<td>bool</td> +</tr> +<tr> +<td>gs_spt_int</td> +<td>int</td> +</tr> +<tr> +<td>gs_spt_float</td> +<td>float</td> +</tr> +<tr> +<td>gs_spt_name</td> +<td>[Error]</td> +</tr> +<tr> +<td>gs_spt_string</td> +<td>(bytes, str)</td> +</tr> +<tr> +<td>gs_spt_long</td> +<td>int</td> +</tr> +<tr> +<td>gs_spt_i64</td> +<td>int</td> +</tr> +<tr> +<td>gs_spt_size_t</td> +<td>int</td> +</tr> +<tr> +<td>gs_spt_parsed</td> +<td>(bytes, str)</td> +</tr> +<tr> +<td>gs_spt_more_to_come</td> +<td>(bytes, str)</td> +</tr> +</tbody></table> +<p>An exception is raised if <code>type_</code> is an integer type and <code>value</code> is outside its range.</p> +<p>If <code>type_</code> is <code>None</code>, we choose something suitable for type of <code>value</code>:</p> +<table> +<thead> +<tr> +<th>Python type of <code>value</code></th> +<th><code>type_</code></th> +</tr> +</thead> +<tbody><tr> +<td>bool</td> +<td>gs_spt_bool</td> +</tr> +<tr> +<td>int</td> +<td>gs_spt_i64</td> +</tr> +<tr> +<td>float</td> +<td>gs_spt_float</td> +</tr> +<tr> +<td>bytes</td> +<td>gs_spt_parsed</td> +</tr> +<tr> +<td>str</td> +<td>gs_spt_parsed (encoded with utf-8)</td> +</tr> +</tbody></table> +<p>If <code>value</code> is <code>None</code>, we use <code>gs_spt_null</code>.</p> +<p>Otherwise <code>type_</code> must be a <code>gs_spt_*</code> except for <code>gs_spt_invalid</code> and <code>gs_spt_name</code>.</p> +<blockquote> +<p><strong>NOTE</strong><br> +This implementation supports automatic inference of type by looking at the type of <code>value</code>.</p> +</blockquote> +<div class="tag sampleCode python"></div> + +<pre><code>set_margins = gsapi.gsapi_set_param(instance, "Margins", "[10 10]")</code></pre><blockquote> +<p><strong>NOTE</strong><br> +For more on the <code>C</code> implementation of parameters see: <a href="https://www.ghostscript.com/doc/current/Use.htm#Parameters">Ghostscript parameters in C</a>.</p> +</blockquote> +<h3 id="gsapi_get_param">gsapi_get_param</h3> +<p>Retrieve the current value of a parameter.</p> +<p>If an error occurs, the return value is negative. Otherwise the return value is the number of bytes required for storage of the value. Call once with value <code>NULL</code> to get the number of bytes required, then call again with value pointing to at least the required number of bytes where the value will be copied out. Note that the caller is required to know the type of value in order to get it. For all types other than <a href="#parameter-list">gs_spt_string</a>, <a href="#parameter-list">gs_spt_name</a>, and <a href="#parameter-list">gs_spt_parsed</a> knowing the type means you already know the size required.</p> +<p>This call retrieves parameters/values that have made it to the device. Thus, any values set using <a href="#parameter-list">gs_spt_more_to_come</a> without a following call omitting that flag will not be retrieved. Similarly, attempting to get a parameter before <a href="#gsapi_init_with_args">gsapi_init_with_args</a> has been called will not list any, even if <a href="#gsapi_set_param">gsapi_set_param</a> has been used.</p> +<p>Attempting to read a parameter that is not set will return <code>gs_error_undefined</code> (-21). Note that calling <a href="#gsapi_set_param">gsapi_set_param</a> followed by <a href="#gsapi_get_param">gsapi_get_param</a> may not find the value, if the device did not recognise the key as being one of its configuration keys.</p> +<p>For the <code>C</code> documentation please refer to <a href="https://www.ghostscript.com/doc/current/API.htm#get_param">Ghostscript get_param</a>.</p> +<div class="tag methodDefinition python"></div> + +<pre><code>def gsapi_get_param(instance, param, type_=None, encoding=None)</code></pre><h4 id="parameters">Parameters</h4> +<p><code>instance</code>: Your instance of Ghostscript.</p> +<p><code>param</code>: Name of parameter, either a <code>bytes</code> or <code>str</code>; if a <code>str</code> it is encoded using <code>latin-1</code>.</p> +<p><code>type_</code>: A <code>gs_spt_*</code> constant or <code>None</code>. If <code>None</code> we try each <code>gs_spt_*</code> until one succeeds; if none succeeds we raise the last error.</p> +<p><code>encoding</code>: Only affects string values. If <code>None</code> we return a <code>bytes</code> object, otherwise it should be the encoding to use to decode into a string, e.g. 'utf-8'.</p> +<div class="tag sampleCode python"></div> + +<pre><code>get_margins = gsapi.gsapi_get_param(instance, "Margins")</code></pre><h3 id="gsapi_enumerate_params">gsapi_enumerate_params</h3> +<p>Enumerate the current parameters on the instance of Ghostscript.</p> +<p>Returns an array of <code>(key, value)</code> for each parameter. <code>key</code> is decoded as <code>latin-1</code>.</p> +<div class="tag methodDefinition python"></div> + +<pre><code>def gsapi_enumerate_params(instance)</code></pre><h4 id="parameters">Parameters</h4> +<p><code>instance</code>: Your instance of Ghostscript.</p> +<div class="tag sampleCode python"></div> + +<pre><code>for param, type_ in gsapi.gsapi_enumerate_params(instance): + val = gsapi.gsapi_get_param(instance,param, encoding='utf-8') + print('%-24s : %s' % (param, val))</code></pre><h3 id="gsapi_add_control_path">gsapi_add_control_path</h3> +<p>Add a (case sensitive) path to one of the lists of <a href="https://ghostscript.com/doc/current/Use.htm#Safer">permitted paths</a> for file access.</p> +<div class="tag methodDefinition python"></div> + +<pre><code>def gsapi_add_control_path(instance, type_, path)</code></pre><h4 id="parameters">Parameters</h4> +<p><code>instance</code>: Your instance of Ghostscript.</p> +<p><code>type_</code>: An <code>int</code> which must be one of:</p> +<table> +<thead> +<tr> +<th>Enum</th> +<th>Value</th> +</tr> +</thead> +<tbody><tr> +<td>GS_PERMIT_FILE_READING</td> +<td>0</td> +</tr> +<tr> +<td>GS_PERMIT_FILE_WRITING</td> +<td>1</td> +</tr> +<tr> +<td>GS_PERMIT_FILE_CONTROL</td> +<td>2</td> +</tr> +</tbody></table> +<p><code>path</code>: A <code>string</code> representing the file path.</p> +<div class="tag sampleCode python"></div> + +<pre><code>gsapi.gsapi_add_control_path(instance, gsapi.GS_PERMIT_FILE_READING, "/docs/secure/")</code></pre><h3 id="gsapi_remove_control_path">gsapi_remove_control_path</h3> +<p>Remove a (case sensitive) path from one of the lists of <a href="https://ghostscript.com/doc/current/Use.htm#Safer">permitted paths</a> for file access.</p> +<div class="tag methodDefinition python"></div> + +<pre><code>def gsapi_remove_control_path(instance, type_, path)</code></pre><h4 id="parameters">Parameters</h4> +<p><code>instance</code>: Your instance of Ghostscript.</p> +<p><code>type_</code>: An <code>int</code> representing the permission type.</p> +<p><code>path</code>: A <code>string</code> representing the file path.</p> +<div class="tag sampleCode python"></div> + +<pre><code>gsapi.gsapi_remove_control_path(instance, gsapi.GS_PERMIT_FILE_READING, "/docs/secure/")</code></pre><h3 id="gsapi_purge_control_paths">gsapi_purge_control_paths</h3> +<p>Clear all the paths from one of the lists of <a href="https://ghostscript.com/doc/current/Use.htm#Safer">permitted paths</a> for file access.</p> +<div class="tag methodDefinition python"></div> + +<pre><code>def gsapi_purge_control_paths(instance, type_)</code></pre><h4 id="parameters">Parameters</h4> +<p><code>instance</code>: Your instance of Ghostscript.</p> +<p><code>type_</code>: An <code>int</code> representing the permission type.</p> +<div class="tag sampleCode python"></div> + +<pre><code>gsapi.gsapi_purge_control_paths(instance, gsapi.GS_PERMIT_FILE_READING)</code></pre><h3 id="gsapi_activate_path_control">gsapi_activate_path_control</h3> +<p>Enable/Disable path control (i.e. whether paths are checked against <a href="https://ghostscript.com/doc/current/Use.htm#Safer">permitted paths</a> before access is granted).</p> +<div class="tag methodDefinition python"></div> + +<pre><code>def gsapi_activate_path_control(instance, enable)</code></pre><h4 id="parameters">Parameters</h4> +<p><code>instance</code>: Your instance of Ghostscript.</p> +<p><code>enable</code>: <code>bool</code> to enable/disable path control.</p> +<div class="tag sampleCode python"></div> + +<pre><code>gsapi.gsapi_activate_path_control(instance, true)</code></pre><h3 id="gsapi_is_path_control_active">gsapi_is_path_control_active</h3> +<p>Query whether path control is activated or not.</p> +<div class="tag methodDefinition python"></div> + +<pre><code>def gsapi_is_path_control_active(instance)</code></pre><h4 id="parameters">Parameters</h4> +<p><code>instance</code>: Your instance of Ghostscript.</p> +<div class="tag sampleCode python"></div> + +<pre><code>isActive = gsapi.gsapi_is_path_control_active(instance)</code></pre><h2 id="notes">Notes</h2> +<h4 id="1-user-errors-parameter">1: User errors parameter</h4> +<p>The <code>user_errors</code> argument is normally set to zero to indicate that errors should be handled through the normal mechanisms within the interpreted code. If set to a negative value, the functions will return an error code directly to the caller, bypassing the interpreted language. The interpreted language's error handler is bypassed, regardless of <code>user_errors</code> parameter, for the <code>gs_error_interrupt</code> generated when the polling callback returns a negative value. A positive <code>user_errors</code> is treated the same as zero.</p> +</article> + + + </div><!-- / middle --> + + <div class="right"> + + <div class="link"><a href="#about">About</a></div> + <div class="link"><a href="#gsapi">gsapi</a></div> + <div class="sub-link"><a href="#overview">Overview</a></div> + <div class="sub-link"><a href="#return-codes">Return codes</a></div> + <div class="sub-link"><a href="#gsapi_revision">gsapi_revision</a></div> + <div class="sub-link"><a href="#gsapi_new_instance">gsapi_new_instance</a></div> + <div class="sub-link"><a href="#gsapi_delete_instance">gsapi_delete_instance</a></div> + <div class="sub-link"><a href="#gsapi_set_stdio">gsapi_set_stdio</a></div> + <div class="sub-link"><a href="#gsapi_set_poll">gsapi_set_poll</a></div> + <div class="sub-link"><a href="#gsapi_set_display_callback">gsapi_set_display_callback</a></div> + <div class="sub-link"><a href="#gsapi_set_arg_encoding">gsapi_set_arg_encoding</a></div> + <div class="sub-link"><a href="#gsapi_set_default_device_list">gsapi_set_default_device_list</a></div> + <div class="sub-link"><a href="#gsapi_get_default_device_list">gsapi_get_default_device_list</a></div> + <div class="sub-link"><a href="#gsapi_init_with_args">gsapi_init_with_args</a></div> + <div class="sub-link"><a href="#gsapi_run_-">gsapi_run_*</a></div> + <div class="sub-link"><a href="#gsapi_run_string_begin">gsapi_run_string_begin</a></div> + <div class="sub-link"><a href="#gsapi_run_string_continue">gsapi_run_string_continue</a></div> + <div class="sub-link"><a href="#gsapi_run_string_with_length">gsapi_run_string_with_length</a></div> + <div class="sub-link"><a href="#gsapi_run_string">gsapi_run_string</a></div> + <div class="sub-link"><a href="#gsapi_run_string_end">gsapi_run_string_end</a></div> + <div class="sub-link"><a href="#gsapi_run_file">gsapi_run_file</a></div> + <div class="sub-link"><a href="#gsapi_exit">gsapi_exit</a></div> + <div class="sub-link"><a href="#gsapi_set_param">gsapi_set_param</a></div> + <div class="sub-link"><a href="#gsapi_get_param">gsapi_get_param</a></div> + <div class="sub-link"><a href="#gsapi_enumerate_params">gsapi_enumerate_params</a></div> + <div class="sub-link"><a href="#gsapi_add_control_path">gsapi_add_control_path</a></div> + <div class="sub-link"><a href="#gsapi_remove_control_path">gsapi_remove_control_path</a></div> + <div class="sub-link"><a href="#gsapi_purge_control_paths">gsapi_purge_control_paths</a></div> + <div class="sub-link"><a href="#gsapi_activate_path_control">gsapi_activate_path_control</a></div> + <div class="sub-link"><a href="#gsapi_is_path_control_active">gsapi_is_path_control_active</a></div> + <div class="link"><a href="#notes">Notes</a></div> + </div> + + </div> + + <footer></footer> + + </body> + +</html> diff --git a/doc/language-bindings/python-intro.html b/doc/language-bindings/python-intro.html new file mode 100644 index 00000000..6236219b --- /dev/null +++ b/doc/language-bindings/python-intro.html @@ -0,0 +1,114 @@ +<html lang="en"> + <head> + <title>Ghostscript language bindings</title> + <meta http-equiv="content-type" content="text/html; charset=utf-8"> + <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width"> + <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:200,200i,300,300i,400,400i,600,600i,700,700i,900,900i" rel="stylesheet"> + <link rel="shortcut icon" type="image/png" href="../images/favicon.png"> + <link href="css/default.css" rel="stylesheet" type="text/css" /> + <script type="text/javascript" src="js/default.js"></script> + </head> + + <body> + + <header><h1></h1><div class="menu-icon" onclick="javascript:showMenu();"></div></header> + + <div id="burger-menu"> + <div class="navigation"> + <div class="title first">Introduction</div> + <div class="link"><a href="index.html">About our APIs</a></div> + <div class="link"><a href="demo-code.html">Demo code</a></div> + + <div class="title">C#</div> + <div class="link"><a href="c-sharp-intro.html">Overview</a></div> + <div class="link"><a href="c-sharp-ghost-api.html">GhostAPI</a></div> + <div class="link"><a href="c-sharp-ghost-net.html">GhostNET</a></div> + <div class="link"><a href="c-sharp-ghost-mono.html">GhostMono</a></div> + + <div class="title">Java</div> + <div class="link"><a href="java-intro.html">Overview</a></div> + <div class="link"><a href="java-gsjavajar.html">gsjava.jar</a></div> + + <div class="title">Python</div> + <div class="link selected"><a href="python-intro.html">Overview</a></div> + <div class="link"><a href="python-gsapi.html">gsapi.py</a></div> + </div> + </div> + <div class="main"> + + <div class="left"> + <div class="title first">Introduction</div> + <div class="link"><a href="index.html">About our APIs</a></div> + <div class="link"><a href="demo-code.html">Demo code</a></div> + + <div class="title">C#</div> + <div class="link"><a href="c-sharp-intro.html">Overview</a></div> + <div class="link"><a href="c-sharp-ghost-api.html">GhostAPI</a></div> + <div class="link"><a href="c-sharp-ghost-net.html">GhostNET</a></div> + <div class="link"><a href="c-sharp-ghost-mono.html">GhostMono</a></div> + + <div class="title">Java</div> + <div class="link"><a href="java-intro.html">Overview</a></div> + <div class="link"><a href="java-gsjavajar.html">gsjava.jar</a></div> + + <div class="title">Python</div> + <div class="link selected"><a href="python-intro.html">Overview</a></div> + <div class="link"><a href="python-gsapi.html">gsapi.py</a></div> + </div> + + <div class="middle"> + +<!-- note: don't tab indent <article> as it has <pre> code which will have its layout adversly affected --> +<article class="markdown-body entry-content"><h1 id="python-overview">Python overview</h1> +<div class="banner"> +<div class="python-text"></div> +<div class="vendor-logo python-logo"></div> +</div> + +<h2 id="about">About</h2> +<p>The <code>Python</code> API is provided by the file <a href="python-gsapi">gsapi.py</a> - this is the binding to the Ghostscript <code>C</code> library.</p> +<p>In the <a href="https://github.com/ArtifexSoftware/ghostpdl">GhostPDL repository</a> sample <code>Python</code> examples can be found in <code>/demos/python/examples.py</code>.</p> +<h2 id="platform-setup">Platform & setup</h2> +<h3 id="building-ghostscript">Building Ghostscript</h3> +<p>Ghostscript should be built as a shared library for your platform.</p> +<p>See <a href="index.html#building-ghostscript">Building Ghostscript</a>.</p> +<h2 id="specifying-the-ghostscript-shared-library">Specifying the Ghostscript shared library</h2> +<p>Two environmental variables can be used to specify where to find the Ghostscript shared library.</p> +<p><code>GSAPI_LIB</code> sets the exact path of the Ghostscript shared library, otherwise, <code>GSAPI_LIBDIR</code> sets the directory containing the Ghostscript shared library.</p> +<p>If neither is defined we will use the OS's default location(s) for shared libraries.</p> +<p>If <code>GSAPI_LIB</code> is not defined, the leafname of the shared library is inferred +from the OS type - <code>libgs.so</code> on Unix, <code>libgs.dylib</code> on MacOS, <code>gsdll64.dll</code> on Windows 64.</p> +<h2 id="api-test">API test</h2> +<p>The <code>gsapi.py</code> file that provides the <code>Python</code> bindings can also be used to test the bindings, by running it directly.</p> +<p>Assuming that your Ghostscript library has successfully been created, then from the root of your <code>ghostpdl</code> checkout run:</p> +<h4 id="windows">Windows</h4> +<div class="tag shellCommand"> from ghostpdl</div> + +<pre><code>// Run gsapi.py as a test script in a cmd.exe window: +set GSAPI_LIBDIR=debugbin&& python ./demos/python/gsapi.py + +// Run gsapi.py as a test script in a PowerShell window: +cmd /C "set GSAPI_LIBDIR=debugbin&& python ./demos/python/gsapi.py"</code></pre><h4 id="linux-openbsd-macos">Linux/OpenBSD/MacOS</h4> +<div class="tag shellCommand"> from ghostpdl</div> + +<pre><code>// Run gsapi.py as a test script: +GSAPI_LIBDIR=sodebugbin ./demos/python/gsapi.py</code></pre><p>If there are no errors then this will have validated that the Ghostscript library is present & operational.</p> +</article> + + </div> <!-- /middle --> + + <div class="right"> + <div class="link"><a href="#about">About</a></div> + <div class="link"><a href="#platform-setup">Platform & setup</a></div> + <div class="sub-link"><a href="#building-ghostscript">Building Ghostscript</a></div> + <div class="link"><a href="#specifying-the-ghostscript-shared-library">Specifying the Ghostscript shared library</a></div> + <div class="link"><a href="#api-test">API test</a></div> + </div> + + </div> + + <footer></footer> + + </body> + +</html> |