RESTful api for converting pdf to images using ghostscript.
409
RESTful api for converting pdf to images using ghostscript.
| Service | Port | Description |
|---|---|---|
| RESTful API | 3000 | Uploading file, download images |
| MQTT | 1833 | Subscribing converting status |
POST /api/v1/pdf2image?<query-parameters>
| Name | Default | Description |
|---|---|---|
device | pngalpha | values: png16m, pnggray, png256, png16, pngmono, pngmonod, pngalpha |
res | 450 | original sample resolution |
downScaleFactor | 3 | down sample factor |
backgroundColor | none | HEX color, e.g. ffffff |
The final resolution would be res / downScaleFactor e.g. 450 / 3 is 150 dpi.
files PDF file(s)interface JobResult {
result: {
files: JobStatus[];
}
}
Each uploaded file has its corresponding result:
interface JobStatus {
createdAt: number;
status: 'pending' | 'done';
downloadUrl: string;
fieldname: string;
originalname: string;
encoding: string;
mimetype: string;
destination: string;
filename: string;
path: string;
size: string;
pageCount: string;
_id: string;
}
Example:
const mqtt = require('mqtt')
const client = mqtt.connect('mqtt://127.0.0.1:1833')
client.on('connect', function () {
console.log('connected');
client.subscribe('converted', function (err) {
if (err) return
client.on('message', function (topic, message) {
const result = JSON.parse(message.toString())
console.log(result)
})
})
})
The result should be the same data from uploading API, except for the status is done
When result is received, the converted image is available:
const page = 1;
const url = `http://127.0.0.1:3000${result.downloadUrl}/${page}.png`
Check Ghostscript document for more
PNG (pronounced 'ping') stands for Portable Network Graphics, and is the recommended format for high-quality images. It supports full quality color and transparency, offers excellent lossless compression of the image data, and is widely supported. Please see the PNG website for a complete description of the format.
Ghostscript provides a variety of devices for PNG output varying by bit depth. For normal use we recommend png16m for 24-bit RGB color, or pnggray for grayscale. The png256, png16 and pngmono devices respectively provide 8-bit color, 4-bit color and black-and-white for special needs. The pngmonod device is also a black-and-white device, but the output is formed from an internal 8 bit grayscale rendering which is then error diffused and converted down to 1bpp.
The pngalpha device is 32-bit RGBA color with transparency indicating pixel coverage. The background is transparent unless it has been explicitly filled. PDF 1.4 transparent files do not give a transparent background with this device. Text and graphics anti-aliasing are enabled by default.
Content type
Image
Digest
Size
389 MB
Last updated
about 7 years ago
docker pull nexushubs/pdf2image