Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update readme Nodejs example #229

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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