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
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
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
|