Need help with node-pdf-image?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

mooz
210 Stars 78 Forks MIT License 52 Commits 37 Opened issues

Description

Provides an interface to convert PDF's pages to png files in Node.js by using ImageMagick

Services available

!
?

Need anything else?

Contributors list

# 62,614
ecmascr...
Python
Linux
keyboar...
10 commits
# 472,024
JavaScr...
5 commits
# 23,743
Go
zap
structu...
Docker
3 commits
# 520,272
JavaScr...
3 commits
# 99,984
HTML
express...
Svelte
optimiz...
1 commit
# 140,702
PHP
C
Shell
sentry
1 commit
# 297,202
CSS
HTML
Shell
1 commit
# 632,795
JavaScr...
1 commit
# 91,398
webpack...
Shell
Webpack
TypeScr...
1 commit
# 285,204
ldap
openlda...
Docker
Shell
1 commit
# 632,796
JavaScr...
1 commit
# 34,122
Elixir
email-s...
etl-fra...
curl
1 commit

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 = require("pdf-image").PDFImage;

var pdfImage = new PDFImage("/tmp/slide.pdf"); pdfImage.convertPage(0).then(function (imagePath) { // 0-th page (first page) of the slide.pdf is available as slide-0.png fs.existsSync("/tmp/slide-0.png") // => true });

Convert full file

var PDFImage = require("pdf-image").PDFImage;

var pdfImage = new PDFImage("/tmp/slide.pdf"); pdfImage.convertFile().then(function (imagePaths) { // [ /tmp/slide-0.png, /tmp/slide-1.png ] });

Convert full file and merge result into single image

var PDFImage = require("pdf-image").PDFImage;
var pdfImage = new PDFImage("/tmp/slide.pdf", {
  combinedImage: true
});

pdfImage.convertFile().then(function (imagePaths) { // /tmp/slide.png });

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.get(/(.*\.pdf)\/([0-9]+).png$/i, function (req, res) {
    var pdfPath = req.params[0];
    var pageNumber = req.params[1];

var PDFImage = require("pdf-image").PDFImage;
var pdfImage = new PDFImage(pdfPath);

pdfImage.convertPage(pageNumber).then(function (imagePath) {
  res.sendFile(imagePath);
}, function (err) {
  res.send(err, 500);
});

});

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 = new PDFImage(pdfPath, {
  convertOptions: {
    "-resize": "2000x2000",
    "-quality": "75"
  }
});

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.