npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@brunofrancadasilva/pdf2pic

v3.0.13

Published

A utility for converting pdf to image formats. Supports different outputs: directly to file, base64 or buffer.

Downloads

64

Readme

pdf2pic

Forked from: https://github.com/yakovmeister/pdf2image

A utility for converting pdf to image, base64 or buffer format.

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

Prerequisites

  • node >= 14.x
  • graphicsmagick
  • ghostscript

Don't have graphicsmagick and ghostscript yet?

Follow this guide to install the required dependencies.

Installation

npm install --save 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,
  ignoreAspectRatio: false
};
const convert = fromPath("/path/to/pdf/sample.pdf", options);
const pageToConvertAsImage = 1;

convert(pageToConvertAsImage, { responseType: "image" })
  .then((resolve) => {
    console.log("Page 1 is now converted as image");

    return resolve;
  });

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/Buffer by supplying a file path

fromPath(filePath, options)(page, convertOptions)
  • filePath - pdf file's path
  • options - see options.
  • page - page number to convert to an image
  • convertOptions - see convertOptions.

Converts PDF to Image/Base64/Buffer by supplying a file path

fromPath(filePath, options).bulk(pages, convertOptions)
  • 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
  • convertOptions - see convertOptions

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/Buffer by supplying a buffer

fromBuffer(buffer, options)(page, convertOptions)

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


Converts PDF to Image/Base64/Buffer by supplying a buffer:

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

Functions same as fromPath(filePath, options).bulk(pages, convertOptions) 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/Buffer by supplying a base64 string:

fromBase64(b64string, options)(page, convertOptions)

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


Converts PDF to Image/Base64/Buffer by supplying a base64 string:

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

Functions same as fromPath(filePath, options).bulk(pages, convertOptions) 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 | | ignoreAspectRatio | false | If gm should ignore output aspect ratio | | compression | 'jpeg' | Compression method (more info) |

convertOptions

| option | default value | description | |--------------|---------------|-------------| | responseType | image | Response type of the output. Accepts: image, base64 or buffer |

The parameter can also be a boolean, if true then the response type will be base64 and if false then the response type will be image. This is deprecated and will be removed in the next major version.

License

pdf2pic is MIT licensed.