pdf-image
Provides an interface to convert PDF's pages to png files in Node.js by using ImageMagick.
Installation
npm install pdf-image
Ensure you have convert
, gs
, and pdfinfo
(part of poppler) commands.
Ubuntu
sudo apt-get install imagemagick ghostscript poppler-utils
OSX (Yosemite)
brew install imagemagick ghostscript poppler
Usage
Convert single page:
var PDFImage = PDFImage; var pdfImage = "/tmp/slide.pdf";pdfImage;
Convert full file
var PDFImage = PDFImage; var pdfImage = "/tmp/slide.pdf";pdfImage;
Convert full file and merge result into single image
var PDFImage = PDFImage;var pdfImage = "/tmp/slide.pdf" combinedImage: true; pdfImage;
Express
Following example shows an example of pdf-image in Express, which gives
URLs for each pages of a PDF like
http://example.com:3000/tmp/slide.pdf/0.png
.
app;
Options
Following example shows an example of how to add imagemagick command-line options (you can find the complete list here -> http://www.imagemagick.org/script/convert.php):
var pdfImage = pdfPath convertOptions: "-resize": "2000x2000" "-quality": "75" ;