Skip to content

A utility for converting pdf to image and base64 format.

License

Notifications You must be signed in to change notification settings

NoMoreViolence/pdf2image

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

80 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PDF2Pic

Build Status Version
A utility for converting pdf to image and base64 format.

Prerequisite

  • node >= 4.1.2
  • graphicsmagick

Features

  • converts pdf to image, duh.
  • converts pdf to base64.

Dependencies

  • bluebird
  • fs-extra
  • gm
  • gm-base64

Installation

npm install -S pdf2pic

Usage

let PDF2Pic = require('pdf2pic').default
let converter = new PDF2Pic({
    density: 100,           // output pixels per inch
    savename: "untitled",   // output file name
    savedir: "./images",    // output file location
    format: "png",          // output file format
    size: 600               // output size in pixels
})

// by default the first page of the pdf will be converted
// to image
converter.convert("/path/to/pdf/sample.pdf")
         .then(resolve => {
             console.log("image converted successfully")
         })

// or you can also convert bulk
// in this example we will only convert pages 1 4 and 6
converter.convertBulk("path/to/pdf/sample.pdf", [1,4,6])
         .then(resolve => {
             console.log("image converted successfully")
         })


// fuck it, we can also convert all pages to pdf by
// supplying -1 as second argument
converter.convertBulk("path/to/pdf/sample.pdf", -1)
         .then(resolve => {
             console.log("image converted successfully")
         })


// you can also directly convert pdf to base64 of an image
converter.convertToBase64("path/to/pdf/sample.pdf")
         .then(resolve => {
             if(resolve.base64) {
                 // assuming you're using some ORM to save base64 to db
                 db.model.table('users').update({id: "1", image: resolve.base64})
             }
         })

Issues

  • running convert() after running convertToBase64() doesn't save the file.

About

A utility for converting pdf to image and base64 format.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%