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

pdf-to-image-generator

v0.0.9

Published

Performant Node.js library to convert PDF file/buffer pages to PNG or JPEG files/buffers.

Downloads

403

Readme

pdf-to-image-generator

Performant and lightweight Node.js library to convert PDF file/buffer pages to PNG or JPEG files/buffers without binary and OS dependencies (except MacOs on arm64). Designed with high focus on performance and developer experience.

Getting started

Package installation

Installation:

npm install pdf-to-image-generator

MacOs M1 prerequisites

MacOs M1 dependencies prerequisites installation:

arch -arm64 brew install pkg-config cairo pango libpng librsvg

Documentation

Find the complete documentation here.

Example

// The path of your local PDF
const filePath = path.join(__dirname, '../my_document.pdf');
// Conversion options
const options: PDFToIMGOptions = {
  // the name of the folder where files will be rendered
  outputFolderName: 'upload',
  // controls scaling
  viewportScale: 2,
  // disable streams
  disableStreams: true,
};

// Load the pdf file
const pdf = await new PDFToImage().load(filePath);

setTimeout(() => {
  // Simulating a user pausing the conversion flows
  pdf.pause();

  setTimeout(async () => {
    // Resume conversion flows
    await pdf.resume();
  }, 500);
}, 500);

// Listen to a progression event
pdf.on('progress', (data) => {
  console.log(
    `Page: ${data.currentPage}. Total: ${data.totalPages}. Progression: ${data.progress}%`
  );
});

// Notification of end of conversion
pdf.on('end', (data) => {
  console.log('End of conversion.', data);
});

// Convert your PDF to image
const pdf = await pdfConversion.convert(options);
// Other conversion flows with the same pdf but different options

Developer experience

Focus on developer experience. Properties and methods are exhaustively documented and typed. Use your IDE's autocompletion or hover on properties and methods for help.

File a bug, got a new idea, or want to contribute?

Feel free! Open a ticket.

Changelog

V0.0.3: [MINOR] API changes. Exposing the text content in a separate method. Width and height have been removed from the returned object of conversion.

V0.0.5: [MINOR] Exposing the name of the file in the getTextContent method.

V0.0.6: [MAJOR] API changes, giving more flexibility and offering a cleaner way of options initialisation. Adding pausing, resume and stop methods to give more control over the conversion flow. Adding progression and end events.

V0.0.7: [MINOR] Removal of possible duplicate page index in the option provided by the user and adding verification.

V0.0.8: [MINOR] Addition of a method to remove generated images on disk. Addition of a getter for accessing the loaded pdf document and all its methods. Minor changes to the returned object of conversion.

V0.0.9: [MINOR] Bug path correction.

Discover others libraries

All libraries are permanently supported. Discover them here.