2.1.2 ā€¢ Published 7 months ago

pdf-to-img v2.1.2

Weekly downloads
109
License
MIT
Repository
github
Last release
7 months ago

pdf-to-img

Build Status Coverage Status npm version npm npm bundle size

šŸ“ƒšŸ“ø Converts PDFs to images in nodejs with no native dependencies.

Useful for unit tests of PDFs

Supports nodejs v14, v16, v18 and v19.

Install

npm install -S pdf-to-img

Example

Using jest and jest-image-snapshot.

const { pdf } = require("pdf-to-img");

it("generates a PDF", async () => {
  for await (const page of await pdf("example.pdf")) {
    expect(page).toMatchImageSnapshot();
  }
});

// or if you want access to more details:

it("generates a PDF with 2 pages", async () => {
  const doc = await pdf("example.pdf");

  expect(doc.length).toBe(2);
  expect(doc.metadata).toEqual({ ... });

  for await (const page of doc) {
    expect(page).toMatchImageSnapshot();
  }
});

The pdf function accepts either a path to the file on disk, or a data URL (e.g. data:application/pdf;base64,...)

Options

You can supply a second argument which is an object of options:

const doc = await pdf("example.pdf", {
  password: "...", // if the PDF is encrypted

  scale: 2.0, // use this for PDFs with high resolution images if the generated image is low quality
});
2.1.2

7 months ago

2.1.1

1 year ago

2.1.0

1 year ago

2.0.0

2 years ago

1.2.0

2 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago