Coder Social home page Coder Social logo

pdf2image's Introduction

PDF2Pic

Donate Greenkeeper badge Build Status NPM Version Downloads Stats
A utility for converting pdf to image and base64 format.

Prerequisite

  • node >= 8.x
  • graphicsmagick
  • ghostscript

Features

  • converts pdf to image.
  • converts pdf to base64.
  • customizable output.
  • customizable image quality.

Dependencies

  • fs-extra
  • gm
  • gm-base64

Installation

npm install -S pdf2pic

Usage

Basic

const PDF2Pic = require("pdf2pic");

const pdf2pic = new PDF2Pic({
  density: 100,           // output pixels per inch
  savename: "untitled",   // output file name
  savedir: "./images",    // output file location
  format: "png",          // output file format
  size: "600x600"         // output size in pixels
});

pdf2pic.convert("/path/to/pdf/sample.pdf").then((resolve) => {
  console.log("image converter successfully!");

  return resolve;
});

Convert all pages

const PDF2Pic = require("pdf2pic");

const pdf2pic = new PDF2Pic({
  density: 100,           // output pixels per inch
  savename: "untitled",   // output file name
  savedir: "./images",    // output file location
  format: "png",          // output file format
  size: "600x600"         // output size in pixels
});

pdf2pic.convertBulk("path/to/pdf/sample.pdf", -1).then((resolve) => {
  console.log("image converter successfully!");

  return resolve;
});

Multiple page conversion (specific pages)

const PDF2Pic = require("pdf2pic");

const pdf2pic = new PDF2Pic({
  density: 100,           // output pixels per inch
  savename: "untitled",   // output file name
  savedir: "./images",    // output file location
  format: "png",          // output file format
  size: "600x600"         // output size in pixels
});

pdf2pic.convertBulk("path/to/pdf/sample.pdf", [1,4,6]).then((resolve) => {
  console.log("image converter successfully!");

  return resolve;
});

Convert pdf to base64 string of an image

const PDF2Pic = require("pdf2pic");

const pdf2pic = new PDF2Pic({
  density: 100,           // output pixels per inch
  savename: "untitled",   // output file name
  savedir: "./images",    // output file location
  format: "png",          // output file format
  size: "600x600"         // output size in pixels
});

pdf2pic.convertToBase64("path/to/pdf/sample.pdf").then((resolve) => {
  if (resolve.base64) {
    console.log("image converter successfully!");

    // assuming you're using some ORM to save base64 to db
    return db.model.table('users').update({id: "1", image: resolve.base64});
  }
});

pdf2image's People

Contributors

yakovmeister avatar greenkeeper[bot] avatar amauryliet avatar clauzzz avatar javi avatar nomoreviolence avatar sebikeller avatar ftorto avatar yhanwen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.