GithubHelp home page GithubHelp logo

dreamjob0415 / pdf2image Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yakovmeister/pdf2image

0.0 0.0 0.0 44.18 MB

A utility for converting pdf to image and base64 format.

License: MIT License

JavaScript 1.41% TypeScript 98.59%

pdf2image's Introduction

PDF2Pic

Donate Build Status CodeFactor Maintainability Test Coverage install size NPM Version License Known Vulnerabilities Downloads Stats

A utility for converting pdf to image and base64 format.

IMPORTANT NOTE: Please support this library by donating via PayPal, your help is much appreciated. Contributors are also welcome!

Prerequisite

  • node >= 12.x
  • graphicsmagick
  • ghostscript

Don't have graphicsmagick and ghostscript yet?

Follow this guide to install the required dependencies.

Installation

npm install -S pdf2pic

Usage

Converting specific page of PDF from path, then saving as image file

import { fromPath } from "pdf2pic";

const options = {
  density: 100,
  saveFilename: "untitled",
  savePath: "./images",
  format: "png",
  width: 600,
  height: 600
};
const storeAsImage = fromPath("/path/to/pdf/sample.pdf", options);
const pageToConvertAsImage = 1;

storeAsImage(pageToConvertAsImage).then((resolve) => {
  console.log("Page 1 is now converted as image");

  return resolve;
});

Nuff talk, show me how:

More usage example can be found here.

pdf2pic API

fromPath(filePath, options)

Initialize PDF to image conversion by supplying a file path

Functions

Convert a specific page of the PDF to Image/Base64 by supplying a file path

fromPath(filePath, options)(page, isBase64)
  • filePath - pdf file's path
  • options - see options.
  • page - page number to convert to an image
  • isBase64 - if true, convert() will return base64 output instead

Converts PDF to Image/Base64 by supplying a file path

fromPath(filePath, options).bulk(pages, isBase64)
  • filePath - pdf file's path
  • options - see options.
  • pages - page numbers to convert to image
    • set pages to -1 to convert all pages
    • pages also accepts an array indicating the page number e.g. [1,2,3]
    • also accepts number e.g. 1
  • isBase64 - if true, bulk() will return an array of base64 output instead

Set GraphicsMagick's subclass or path

fromPath(filePath, options).setGMClass(subClass)  

NOTE: should be called before calling convert() or bulk().

  • filePath - pdf file's path
  • options - see options.
  • subClass - path to gm binary or set to true to use imagemagick
    • set subClass to true to use imagemagick
    • supply a valid path as subClass to locate gm path specified

fromBuffer(buffer, options)

Initialize PDF to image conversion by supplying a PDF buffer

Functions

Convert a specific page of the PDF to Image/Base64 by supplying a buffer

fromBuffer(buffer, options)(page, isBase64)

Functions same as fromPath(filePath, options)(page, isBase64) only input is changed


Converts PDF to Image/Base64 by supplying a buffer

fromBuffer(buffer, options).bulk(pages, isBase64)

Functions same as fromPath(filePath, options).bulk(pages, isBase64) only input is changed


Set GraphicsMagick's subclass or path

fromBuffer(buffer, options).setGMClass(subClass)  

Functions same as fromPath(filePath, options).setGMClass(subClass) only input is changed


fromBase64(b64string, options)

Initialize PDF to image conversion by supplying a PDF base64 string

Functions

Convert a specific page of the PDF to Image/Base64 by supplying a base64 string

fromBase64(b64string, options)(page, isBase64)

Functions same as fromPath(filePath, options)(page, isBase64) only input is changed


Converts PDF to Image/Base64 by supplying a base64 string

fromBase64(b64string, options).bulk(pages, isBase64)

Functions same as fromPath(filePath, options).bulk(pages, isBase64) only input is changed


Set GraphicsMagick's subclass or path

fromBase64(b64string, options).setGMClass(subClass)  

Functions same as fromPath(filePath, options).setGMClass(subClass) only input is changed.


options

Following are the options that can be passed on the pdf2pic api:

option default value description
quality 0 Image compression level. Value depends on format, usually from 0 to 100 (more info)
format 'png' Formatted image characteristics / image format (image characteristics, image format)
width 768 Output width
height 512 Output height
density 72 Output DPI (dots per inch) (more info)
savePath './' Path where to save the output
saveFilename 'untitled' Output filename
compression 'jpeg' Compression method (more info)

Contributing

  • Fork it (https://github.com/yakovmeister/pdf2image/fork)
  • Create your feature branch (git checkout -b feature/make-maintainer-cry)
  • Commit your changes (git commit -am 'feature: make maintainer cry by running git rm -rf')
  • Push to the branch (git push origin feature/make-maintainer-cry)
  • Create a new PR

License

pdf2pic is MIT licensed.

pdf2image's People

Contributors

amauryliet avatar clauzzz avatar dependabot-preview[bot] avatar dependabot[bot] avatar ftorto avatar greenkeeper[bot] avatar guillaumegarcia13 avatar hadrien-f avatar javi avatar marcesengel avatar mrichtsfeld avatar mskec avatar nomoreviolence avatar sdg9670 avatar sebikeller avatar yakovmeister 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.