{"id":15296117,"url":"https://github.com/nicknaso/ghostscript4js","last_synced_at":"2025-06-21T00:08:01.837Z","repository":{"id":57250958,"uuid":"71713640","full_name":"NickNaso/ghostscript4js","owner":"NickNaso","description":"Ghostscript4JS binds the Ghostscript C API to the Node.JS world.","archived":false,"fork":false,"pushed_at":"2024-06-24T14:00:36.000Z","size":374,"stargazers_count":72,"open_issues_count":10,"forks_count":19,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-06-21T00:04:33.417Z","etag":null,"topics":["addon","cplusplus","ghostscript","javascript","native","nodejs"],"latest_commit_sha":null,"homepage":"http://www.nacios.it","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NickNaso.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-10-23T16:02:26.000Z","updated_at":"2025-06-20T04:38:32.000Z","dependencies_parsed_at":"2024-10-15T01:20:51.885Z","dependency_job_id":null,"html_url":"https://github.com/NickNaso/ghostscript4js","commit_stats":{"total_commits":185,"total_committers":11,"mean_commits":"16.818181818181817","dds":"0.15135135135135136","last_synced_commit":"a6e4d973acc94de3580a8e1084e2e3ff278cc8b9"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/NickNaso/ghostscript4js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NickNaso%2Fghostscript4js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NickNaso%2Fghostscript4js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NickNaso%2Fghostscript4js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NickNaso%2Fghostscript4js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NickNaso","download_url":"https://codeload.github.com/NickNaso/ghostscript4js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NickNaso%2Fghostscript4js/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261039105,"owners_count":23100975,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["addon","cplusplus","ghostscript","javascript","native","nodejs"],"created_at":"2024-09-30T18:09:26.802Z","updated_at":"2025-06-21T00:07:56.818Z","avatar_url":"https://github.com/NickNaso.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://raw.githubusercontent.com/NickNaso/ghostscript4js/master/node-love-ghostscript.png\"/\u003e\n\u003c/p\u003e\n\n# Ghostscript4JS\n## This module binds the Ghostscript C API to bring its power to the Node.JS world\n\n* [Introduction](#introduction)\n* [Motivations](#motivations)\n* [Prerequisites](#prerequisites)\n* [Installation](#install)\n* [Installation options](#installoptions)\n* [Usage](#usage)\n* [Docker](#docker)\n* [Code of conduct](CODE_OF_CONDUCT.md)\n* [Team](#team)\n* [Acknowledgements](#acknowledgements)\n* [License](#license)\n\n\n\u003ca name=\"introduction\"\u003e\u003c/a\u003e\n\n## Introduction\n\n**Ghostscript** is a suite of software based on an interpreter for Adobe Systems' PostScript and Portable Document Format (PDF)\npage description languages. Its main purposes are the rasterization or rendering of such page description language files,\nfor the display or printing of document pages, and the conversion between PostScript and PDF files.\n\nGhostscript can be used as a raster image processor (RIP) for raster computer printers—for instance, as an input filter\nof line printer daemon—or as the RIP engine behind PostScript and PDF viewers.\n\nGhostscript can also be used as a file format converter, such as PostScript to PDF converter. The **ps2pdf** conversion program,\nwhich comes with the ghostscript distribution, is described by its documentation as a \"work-alike for nearly all the functionality\n(but not the user interface) of Adobe's Acrobat Distiller product\".[3] This converter is basically a thin wrapper around\nghostscript's pdfwrite output device, which supports PDF/A-1 and PDF/A-2 as well as PDF/X-3 output.[3]\n\nGhostscript can also serve as the back-end for **PDF** to **raster image** (png, tiff, jpeg, etc.) converter; this is often\ncombined with a PostScript printer driver in \"virtual printer\" PDF creators.\n\nAs it takes the form of a language interpreter, Ghostscript can also be used as a general purpose programming environment.\n\nGhostscript has been ported to many operating systems, including Unix-like systems, classic **Mac OS**, **OpenVMS**, **Microsoft Windows**,\n**Plan 9**, **MS-DOS**, **FreeDOS**, **OS/2**, **Atari TOS and AmigaOS**.\n\n### More resource and info about Ghostscript\n\n* [Introduction to Ghostscript](https://www.gnu.org/software/ghostscript/intro.html)\n\n* [Ghostscript on Wikipedia](https://en.wikipedia.org/wiki/Ghostscript)\n\n* [Ghostscript documentation](https://www.ghostscript.com/Documentation.html)\n\n\u003ca name=\"motivations\"\u003e\u003c/a\u003e\n\n## Motivations\n\nAt the time i created this module i was not able to find any module on npm that execute Ghostscript command through its C API,\notherwise there were some module that call Ghostscript through the execution of the corresponding shell command. This is a\ngood way to start using some library from node, but there are the following drawbacks:\n\n* **Performance** - The call to the shell command take more time and more resources than calling a library C or C++ API directly from Node.js environment.\n\n* **Errror handler** - Sometimes you cannot intercept and handle errors in a good and a proper way.\n\nTo fit all needs Ghostscript4JS has sync and async methods so it could be used in a web application where it's very important\nto not block the event loop, so all requests will be served without any delay originated by our application.\n\n[Understanding Node.js event loop](https://nodesource.com/blog/understanding-the-nodejs-event-loop/)\n\n\u003ca name=\"prerequisites\"\u003e\u003c/a\u003e\n\n## Prerequisites\n\nBefore installing Ghostscript4JS you need to assure you have the following prerequisites:\n\n* **Node.JS** see: [Installing Node.js via package manager](https://nodejs.org/en/download/package-manager/)\n\n* **Node.js native addon build tool** see: [node-gyp](https://github.com/nodejs/node-gyp)\n\n* **Ghostscript** for your Operating System.\n\n## At moment Ghostscript4JS is fully compatible with Ghostscript from version 9.19 to 9.50\n\n## Linux\n\n### Debian systems\n\nInstall Ghostscript\n\n```bash\napt-get install ghostscript libgs-dev\n```\n\nAt this point you need to set the enviroment variable **GS4JS_HOME** to  ```/usr/lib/x86_64-linux-gnu```\n\n### Red Hat | Fedora\n\n```bash\nyum install ghostscript ghostscript-devel\n```\n\nAt this point you need to set the enviroment variable **GS4JS_HOME** to  ```/usr/lib64``` or ```/usr/lib``` based on you architecture\n\n### Arch Linux\n```\npacman -S ghostscript\n```\nAt this point you need to set the enviroment variable **GS4JS_HOME** to  ```/usr/lib```\n\n### Alpine\n```\napk add ghostscript\n```\nAt this point you need to set the enviroment variable **GS4JS_HOME** to  ```/usr/lib```\n\nIn general, based on your Linux OS and architecture, you have to set the environment variable **GS4JS_HOME** to point on folder containing ```libgs.so``` library.\n\n## Windows\n\n* Download last Ghostscript version for your platform [x86](https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs920/gs920w32.exe) or [x64](https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs920/gs920w64.exe)\n\n* Install Ghostscript on your system, for example in ```C:\\gs```\n\n* Add the environment variable **GS4JS_HOME** to point to a folder containing Ghostscript's DLL and Library files (Es. gsdll64.dll and gsdll64.lib). Typically, they are located in **bin** folder of you ghostscript installation, for example ```C:\\gs\\bin```\n\n## macOS\n\n* Install Homebrew following the official guide [here](https://brew.sh/index_it.html)\n\n* Open terminal and install Ghostscript\n\n```bash\nbrew install ghostscript\n```\n\n* Set the environment variable **GS4JS_HOME** to ```/usr/local/lib```\n\n## Official installation guide to install Ghostscript\n\n* [Installation from official documentation](https://ghostscript.com/doc/current/Install.htm)\n\n* [Download Ghostscript](https://ghostscript.com/download/gsdnld.html)\n\n\u003ca name=\"install\"\u003e\u003c/a\u003e\n\n## Installation\n\nIf you want to use ghostscript4js you have to install it. There are two methods for that:\n\nIn dependencies of your ```package.json``` add the following item:\n\n```json\n\"ghostscript4js\": \"version\"\n```\n\nthen digit\n\n```console\nnpm install\n```\n\n**Example**:\n\n```json\n\"ghostscript4js\": \"*\" for the latest version\n\"ghostscript4js\": \"1.0.0\" for the version 1.0.0\n```\n\n**OR**\n\nlaunch this command:\n\n```console\nnpm install ghostscript4js --save\n```\n\n\u003ca name=\"installoptions\"\u003e\u003c/a\u003e\n\n## Installation options\n\nThe module ghostscript4js allows you to use some installation options that you can use when in your operating system something is different against standard installation.\n\n**--GS4JS_HOME** Set the GS4JS_HOME variable that represents the path in your system where is located the ghostscript library\n\nEs. ```npm install ghostscript4js --GS4JS_HOME=\"C:/gs/bin\"```\n\n**--GS4JS_LIB** Set the GS4JS_LIB variable that represents the file name for the ghostscript library installed in your system\n\nEs. ```npm install ghostscript4js --GS4JS_LIB=\"libgs.so\"```\n\n### Only for Windows\n\n**--GS4JS_DLL** Set the GS4JS_DLL variable that represents the file name for the ghostscript DLL installed in your windows system\n\nEs. ```npm install ghostscript4js --GS4JS_DLL=\"gsdll64.dll\"```\n\n\u003ca name=\"usage\"\u003e\u003c/a\u003e\n\n## Usage\n\n```js\n'use strict'\n\nconst gs = require('ghostscript4js')\n\ntry {\n  // Take decision based on Ghostscript version\n  const version = gs.version()\n  console.log(version)\n  gs.executeSync('-sDEVICE=pngalpha -o my.png -sDEVICE=pngalpha -r144 my.pdf')\n} catch (err) {\n  // Handle error\n  throw err\n}\n```\n\n## API\n\n### version\n\n**version()** method returns an object that contains information about version of Ghostscript library\ninstalled on the system. It is important in those circumstances where you have to take\ndecision based on different version.\nThe returned data are similar to the example repoted below:\n\n```js\n{\n  product: \"GPL Ghostscript\",\n  copyright: \"Copyright (C) 2016 Artifex Software, Inc.  All rights reserved.\",\n  revision: 919,\n  revisiondate: 20160323\n}\n```\n\nThis is a synchronous method and returns the version info or throws an Error to indicate that\nsomething went wrong during its execution.\n\n#### Example - version\n\n```js\n'use strict'\n\nconst gs = require('ghostscript4js')\n\ntry {\n  const version = gs.version()\n  console.log(version)\n  // Take decision based on Ghostscript version\n  if (version.revision \u003e 916) {\n    // ... some stuff\n  } else {\n    // ... other stuff\n  }\n} catch (err) {\n  // Handle error\n  throw err\n}\n```\n\n### executeSync\n\n**executeSync(cmd)** method takes the Ghostscript command parameters in input as a string or array of strings and executes in a synchronous way.\nIf something wrong happens in calling this method an Error with description and code error will be thrown.\n\n#### Example - executeSync\n\n```js\n'use strict'\n\nconst gs = require('ghostscript4js')\n\ntry {\n  gs.executeSync('-sDEVICE=pngalpha -o my.png -sDEVICE=pngalpha -r144 my.pdf')\n} catch (err) {\n  // Handle error\n  throw err\n}\n```\n\n### execute\n\n**execute(cmd, callback)** method takes in input the Ghostscript command parameters as a string or array of strings and an optional callback. The execution will be asynchronous so this ensure better performance especially in a web application enviroment, because it'll not block the Node.Js event loop.\nThis method has an optional callback function as input, in that case, a possible error will be handled by this function. If noone function will be provided the method returns a Promise that will be resolved or rejected as reported in the following example.\n\n#### Example - execute\n\n```js\n'use strict'\n\nconst gs = require('ghostscript4js')\n\nlet cmd = '-sDEVICE=pngalpha -o my.png -sDEVICE=pngalpha -r144 my.pdf'\ngs.execute(cmd, function (err) {\n  if (err) {\n    console.log(\"Ooops... something wrong happened\")\n  }\n})\n\n```\n\n```js\n'use strict'\n\nconst gs = require('ghostscript4js')\n\nlet cmd = '-sDEVICE=pngalpha -o my.png -sDEVICE=pngalpha -r144 my.pdf'\ngs.execute(cmd)\n.then(() =\u003e {\n  console.log(\"All is ok\")\n})\n.catch((err) =\u003e {\n console.log(\"Ooops... something wrong happened\")\n})\n\n```\n\n### Error\n\nThe error raised from **ghostscript4js** in all of its method is an instance of Error object that cointains a message that\ndescribes what happened and at the same time cointains the Ghostscript error code so you can inspect what happened in a better\nway. At this link [Ghostscript error codes](https://ghostscript.com/doc/current/API.htm#return_codes) you can find all Ghostscript errors code.\n\n### Min and Max supported revision\n\nThis module was built based on Ghostscript C API that is compatible with some specifics versions. The module has two\nproperties  **MIN_SUPPORTED_REVISION** and **MAX_SUPPORTED_REVISION** which respectively indicate the minimum and maximum supported Ghostscript's version.\n\n#### Example - Min and Max supported revision\n\n```js\n'use strict'\n\nconst gs = require('ghostscript4js')\n\nconsole.log(gs.MIN_SUPPORTED_REVISION)\nconsole.log(gs.MAX_SUPPORTED_REVISION)\n\n```\n\n\u003ca name=\"docker\"\u003e\u003c/a\u003e\n\n## Docker\n\nCheck out the example `Dockerfile` in `examples/docker`. It will create an image based on node 8.x and Debian stretch.\n\nTo build the image do:\n\n\n```\ncd examples/docker\ndocker build -t ghostscript4js .\n```\n\nNow you can run the image. By default it does `npm start` (which is `node index.js`) and exits.\n\n```\ndocker run ghostscript4js\n```\n\nRunning the container should output something like:\n\n```\n{ product: 'GPL Ghostscript',\n  copyright: 'Copyright (C) 2016 Artifex Software, Inc.  All rights reserved.',\n  revision: 920,\n  revisiondate: 20160926 }\n```\n\nIf you want to look around in the container you can get a shell like:\n\n```\ndocker run -it ghostscript4js /bin/bash\ngs --version\n```\n\n\u003ca name=\"team\"\u003e\u003c/a\u003e\n\n## The Team\n\n### Nicola Del Gobbo\n\n\u003chttps://github.com/NickNaso/\u003e\n\n\u003chttps://www.npmjs.com/~nicknaso\u003e\n\n\u003chttps://twitter.com/NickNaso\u003e\n\n### Mauro Doganieri\n\n\u003chttps://github.com/mauro-d\u003e\n\n\u003chttps://www.npmjs.com/~mauro-d\u003e\n\n\u003chttps://twitter.com/maurodoganieri\u003e\n\n\u003ca name=\"acknowledgements\"\u003e\u003c/a\u003e\n\n## Acknowledgements\n\nThank you to all people that encourage me every day.\n\n\u003ca name=\"license\"\u003e\u003c/a\u003e\n\n## License\n\nLicensed under [Apache license V2](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicknaso%2Fghostscript4js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnicknaso%2Fghostscript4js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicknaso%2Fghostscript4js/lists"}