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

pdf-visual-compare

v3.4.0

Published

Visual regression testing library for PDFs in Js/Ts without binary and OS dependencies.

Readme

pdf-visual-compare


Table of Contents


Requirements

  • Node.js >= 20

Installation

npm install -D pdf-visual-compare

Usage

Basic comparison

import { comparePdf } from 'pdf-visual-compare';

const isEqual = await comparePdf('./actual.pdf', './expected.pdf');
// true  → PDFs are visually identical
// false → PDFs differ

Comparison with options

import { comparePdf } from 'pdf-visual-compare';

const isEqual = await comparePdf('./actual.pdf', './expected.pdf', {
  // Folder for diff PNG images written when differences are found. Default: ./comparePdfOutput
  diffsOutputFolder: 'test-results/diffs',

  // Maximum number of differing pixels allowed before the comparison fails.
  // 0 = pixel-perfect match required (default). Must be >= 0.
  compareThreshold: 200,

  // Per-page exclusion zones, matched by array index (0-based).
  // Index 0 → first page, index 1 → second page, etc.
  // Pixel coordinates are relative to the rendered PNG at the configured viewportScale.
  excludedAreas: [
    {
      pageNumber: 1,
      excludedAreas: [
        { x1: 700, y1: 375, x2: 790, y2: 400 }, // dynamic timestamp on page 1
      ],
    },
    {
      pageNumber: 2,
      excludedAreas: [
        { x1: 680, y1: 240, x2: 955, y2: 465 }, // chart on page 2
      ],
    },
  ],

  pdfToPngConvertOptions: {
    viewportScale: 2.0,          // Rendering scale — higher means more detail. Default: 2.0.
    disableFontFace: true,       // Use built-in font renderer. Default: true.
    useSystemFonts: false,       // Fall back to system fonts for non-embedded fonts. Default: false.
    enableXfa: false,            // Enable XFA form rendering. Default: false.
    pdfFilePassword: 'pa$$word', // Password for encrypted PDFs.
    outputFolder: 'output/pngs', // Save intermediate PNG files here. Omit to keep in memory only.
    outputFileMaskFunc: (pageNumber) => `page_${pageNumber}.png`, // Custom PNG filename.
    pagesToProcess: [1, 3],      // Limit comparison to specific pages (1-based). Default: all pages.
    verbosityLevel: 0,           // 0 = errors only, 1 = warnings, 5 = info. Default: 0.
  },
});

Comparing PDF buffers

Both file paths and Buffer instances are accepted as inputs:

import { readFileSync } from 'node:fs';
import { comparePdf } from 'pdf-visual-compare';

const actual = readFileSync('./actual.pdf');
const expected = readFileSync('./expected.pdf');

const isEqual = await comparePdf(actual, expected);

API

comparePdf(actualPdf, expectedPdf, options?)

| Parameter | Type | Description | | ------------- | --------------------------------- | ----------------------------------------- | | actualPdf | string \| Buffer | File path or buffer of the PDF under test | | expectedPdf | string \| Buffer | File path or buffer of the reference PDF | | options | ComparePdfOptions (optional) | Comparison configuration |

Returns Promise<boolean>true if the PDFs are visually equivalent within the configured threshold, false otherwise.

Throws:

  • Error: PDF file not found: <path> — when a string argument points to a non-existent file.
  • Error: Unknown input file type. — when an argument is neither a string nor a Buffer.
  • Error: Compare Threshold cannot be less than 0. — when options.compareThreshold < 0.

ComparePdfOptions

| Property | Type | Default | Description | | ------------------------ | --------------------- | -------------------- | --------------------------------------------------------------------------- | | diffsOutputFolder | string | ./comparePdfOutput | Folder where diff PNG images are written | | compareThreshold | number | 0 | Maximum number of differing pixels allowed before comparison fails | | excludedAreas | ExcludedPageArea[] | [] | Per-page exclusion zones; array index corresponds to page index (0-based) | | pdfToPngConvertOptions | PdfToPngOptions | see below | Options forwarded to pdf-to-png-converter |

ExcludedPageArea

| Property | Type | Description | | ------------------- | -------- | --------------------------------------------------------------------------------------------------- | | pageNumber | number | Informational page number (matching is performed by array index, not this value) | | excludedAreas | Area[] | Rectangles to exclude. Area = { x1, y1, x2, y2 } in pixels at the configured viewportScale | | excludedAreaColor | Color | Fill color for excluded regions in diff images. Color = { r, g, b } with values 0–255 | | diffFilePath | string | Override the diff image output path for this page | | matchingThreshold | number | Per-page pixel threshold, overrides the document-level compareThreshold for this page |


Support

If you want to support my work, you can buy me a coffee.

Buy Me A Coffee