Sign inSign up

nexushubs/pdf2image

By nexushubs

•Updated about 7 years ago

RESTful api for converting pdf to images using ghostscript.

Image
0

409

nexushubs/pdf2image repository overview

⁠pdf2image

RESTful api for converting pdf to images using ghostscript.

⁠Services

ServicePortDescription
RESTful API3000Uploading file, download images
MQTT1833Subscribing converting status

⁠Uploading

POST /api/v1/pdf2image?<query-parameters>
⁠Query Parameters
NameDefaultDescription
devicepngalphavalues: png16m, pnggray, png256, png16, pngmono, pngmonod, pngalpha
res450original sample resolution
downScaleFactor3down sample factor
backgroundColornoneHEX color, e.g. ffffff

The final resolution would be res / downScaleFactor e.g. 450 / 3 is 150 dpi.

⁠Body
  • files PDF file(s)
⁠Response
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;
}
⁠Subscribing Converting Status

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`

⁠Reference

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.

Tag summary

Content type

Image

Digest

Size

389 MB

Last updated

about 7 years ago

docker pull nexushubs/pdf2image