Skip to content

Commit

Permalink
Add NodeJS example to README (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpes8693 authored Oct 17, 2023
1 parent 75eba42 commit 851bb1f
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

Useful for unit tests of PDFs

Supports nodejs v14, v16, v18 and v19.
Supports nodejs v16 to v20.

## Install

Expand All @@ -20,7 +20,24 @@ npm install -S pdf-to-img

## Example

Using jest and [jest-image-snapshot](https://npm.im/jest-image-snapshot).
NodeJS:

```js
const { promises: fs } = require("node:fs");
const { pdf } = require("pdf-to-img");

async function main() {
let counter = 1;
const document = await pdf("example.pdf", { scale: 3 });
for await (const image of document) {
await fs.writeFile(`page${counter}.png`, image);
counter++;
}
}
main();
```

Using jest and [jest-image-snapshot](https://npm.im/jest-image-snapshot):

```js
const { pdf } = require("pdf-to-img");
Expand Down

0 comments on commit 851bb1f

Please sign in to comment.