summaryrefslogtreecommitdiff
path: root/doc/language-bindings/java-gsjavajar.html
blob: 68877f484bcfbb82d22aa99d5173267c7fe53c82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
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" href="../images/favicon.svg">
        <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 &amp; 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&lt;Long&gt; 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&lt;byte[]&gt; list,
                                         Reference&lt;Integer&gt; 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&lt;String&gt; argv);</code></pre>
<h3 id="gsapi_run_-">gsapi_run_*</h3>
<p>If these functions return <code>&lt;= -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&lt;Integer&gt; 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&lt;Integer&gt; 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&lt;Integer&gt; 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&lt;Integer&gt; 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&lt;Integer&gt; 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&lt;Integer&gt; 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&lt;Integer&gt; 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&lt;Integer&gt; 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&lt;Integer&gt; 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&lt;Integer&gt; 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 "&lt;&lt;/HWResolution [ 200.0 200.0 ]&gt;&gt;".</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&lt;Long&gt; iter,
                                   Reference&lt;byte[]&gt; key,
                                  Reference&lt;Integer&gt; 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 &amp; Callout interfaces</h2>
<p><code>gsjava.jar</code> also defines some functional interfaces for callbacks &amp; 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 &lt;code&gt;len&lt;/code&gt;/
     */
    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 &lt;code&gt;len&lt;/code&gt;.
     */
    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 &lt;code&gt;len&lt;/code&gt;.
     */
    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&lt;byte[]&gt; list,
                                   Reference&lt;Integer&gt; 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&lt;String&gt; 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&lt;Integer&gt; 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&lt;Integer&gt; pExitCode);</code></pre>
<pre><code class="language-clike">public int run_string_continue(String str,
                                  int length,
                                  int userErrors,
                   Reference&lt;Integer&gt; 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&lt;Integer&gt; pExitCode);</code></pre>
<pre><code class="language-clike">public int run_string(String str,
                         int userErrors,
          Reference&lt;Integer&gt; 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&lt;Integer&gt; pExitCode);</code></pre>
<pre><code class="language-clike">public int run_file(String filename,
                       int userErrors,
        Reference&lt;Integer&gt; 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&lt;Long&gt; iter,
                          Reference&lt;byte[]&gt; key,
                         Reference&lt;Integer&gt; 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&lt;T&gt;</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&lt;T&gt; {

    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>