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 🙏

© 2026 – Pkg Stats / Ryan Hefner

pdf2thumbnail

v2.0.0

Published

Fast, flexible PDF thumbnail generation for Node.js — per-page images, merged strips, and ZIP archives.

Downloads

100

Readme

pdf2thumbnail

hero

Fast, flexible PDF thumbnail generation for Node.js. Convert PDF pages into images, merge them into a single strip, and optionally archive everything as a ZIP.

npm version License: MIT

Requirements

ImageMagick CLI tools must be installed on your system.

macOS (Homebrew):

brew install imagemagick

Linux (apt):

sudo apt-get install imagemagick

Linux (yum):

sudo yum -y install ImageMagick

Supported Platforms

  • Linux
  • macOS

Installation

npm install pdf2thumbnail

Quick Start

import {writeThumbnails, getTotalNumberOfPages} from 'pdf2thumbnail';

// Generate thumbnails for all pages
const result = await writeThumbnails('report.pdf', './thumbnails');
console.log(result.thumbnailPaths); // ['./thumbnails/report_1.jpg', './thumbnails/report_2.jpg', ...]
console.log(result.mergedPath);     // './thumbnails/report.jpg'

// Get the total page count
const pages = await getTotalNumberOfPages('report.pdf');
console.log(pages); // 12

API

getTotalNumberOfPages(pdfPathOrDataUrl)

Returns the total number of pages in a PDF document.

Parameters

| Name | Type | Description | |------|------|-------------| | pdfPathOrDataUrl | string | Path to a PDF file, or a PDF encoded as a DataURL string. |

Returns Promise<number>

import {getTotalNumberOfPages} from 'pdf2thumbnail';

// From a file path
const totalFromFile = await getTotalNumberOfPages('/docs/report.pdf');

// From a DataURL
const totalFromDataUrl = await getTotalNumberOfPages('data:application/pdf;base64,...');

writeThumbnails(pdfPathOrDataUrl, outputDir, options?)

Generates thumbnail images for each page of a PDF document. Each page becomes an individual image. All thumbnails are also merged into a single vertically-stacked image. Optionally creates a ZIP archive.

Parameters

| Name | Type | Default | Description | |------|------|---------|-------------| | pdfPathOrDataUrl | string | | Path to a PDF file, or a DataURL string. | | outputDir | string | | Directory where thumbnails will be saved. Created automatically if it doesn't exist. | | options.width | number | 595 | Width of each thumbnail in pixels. Height is calculated automatically. | | options.quality | number | 100 | Image quality (1-100). | | options.format | string | 'jpg' | Output format (e.g. 'jpg', 'png'). | | options.xDensity | number | 288 | Horizontal resolution in DPI for PDF rasterization. | | options.yDensity | number | 288 | Vertical resolution in DPI for PDF rasterization. | | options.start | number | | Starting page number (1-based). | | options.end | number | | Ending page number (1-based). | | options.archive | boolean | false | Generate a ZIP archive of all thumbnails. | | options.background | string | '#fff' | Background color of the merged image. Accepts color names, hex, rgb(), etc. | | options.offset | number | 0 | Spacing in pixels between thumbnails in the merged image. |

Returns Promise<ThumbnailResult>

interface ThumbnailResult {
  thumbnailPaths: string[];  // Paths to individual page thumbnails
  mergedPath: string;        // Path to the merged image
  archivePath?: string;      // Path to the ZIP archive (when archive: true)
}

Examples

import {writeThumbnails} from 'pdf2thumbnail';

// All pages with default settings
const result = await writeThumbnails('presentation.pdf', './output');

// Custom quality and format
await writeThumbnails('presentation.pdf', './output', {
  width: 300,
  quality: 80,
  format: 'png',
});

// Specific page range (pages 2 through 5)
await writeThumbnails('presentation.pdf', './output', {
  start: 2,
  end: 5,
});

// With ZIP archive and custom merged image styling
const archived = await writeThumbnails('presentation.pdf', './output', {
  archive: true,
  background: '#f0f0f0',
  offset: 10,
});
console.log(archived.archivePath); // './output.zip'

Testing

npm test

Changelog

See CHANGELOG.md for release history.

Author

shumatsumonobu

License

MIT