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 - npm Package Compare versions

Comparing version 1.4.0 to 2.0.0-alpha.1

dist/graphics.d.ts

94

package.json
{
"name": "pdf2pic",
"version": "1.4.0",
"types": "index.d.ts",
"version": "2.0.0-alpha.1",
"description": "A utility for converting pdf to image and base64 format.",
"main": "index.js",
"license": "MIT",
"homepage": "https://github.com/yakovmeister/pdf2image",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"dependencies": {
"fs-extra": "^9.0.1",
"gm": "^1.23.1"
},
"directories": {
"test": "test"
},
"devDependencies": {
"@rollup/plugin-alias": "^3.1.1",
"@types/chai": "^4.2.12",
"@types/fs-extra": "^9.0.1",
"@types/gm": "^1.18.9",
"@types/mocha": "^8.0.3",
"@types/node": "^14.6.4",
"@types/rimraf": "^3.0.0",
"@typescript-eslint/eslint-plugin": "^4.1.0",
"@typescript-eslint/parser": "^4.1.0",
"chai": "^4.2.0",
"eslint": "^7.8.1",
"mocha": "^8.1.3",
"nyc": "^15.1.0",
"rimraf": "^3.0.2",
"rollup": "^2.26.11",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.27.2",
"ts-node": "^9.0.0",
"tsconfig-paths": "^3.9.0",
"tslib": "^2.0.1",
"typescript": "^4.0.2"
},
"scripts": {
"mocha": "./node_modules/.bin/mocha test/**/*.test.ts",
"test": "npm run lint && nyc --reporter=lcov npm run mocha",
"rollup": "rollup -c",
"clean": "rimraf ./dist",
"lint": "./node_modules/.bin/eslint . --ext .ts",
"build": "npm run test && npm run clean && npm run rollup"
},
"repository": {
"type": "git",
"url": "https://github.com/yakovmeister/pdf2image.git"
"url": "git+https://github.com/yakovmeister/pdf2image.git"
},
"funding": {
"type": "paypal",
"url": "https://www.paypal.me/yakovmeister"
},
"scripts": {
"clean": "rimraf ./lib && mkdir lib",
"clean:test": "rimraf ./test/output && mkdir test/output",
"clean:compile": "rimraf ./lib/compiled",
"compile:rollup": "rollup -c",
"compile": "npm run clean && npm run compile:rollup && npm run clean:compile",
"test": "npm run clean:test && mocha --require @babel/register"
},
"keywords": [

@@ -39,30 +63,12 @@ "pdf-to-image",

],
"funding": {
"type": "paypal",
"url": "https://www.paypal.me/yakovmeister"
},
"author": "Jacob Baring <owari@waifu.club>",
"dependencies": {
"@babel/runtime": "^7.8.7",
"fs-extra": "^8.1.0",
"gm": "^1.23.0",
"gm-base64": "^1.1.1"
"license": "MIT",
"bugs": {
"url": "https://github.com/yakovmeister/pdf2image/issues"
},
"devDependencies": {
"@babel/cli": "^7.8.4",
"@babel/core": "^7.8.7",
"@babel/plugin-external-helpers": "^7.8.3",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/plugin-proposal-object-rest-spread": "^7.9.5",
"@babel/plugin-transform-runtime": "^7.9.0",
"@babel/preset-env": "^7.8.7",
"@babel/register": "^7.8.6",
"babel-eslint": "^10.1.0",
"babel-plugin-module-resolver": "^4.0.0",
"chai": "^4.2.0",
"eslint": "^6.6.0",
"eslint-plugin-babel": "^5.3.0",
"eslint-plugin-import": "^2.20.2",
"mocha": "^6.2.3",
"rimraf": "^3.0.2",
"rollup": "^2.0.0",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-uglify": "^6.0.4"
}
"homepage": "https://github.com/yakovmeister/pdf2image#readme"
}
# PDF2Pic
[![Donate][paypal-image]](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=938FMCPPQG4DQ&currency_code=USD&source=url)
[![Greenkeeper badge](https://badges.greenkeeper.io/yakovmeister/pdf2image.svg)](https://greenkeeper.io/)
[![Build Status][travis-image]][travis-url]
[![CodeFactor](https://www.codefactor.io/repository/github/yakovmeister/pdf2image/badge/next)](https://www.codefactor.io/repository/github/yakovmeister/pdf2image/overview/next)
[![Maintainability](https://api.codeclimate.com/v1/badges/6d7bfbae9057998bda99/maintainability)](https://codeclimate.com/github/yakovmeister/pdf2image/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/6d7bfbae9057998bda99/test_coverage)](https://codeclimate.com/github/yakovmeister/pdf2image/test_coverage)
[![install size](https://packagephobia.com/badge?p=pdf2pic)](https://packagephobia.com/result?p=pdf2pic)
[![NPM Version][npm-image]][npm-url]
[![License](https://img.shields.io/npm/l/pdf2pic?color=blue)][npm-url]
[![Known Vulnerabilities](https://snyk.io/test/npm/pdf2pic/badge.svg)](https://snyk.io/test/npm/pdf2pic)
[![Downloads Stats][npm-downloads]][npm-url]
A utility for converting pdf to image and base64 format.
> IMPORTANT NOTE: Please support this library by donating via [PayPal](https://www.paypal.com/paypalme/yakovmeister), your help is much appreciated. Contributors are also welcome!
> ANOTHER IMPORTANT NOTE: please use version 1.x for now as 2.x is still in early development stage
## Prerequisite
* node >= 8.x
* node >= 12.x
* graphicsmagick
* ghostscript
## Features
* converts pdf to image.
* converts pdf to base64.
* customizable output.
* customizable image quality.
### Don't have graphicsmagick and ghostscript yet?
## Dependencies
Follow [this](docs/gm-installation.md) guide to install the required dependencies.
* fs-extra
* gm
* gm-base64
## Installation

@@ -37,17 +37,20 @@

## Basic
### Converting specific page of PDF from path, then saving as image file
```javascript
const PDF2Pic = require("pdf2pic");
import { fromPath } from "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
});
const options = {
density: 100,
savename: "untitled",
savedir: "./images",
format: "png",
width: 600,
height: 600
};
const storeAsImage = fromPath("/path/to/pdf/sample.pdf", options);
const pageToConvertAsImage = 1;
pdf2pic.convert("/path/to/pdf/sample.pdf").then((resolve) => {
console.log("image converter successfully!");
storeAsImage(pageToConvertAsImage).then((resolve) => {
console.log("Page 1 is now converted as image");

@@ -57,19 +60,49 @@ return resolve;

```
## Convert all pages
```
### Converting specific page of PDF from path, then saving as base64 string of image
```javascript
const PDF2Pic = require("pdf2pic");
import { fromPath } from "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
const options = {
density: 100,
savename: "untitled",
savedir: "./images",
format: "png",
size: "600x600"
};
const convertPdf2Base64Image = fromPath("/path/to/pdf/sample.pdf", options);
const pageToConvertAsImage = 1;
// adding true as second parameter will transform response to base64 string
convertPdf2Base64Image(pageToConvertAsImage, true).then((resolve) => {
console.log("Page 1 is now converted as base64string");
console.log({
base64string: resolve.base64
})
return resolve;
});
pdf2pic.convertBulk("path/to/pdf/sample.pdf", -1).then((resolve) => {
console.log("image converter successfully!");
```
### Bulk conversion
```javascript
import { fromPath } from "pdf2pic";
const options = {
density: 100,
savename: "untitled",
savedir: "./images",
format: "png",
size: "600x600"
};
const convert = fromPath("/path/to/pdf/sample.pdf", options);
const pageToConvertAsImage = [4, 5]; // let's convert page 4 and 5
convert.bulk(pageToConvertAsImage).then((resolve) => {
console.log("Page 4 and 5 is now converted as image");
return resolve;

@@ -79,19 +112,25 @@ });

```
## Multiple page conversion (specific pages)
### PDF Stream input, saved as image file
```javascript
const PDF2Pic = require("pdf2pic");
import { fromBuffer } from "pdf2pic";
import { readFileSync } from "fs";
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
});
const options = {
density: 100,
savename: "untitled",
savedir: "./images",
format: "png",
size: "600x600"
};
pdf2pic.convertBulk("path/to/pdf/sample.pdf", [1,4,6]).then((resolve) => {
console.log("image converter successfully!");
const file = readFileSync("/path/to/pdf/sample.pdf", "base64");
const buff = Buffer.from(file, "base64");
const convert = fromBuffer(buff, options);
const pageToConvertAsImage = 1;
convert(pageToConvertAsImage).then((resolve) => {
console.log("Page 1 is now converted as image");
return resolve;

@@ -101,24 +140,25 @@ });

```
## Convert pdf to base64 string of an image
### PDF base64 input, saved as image file
```javascript
const PDF2Pic = require("pdf2pic");
import { fromBase64 } from "pdf2pic";
import { readFileSync } from "fs";
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
});
const options = {
density: 100,
savename: "untitled",
savedir: "./images",
format: "png",
size: "600x600"
};
pdf2pic.convertToBase64("path/to/pdf/sample.pdf").then((resolve) => {
if (resolve.base64) {
console.log("image converter successfully!");
const file = readFileSync("/path/to/pdf/sample.pdf", "base64");
// assuming you're using some ORM to save base64 to db
return db.model.table('users').update({id: "1", image: resolve.base64});
}
const convert = fromBase64(file, options);
const pageToConvertAsImage = 1;
convert(pageToConvertAsImage).then((resolve) => {
console.log("Page 1 is now converted as image");
return resolve;
});

@@ -128,2 +168,4 @@

## TO BE CONTINUED!
<!-- Markdown link & img dfn's -->

@@ -133,4 +175,4 @@ [npm-image]: https://img.shields.io/npm/v/pdf2pic.svg?style=flat-square

[npm-downloads]: https://img.shields.io/npm/dm/pdf2pic.svg?style=flat-square
[travis-image]: https://travis-ci.org/yakovmeister/pdf2image.svg?branch=1.0
[travis-image]: https://travis-ci.org/yakovmeister/pdf2image.svg?branch=next
[travis-url]: https://travis-ci.org/yakovmeister/pdf2image
[paypal-image]: https://img.shields.io/badge/Donate-PayPal-green.svg
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