{"_id":"@aidinabedi/pdf-to-img","name":"@aidinabedi/pdf-to-img","dist-tags":{"latest":"5.0.0"},"versions":{"5.0.0":{"name":"@aidinabedi/pdf-to-img","version":"5.0.0","description":"📃📸 Converts PDFs to images in nodejs","exports":"./dist/index.js","types":"dist/index.d.ts","license":"MIT","keywords":["pdf","pdfjs","pdf-to-img","pdf-to-png","vitest","jest"],"repository":{"type":"git","url":"git+https://github.com/aidinabedi/pdf-to-img.git"},"scripts":{"build":"npm run clean && tsc","clean":"rimraf dist","lint":"eslint .","test":"vitest --pool=forks","trypublish":"npm publish --provenance || true"},"bin":{"pdf2img":"bin/cli.mjs"},"engines":{"node":">=20"},"engineStrict":true,"dependencies":{"pdfjs-dist":"~5.4.0"},"devDependencies":{"@types/jest-image-snapshot":"^6.4.0","@types/node":"^22.13.4","@vitest/coverage-v8":"^1.6.0","canvas":"^3.2.0","eslint":"^9.20.1","eslint-config-kyle":"^25.0.0","jest-image-snapshot":"^6.4.0","jsdom":"^26.0.0","rimraf":"^6.0.1","typescript":"^5.2.2","vitest":"^1.6.0"},"prettier":{"trailingComma":"es5"},"volta":{"node":"20.19.5"},"_id":"@aidinabedi/pdf-to-img@5.0.0","gitHead":"e3d6ae0ca45c1b020183bec6f2f6942ab4962d7b","bugs":{"url":"https://github.com/aidinabedi/pdf-to-img/issues"},"homepage":"https://github.com/aidinabedi/pdf-to-img#readme","_nodeVersion":"20.19.5","_npmVersion":"10.8.2","dist":{"integrity":"sha512-V9Y4c7fOdEgb1V7v1yY84rwj1l7FcP6upmZIidNPnRklADkW9MPhZmzc6QR9Kt3UcxsZu6n0XQZUt2VXbTh5Jw==","shasum":"1cf56403d54e338734cce5d4e6c810d6866318e5","tarball":"https://registry.npmjs.org/@aidinabedi/pdf-to-img/-/pdf-to-img-5.0.0.tgz","fileCount":10,"unpackedSize":17683,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIEbVOhNocToak5DgKBzxo8hW8N9h9a9JC9qpqwUdouo3AiEA/O6Y9pJTKSOAfkjY4bCjNwQdK5KWdLVoV0Ass4kieTk="}]},"_npmUser":{"name":"aidinabedi","email":"aidinabedi@gmail.com"},"directories":{},"maintainers":[{"name":"aidinabedi","email":"aidinabedi@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/pdf-to-img_5.0.0_1759923053411_0.5657510380714681"},"_hasShrinkwrap":false}},"time":{"created":"2025-10-08T11:30:53.295Z","5.0.0":"2025-10-08T11:30:53.609Z","modified":"2025-10-08T11:30:53.858Z"},"maintainers":[{"name":"aidinabedi","email":"aidinabedi@gmail.com"}],"description":"📃📸 Converts PDFs to images in nodejs","homepage":"https://github.com/aidinabedi/pdf-to-img#readme","keywords":["pdf","pdfjs","pdf-to-img","pdf-to-png","vitest","jest"],"repository":{"type":"git","url":"git+https://github.com/aidinabedi/pdf-to-img.git"},"bugs":{"url":"https://github.com/aidinabedi/pdf-to-img/issues"},"license":"MIT","readme":"# pdf-to-img\n\n[![Build Status](https://github.com/k-yle/pdf-to-img/workflows/Build%20and%20Test/badge.svg)](https://github.com/k-yle/pdf-to-img/actions)\n[![Coverage Status](https://coveralls.io/repos/github/k-yle/pdf-to-img/badge.svg?branch=main&t=LQmPNl)](https://coveralls.io/github/k-yle/pdf-to-img?branch=main)\n[![npm version](https://badge.fury.io/js/pdf-to-img.svg)](https://badge.fury.io/js/pdf-to-img)\n[![npm](https://img.shields.io/npm/dt/pdf-to-img.svg)](https://www.npmjs.com/package/pdf-to-img)\n![npm bundle size](https://img.shields.io/bundlephobia/minzip/pdf-to-img)\n\n📃📸 Converts PDFs to images in nodejs.\n\nUseful for unit tests of PDFs\n\nSupports nodejs v20+, and comes with a CLI.\n\n## Install\n\n```sh\nnpm install -S pdf-to-img\n```\n\n## Example\n\nNodeJS (using ESM Modules):\n\n```js\nimport { promises as fs } from \"node:fs\";\nimport { pdf } from \"pdf-to-img\";\n\nasync function main() {\n  let counter = 1;\n  const document = await pdf(\"example.pdf\", { scale: 3 });\n  for await (const image of document) {\n    await fs.writeFile(`page${counter}.png`, image);\n    counter++;\n  }\n\n\n  // you can also read a specific page number:\n  const page12buffer = await document.getPage(12)\n}\nmain();\n```\n\nIf your app does not support ESM modules, you can use v3 (see the warning above), or just change the import:\n\n```diff\n+ const { promises: fs } = require(\"node:fs\");\n- import { promises as fs } from \"node:fs\";\n- import { pdf } from \"pdf-to-img\";\n\n  async function main() {\n+   const { pdf } = await import(\"pdf-to-img\");\n    let counter = 1;\n    const document = await pdf(\"example.pdf\", { scale: 3 });\n    for await (const image of document) {\n      await fs.writeFile(`page${counter}.png`, image);\n      counter++;\n    }\n  }\n  main();\n```\n\nUsing jest (or vitest) with [jest-image-snapshot](https://npm.im/jest-image-snapshot):\n\n```js\nimport { pdf } from \"pdf-to-img\";\n\nit(\"generates a PDF\", async () => {\n  for await (const page of await pdf(\"example.pdf\")) {\n    expect(page).toMatchImageSnapshot();\n  }\n});\n\n// or if you want access to more details:\n\nit(\"generates a PDF with 2 pages\", async () => {\n  const doc = await pdf(\"example.pdf\");\n\n  expect(doc.length).toBe(2);\n  expect(doc.metadata).toEqual({ ... });\n\n  for await (const page of doc) {\n    expect(page).toMatchImageSnapshot();\n  }\n});\n\n```\n\nThe `pdf` function accepts either a path to the file on disk, or a data URL (e.g. `data:application/pdf;base64,...`)\n\n### Options\n\nYou can supply a second argument which is an object of options:\n\n```js\nconst doc = await pdf(\"example.pdf\", {\n  password: \"...\", // if the PDF is encrypted\n\n  scale: 2.0, // use this for PDFs with high resolution images if the generated image is low quality\n});\n```\n\n## CLI\n\n```sh\nnpm i -g pdf-to-img@latest\n\n# example:\npdf2img inputFile.pdf\n\n# options:\n# -s / --scale: set the scale (defaults to 3)\n# -p / --password: the password to unlock the PDF\n# -o / --output: the output folder, relative to the current working directory.\n# -g / --pages: set which pages to convert. eg: 1,4,7 (defaults to all pages)\n```\n","readmeFilename":"README.md","_rev":"1-929707991576dcd4299cbd2e1d9da12b"}