@tepez/pdf-to-png
v0.1.2
Published
> Convert PDF to PNG using imagemagick6
Downloads
7
Readme
pdf-to-png
Convert PDF to PNG using imagemagick6
This is essentially a small wrapper around imagemagick-stream that make it easier to use when writing tests for PDF files.
Important note - all imagemagick errors are ignored because it's very difficult to tell fatal errors from just warnings.
Install
npm install --save @tepez/pdf-to-png
Usage
const PdfToPng = require('@tepez/pdf-to-png');
const Fs = require('fs');
const pdf = Fs.readFileSync('/path/to/doc.pdf', null);
PdfToPng.pdfToPngBuffer(pdf, 0).then((png) => {
Fs.writeFileSync('/path/to/doc.png', png, null);
})
API
pdfToPngStream(pdf: Buffer | Stream.Readable, page: number): Stream.Readable;
pdfToPngBuffer(pdf: Buffer | Stream.Readable, page: number): Promise<Buffer>;
Install dependencies
Windows
- Download and install Ghostscript.
- Download ImageMagick-6.9.9-20-portable-Q16-x64.zip, extract it locally and add its directory to the system PATH.
Ubuntu
sudo apt-get install imagemagick
TODO find a way to restrict to imagemagick6 (imagemagick-6.q16 does not include the binaries)