{"id":15714567,"url":"https://github.com/k-yle/pdf-to-img","last_synced_at":"2025-05-16T06:06:07.361Z","repository":{"id":37053525,"uuid":"334796552","full_name":"k-yle/pdf-to-img","owner":"k-yle","description":"📃📸 Converts PDFs to images in nodejs","archived":false,"fork":false,"pushed_at":"2025-02-16T21:56:26.000Z","size":35009,"stargazers_count":101,"open_issues_count":10,"forks_count":26,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-08T21:09:18.598Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://npm.im/pdf-to-img","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/k-yle.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-02-01T01:22:27.000Z","updated_at":"2025-05-05T07:48:19.000Z","dependencies_parsed_at":"2024-06-08T02:31:08.002Z","dependency_job_id":"4a2925c1-6974-48df-9666-79b7abb0aa07","html_url":"https://github.com/k-yle/pdf-to-img","commit_stats":{"total_commits":207,"total_committers":7,"mean_commits":"29.571428571428573","dds":0.2657004830917874,"last_synced_commit":"927f10cd357e2561b8842d15ccc8ddaf55561f0f"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/k-yle%2Fpdf-to-img","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/k-yle%2Fpdf-to-img/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/k-yle%2Fpdf-to-img/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/k-yle%2Fpdf-to-img/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/k-yle","download_url":"https://codeload.github.com/k-yle/pdf-to-img/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254478189,"owners_count":22077676,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T21:38:29.019Z","updated_at":"2025-05-16T06:06:03.713Z","avatar_url":"https://github.com/k-yle.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"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\u0026t=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 v18+, and comes with a CLI.\n\n## Install\n\n```sh\nnpm install -S pdf-to-img\n```\n\n\u003e [!IMPORTANT]\n\u003e You should use v4 by default. v4 requires nodejs v18 or later, and ESM modules.\n\u003e\n\u003e If you can't upgrade to v4 yet, you can still use v3. If you use v3, you can safely ignore `npm audit`'s [warning about pdfjs-dist](https://github.com/advisories/GHSA-wgrm-67xf-hhpq), since this library [disables `eval` by default](https://github.com/k-yle/pdf-to-img/commit/bdac3a1dcc2004c3f1fe7380bbb860086ec2746f).\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 () =\u003e {\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 () =\u003e {\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```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fk-yle%2Fpdf-to-img","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fk-yle%2Fpdf-to-img","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fk-yle%2Fpdf-to-img/lists"}