File: python-intro.md

package info (click to toggle)
ghostscript 10.0.0~dfsg-11%2Bdeb12u7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 98,252 kB
  • sloc: ansic: 891,828; python: 7,649; cpp: 6,493; cs: 6,209; sh: 6,043; java: 4,028; perl: 2,372; tcl: 1,639; makefile: 521; awk: 66; javascript: 43; yacc: 18
file content (76 lines) | stat: -rw-r--r-- 2,196 bytes parent folder | download
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
# Python overview

<div class="banner">
<div class="python-text"></div>
<div class="vendor-logo python-logo"></div>
</div>

## About

The `Python` API is provided by the file [gsapi.py] - this is the binding to the Ghostscript `C` library.

In the [GhostPDL repository] sample `Python` examples can be found in `/demos/python/examples.py`.

## Platform & setup

### Building Ghostscript

Ghostscript should be built as a shared library for your platform.

See [Building Ghostscript].

## Specifying the Ghostscript shared library

Two environmental variables can be used to specify where to find the Ghostscript shared library.

`GSAPI_LIB` sets the exact path of the Ghostscript shared library, otherwise, `GSAPI_LIBDIR` sets the directory containing the Ghostscript shared library.

If neither is defined we will use the OS's default location(s) for shared libraries.

If `GSAPI_LIB` is not defined, the leafname of the shared library is inferred
from the OS type - `libgs.so` on Unix, `libgs.dylib` on MacOS, `gsdll64.dll` on Windows 64.


## API test

The `gsapi.py` file that provides the `Python` bindings can also be used to test the bindings, by running it directly.

Assuming that your Ghostscript library has successfully been created, then from the root of your `ghostpdl` checkout run:


#### Windows

<div class="tag shellCommand"> from ghostpdl</div>

```
// Run gsapi.py as a test script in a cmd.exe window:
set GSAPI_LIBDIR=debugbin&& python ./demos/python/gsapi.py

// Run gsapi.py as a test script in a PowerShell window:
cmd /C "set GSAPI_LIBDIR=debugbin&& python ./demos/python/gsapi.py"
```

#### Linux/OpenBSD/MacOS

<div class="tag shellCommand"> from ghostpdl</div>

```
// Run gsapi.py as a test script:
GSAPI_LIBDIR=sodebugbin ./demos/python/gsapi.py
```


If there are no errors then this will have validated that the Ghostscript library is present & operational.




[Python]: https://www.python.org/
[Brew]: https://brew.sh/
[GNU]: https://www.gnu.org/
[gsapi.py]: python-gsapi
[Building Ghostscript]: index.html#building-ghostscript
[display]: https://ghostscript.com/doc/current/API.htm#display


[GhostPDL repository]: https://github.com/ArtifexSoftware/ghostpdl