Find #ghostscript on Discord

# Language Bindings

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.

Before using the language bindings first ensure that Ghostscript is built for your platform before proceeding. See:

- Building with Visual Studio

- Building with MacOS

- Building with Unix

## The C API

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.

### 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.

## Demo code

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.

## C#

- Introduction
- Platform & setup
- GhostAPI
  - Structs and Enums
    - `gsapi_revision_t`
    - `gs_set_param_type`
    - `gsEncoding`
  - Constants
    - `gsConstants`
  - GSAPI
    - `gsapi_revision`
    - `gsapi_new_instance`
    - `gsapi_delete_instance`
    - `gsapi_set_stdio_with_handle`
    - `gsapi_set_stdio`
    - `gsapi_set_poll_with_handle`
    - `gsapi_set_poll`
    - `gsapi_set_display_callback`
    - `gsapi_register_callout`
    - `gsapi_deregister_callout`
    - `gsapi_set_arg_encoding`
    - `gsapi_set_default_device_list`
    - `gsapi_get_default_device_list`
    - `gsapi_init_with_args`
    - `gsapi_run_*`
    - `gsapi_run_string_begin`
    - `gsapi_run_string_continue`
    - `gsapi_run_string_with_length`
    - `gsapi_run_string`
    - `gsapi_run_string_end`
    - `gsapi_run_file`
    - `gsapi_exit`
    - `gsapi_set_param`
    - `gsapi_get_param`
    - `gsapi_enumerate_params`
    - `gsapi_add_control_path`
    - `gsapi_remove_control_path`
    - `gsapi_purge_control_paths`
    - `gsapi_activate_path_control`
    - `gsapi_is_path_control_active`
  - Callback and Callout prototypes
    - `gs_stdio_handler`
    - `gsPollHandler`
    - `gsCallOut`
- GhostNET
  - Enums
    - Tasks
    - Results
    - Status
  - The Parameter Struct
    - Parameters explained
  - The Event class
  - GSNET
    - Sample code
    - Delegates
      - `DLLProblemCallBack`
      - `StdIOCallBack`
      - `ProgressCallBack`
      - `PageRenderedCallBack`
    - `GetVersion`
    - `DisplayDeviceOpen`
    - `DisplayDeviceClose`
    - `GetPageCount`
    - `CreateXPS`
    - `DistillPS`
    - `DisplayDeviceRunFile`
    - `DisplayDeviceRenderThumbs`
    - `DisplayDeviceRenderPages`
    - `GetStatus`
    - `Cancel`
    - `GhostscriptException`
- GhostMono
  - Enums
    - Tasks
    - Results
    - Status
  - The Parameter Struct
    - Parameters explained
  - The Event class
  - GSMONO
    - Delegates
      - `DLLProblemCallBack`
      - `StdIOCallBack`
      - `ProgressCallBack`
      - `PageRenderedCallBack`
    - `GetVersion`
    - `DisplayDeviceOpen`
    - `DisplayDeviceClose`
    - `GetPageCount`
    - `DistillPS`
    - `DisplayDeviceRenderAll`
    - `DisplayDeviceRenderThumbs`
    - `DisplayDeviceRenderPages`
    - `GetStatus`
    - `GhostscriptException`

## Java

- Introduction
- Platform & setup
  - jni: Building the Java Native Interface
    - Preparing your include folder
    - Building on Windows
    - Building on MacOS
    - Building on Linux
  - gsjava: Building the JAR
    - Building with the command line
    - Building with Eclipse
    - Linking the JAR
- Demo projects
  - gstest
  - gsviewer
    - Building on Windows
    - Running on Windows
    - Building on MacOS
    - Running on MacOS
    - Building on Linux
    - Running on Linux
- Using the Java library
  - gsjava
  - GSAPI & GSInstance
  - GSAPI
    - `gsapi_revision`
      - `GSAPI.Revision`
    - `gsapi_new_instance`
    - `gsapi_delete_instance`
    - `gsapi_set_stdio_with_handle`
    - `gsapi_set_stdio`
    - `gsapi_set_poll_with_handle`
    - `gsapi_set_poll`
    - `gsapi_set_display_callback`
    - `gsapi_register_callout`
    - `gsapi_deregister_callout`
    - `gsapi_set_arg_encoding`
    - `gsapi_set_default_device_list`
    - `gsapi_get_default_device_list`
    - `gsapi_init_with_args`
    - `gsapi_run_*`
    - `gsapi_run_string_begin`
    - `gsapi_run_string_continue`
    - `gsapi_run_string_with_length`
    - `gsapi_run_string`
    - `gsapi_run_string_end`
    - `gsapi_run_file`
    - `gsapi_exit`
    - `gsapi_set_param`
    - `gsapi_get_param`
    - `gsapi_enumerate_params`
    - `gsapi_add_control_path`
    - `gsapi_remove_control_path`
    - `gsapi_purge_control_paths`
    - `gsapi_activate_path_control`
    - `gsapi_is_path_control_active`
  - Callback & Callout interfaces
    - `IStdInFunction`
    - `IStdOutFunction`
    - `IStdErrFunction`
    - `IPollFunction`
    - `ICalloutFunction`
  - GSInstance
    - Constructors
    - `delete_instance`
    - `set_stdio`
    - `set_poll`
    - `set_display_callback`
    - `register_callout`
    - `deregister_callout`
    - `set_arg_encoding`
    - `set_default_device_list`
    - `get_default_device_list`
    - `init_with_args`
    - `run_string_begin`
    - `run_string_continue`
    - `run_string`
    - `run_file`
    - `exit`
    - `set_param`
    - `get_param`
    - `enumerate_params`
    - `add_control_path`
    - `remove_control_path`
    - `purge_control_paths`
    - `activate_path_control`
    - `is_path_control_active`
  - Utility classes
    - `com.artifex.gsjava.util.Reference`

## Python

- Introduction
- Platform & setup
  - Specifying the Ghostscript shared library
  - API test
- The gsapi Python module
  - `gsapi_revision()`
  - `gsapi_new_instance(caller_handle)`
  - `gsapi_delete_instance(instance)`
  - `gsapi_set_stdio(instance, stdin_fn, stdout_fn, stderr_fn)`
  - `gsapi_set_poll(instance, poll_fn)`
  - `gsapi_set_display_callback(instance, callback)`
  - `gsapi_set_arg_encoding(instance, encoding)`
  - `gsapi_set_default_device_list(instance, list_)`
  - `gsapi_get_default_device_list(instance)`
  - `gsapi_init_with_args(instance, args)`
  - `gsapi_run_*`
  - `gsapi_run_string_begin(instance, user_errors)`
  - `gsapi_run_string_continue(instance, str_, user_errors)`
  - `gsapi_run_string_with_length(instance, str_, length, user_errors)`
  - `gsapi_run_string(instance, str_, user_errors)`
  - `gsapi_run_string_end(instance, user_errors)`
  - `gsapi_run_file(instance, filename, user_errors)`
  - `gsapi_exit(instance)`
  - `gsapi_set_param(instance, param, value, type_=None)`
  - `gsapi_get_param(instance, param, type_=None, encoding=None)`
  - `gsapi_enumerate_params(instance)`
  - `gsapi_add_control_path(instance, type_, path)`
  - `gsapi_remove_control_path(instance, type_, path)`
  - `gsapi_purge_control_paths(instance, type_)`
  - `gsapi_activate_path_control(instance, enable)`
  - `gsapi_is_path_control_active(instance)`