Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

pdf2img-promises

jonathas1.5kMIT0.7.3

A Node.js module for converting a pdf into an image file, using Promises

pdf to image, pdf to jpg, pdf to png

readme

node-pdf2img-promises

Build Status

A Node.js module for converting a pdf into an image file, using Promises.

This module is based on pdf2img by Fitra Aditya.

  • It was completely refactored to use async/await instead of callbacks
  • Error handling was improved
  • The async lib dependency was removed
  • An option to inform the desired image quality was implemented
  • The lib is now an EventEmitter, so you can listen to the file conversion progress

Dependencies

These dependencies must be installed on your server, as the gm package uses them:

  • GraphicsMagick
  • GhostScript

Installation

  $ npm install pdf2img-promises

Usage

const fs      = require('fs');
const path    = require('path');
const Pdf2Img = require('pdf2img-promises');

const input   = __dirname + '/test.pdf';
const fileName = 'test';

const converter = new Pdf2Img();

// The event emitter is emitting to the file name
converter.on(fileName, (msg) => {
  console.log('Received: ', msg);
});

converter.setOptions({
  type: 'png',                                // png or jpg, default jpg
  size: 1024,                                 // default 1024
  density: 600,                               // default 600
  quality: 100,                               // default 100
  outputdir: `${__dirname}${path.sep}output`, // output folder, default null (if null given, then it will create folder name same as file name)
  outputname: fileName,                       // output file name, dafault null (if null given, then it will create image name same as input name)
  page: null                                  // convert selected page, default null (if null given, then it will convert all pages)
});

converter.convert(input)
  .then(info => {
    console.log(info);
  })
  .catch(err => {
    console.error(err);
  })

It will return array of splitted and converted image files.

{ result: 'success',
  message: 
   [ { page: 1,
       name: 'test_1.jpg',
       size: 17.275,
       path: '/output/test_1.jpg' },
     { page: 2,
       name: 'test_2.jpg',
       size: 24.518,
       path: '/output/test_2.jpg' },
     { page: 3,
       name: 'test_3.jpg',
       size: 24.055,
       path: '/output/test_3.jpg' } ] }

Maintainer

Jon Ribeiro

License

MIT

changelog

Changelog

All notable changes to this project will be documented in this file. Dates are displayed in UTC.

Generated by auto-changelog.

0.7.3

  • chore(release): removing .github directory from the release 1f59412

0.7.2

7 January 2023

  • chore: updates in release-it config 9dcd72a
  • chore: added github files ccc06df
  • chore(release): 0.7.2 de8aa92

0.7.1

7 January 2023

  • refactor: changes after eslint 16766aa
  • docs: added the changelog file d6a5b67
  • chore(release): 0.7.1 6464ba1

0.7.0

7 January 2023

  • chore(deps): bump handlebars from 4.0.11 to 4.7.7 #4
  • chore(deps): bump minimatch from 3.0.4 to 5.0.1 #7
  • chore(deps): bump path-parse from 1.0.5 to 1.0.7 #2
  • chore(deps): bump lodash from 4.17.4 to 4.17.21 #3
  • chore(deps): bump minimist, mkdirp, handlebars and mocha #5
  • feat: handle exception throw from inputStream #1
  • chore: release process with release-it b353cc9
  • chore(deps-dev): security updates for libs 14411fb
  • Started using the mime package in order to detect the file type properly ec3818e

0.6.5

27 November 2017

0.6.3

27 November 2017

  • Added istanbul code coverage 2012282
  • Wrote more tests to handle the errors 19cdd06
  • Implemented the quality option for the generated images 476701f

0.6.1

9 November 2017

v0.6.1

9 November 2017

  • Update README.md. Add instruction for windows users. #31
  • Fixed using gm as node_module to identify pages #29
  • feature: add options.page #26
  • Remove async lib dependency 0ddcd37
  • Refactor the lib to async/await and refactor the tests 8471ef6
  • Refactoring module, fix some issues regarding to zero output. f149e57

0.2.0

5 July 2016

  • Proper error handling cd39a62
  • Change indentation to two spaces. 1aab243
  • Remove pdfinfo as dependency. a47bd8e

0.1.2

29 January 2016

  • Issue #1 #2
  • try to fix test f3806be
  • install dependencies: graphicsmagick and imagemagick 3814df6
  • Issue #1 8e74523

0.1.1

24 February 2015

0.1.0

24 February 2015