Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pdf2pic

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pdf2pic

A utility for converting pdf to image and base64 format.

  • 1.3.9
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
84K
increased by44.88%
Maintainers
1
Weekly downloads
 
Created
Source

PDF2Pic

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

Prerequisite

  • node >= 7.x
  • graphicsmagick
  • ghostscript

Features

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

Dependencies

  • bluebird
  • 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});
  }
});

Keywords

FAQs

Package last updated on 14 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc