{"id":18488350,"url":"https://github.com/mikecousins/react-pdf-js","last_synced_at":"2025-05-14T02:05:22.286Z","repository":{"id":43921625,"uuid":"56186473","full_name":"mikecousins/react-pdf-js","owner":"mikecousins","description":"A React component to wrap PDF.js","archived":false,"fork":false,"pushed_at":"2025-05-04T04:39:45.000Z","size":16849,"stargazers_count":771,"open_issues_count":10,"forks_count":151,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-05-10T01:01:56.633Z","etag":null,"topics":["es6","es6-javascript","pdf","pdf-viewer","react","reactjs","tsup","typescript","vite"],"latest_commit_sha":null,"homepage":"https://react-pdf.cousins.ai","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/mikecousins.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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},"funding":{"github":"mikecousins","patreon":null,"open_collective":"react-pdf-js","ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2016-04-13T21:12:00.000Z","updated_at":"2025-05-04T22:22:20.000Z","dependencies_parsed_at":"2024-01-17T00:42:56.048Z","dependency_job_id":"95ff6442-be16-4ef2-a905-c42e16f06acc","html_url":"https://github.com/mikecousins/react-pdf-js","commit_stats":{"total_commits":394,"total_committers":37,"mean_commits":10.64864864864865,"dds":0.4365482233502538,"last_synced_commit":"029e0c0534fb04c97d7f5ebda5af5a8980cc181c"},"previous_names":[],"tags_count":36,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikecousins%2Freact-pdf-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikecousins%2Freact-pdf-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikecousins%2Freact-pdf-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikecousins%2Freact-pdf-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mikecousins","download_url":"https://codeload.github.com/mikecousins/react-pdf-js/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254052692,"owners_count":22006716,"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":["es6","es6-javascript","pdf","pdf-viewer","react","reactjs","tsup","typescript","vite"],"created_at":"2024-11-06T12:51:36.288Z","updated_at":"2025-05-14T02:05:17.267Z","avatar_url":"https://github.com/mikecousins.png","language":"TypeScript","funding_links":["https://github.com/sponsors/mikecousins","https://opencollective.com/react-pdf-js"],"categories":["TypeScript","Repository"],"sub_categories":["Office"],"readme":"# react-pdf-js\n\n`react-pdf-js` provides a component for rendering PDF documents using [PDF.js](http://mozilla.github.io/pdf.js/).\n\n---\n\n[![NPM Version](https://img.shields.io/npm/v/@mikecousins/react-pdf.svg?style=flat-square)](https://www.npmjs.com/package/@mikecousins/react-pdf)\n[![NPM Downloads](https://img.shields.io/npm/dm/@mikecousins/react-pdf.svg?style=flat-square)](https://www.npmjs.com/package/@mikecousins/react-pdf)\n[![codecov](https://codecov.io/gh/mikecousins/react-pdf-js/branch/master/graph/badge.svg)](https://codecov.io/gh/mikecousins/react-pdf-js)\n\n# Demo\n\n[https://react-pdf.cousins.ai](https://react-pdf.cousins.ai/)\n\n# Usage\n\nInstall with `yarn add @mikecousins/react-pdf pdfjs-dist` or `npm install @mikecousins/react-pdf pdfjs-dist`\n\n## `usePdf` hook\n\nUse the hook in your app (showing some basic pagination as well):\n\n```js\nimport React, { useState, useRef } from 'react';\nimport { usePdf } from '@mikecousins/react-pdf';\n\nconst MyPdfViewer = () =\u003e {\n  const [page, setPage] = useState(1);\n  const canvasRef = useRef(null);\n\n  const { pdfDocument, pdfPage } = usePdf({\n    file: 'test.pdf',\n    page,\n    canvasRef,\n  });\n\n  return (\n    \u003cdiv\u003e\n      {!pdfDocument \u0026\u0026 \u003cspan\u003eLoading...\u003c/span\u003e}\n      \u003ccanvas ref={canvasRef} /\u003e\n      {Boolean(pdfDocument \u0026\u0026 pdfDocument.numPages) \u0026\u0026 (\n        \u003cnav\u003e\n          \u003cul className=\"pager\"\u003e\n            \u003cli className=\"previous\"\u003e\n              \u003cbutton disabled={page === 1} onClick={() =\u003e setPage(page - 1)}\u003e\n                Previous\n              \u003c/button\u003e\n            \u003c/li\u003e\n            \u003cli className=\"next\"\u003e\n              \u003cbutton\n                disabled={page === pdfDocument.numPages}\n                onClick={() =\u003e setPage(page + 1)}\n              \u003e\n                Next\n              \u003c/button\u003e\n            \u003c/li\u003e\n          \u003c/ul\u003e\n        \u003c/nav\u003e\n      )}\n    \u003c/div\u003e\n  );\n};\n```\n\n## Props\n\nWhen you call usePdf you'll want to pass in a subset of these props, like this:\n\n\u003e `const { pdfDocument, pdfPage } = usePdf({ canvasRef, file: 'https://example.com/test.pdf', page });`\n\n### canvasRef\n\nA reference to the canvas element. Create with:\n\n\u003e `const canvasRef = useRef(null);`\n\nand then render it like:\n\n\u003e `\u003ccanvas ref={canvasRef} /\u003e`\n\nand then pass it into usePdf.\n\n### file\n\nURL of the PDF file.\n\n### onDocumentLoadSuccess\n\nAllows you to specify a callback that is called when the PDF document data will be fully loaded.\nCallback is called with [PDFDocumentProxy](https://github.com/mozilla/pdf.js/blob/master/src/display/api.js#L579)\nas an only argument.\n\n### onDocumentLoadFail\n\nAllows you to specify a callback that is called after an error occurred during PDF document data loading.\n\n### onPageLoadSuccess\n\nAllows you to specify a callback that is called when the PDF page data will be fully loaded.\nCallback is called with [PDFPageProxy](https://github.com/mozilla/pdf.js/blob/master/src/display/api.js#L897)\nas an only argument.\n\n### onPageLoadFail\n\nAllows you to specify a callback that is called after an error occurred during PDF page data loading.\n\n### onPageRenderSuccess\n\nAllows you to specify a callback that is called when the PDF page will be fully rendered into the DOM.\nCallback is called with [PDFPageProxy](https://github.com/mozilla/pdf.js/blob/master/src/display/api.js#L897)\nas an only argument.\n\n### onPageRenderFail\n\nAllows you to specify a callback that is called after an error occurred during PDF page rendering.\n\n### page\n\nSpecify the page that you want to display. Default = 1,\n\n### scale\n\nAllows you to scale the PDF. Default = 1.\n\n### rotate\n\nAllows you to rotate the PDF. Number is in degrees. Default = 0.\n\n### cMapUrl\n\nAllows you to specify a cmap url. Default = '../node_modules/pdfjs-dist/cmaps/'.\n\n### cMapPacked\n\nAllows you to specify whether the cmaps are packed or not. Default = false.\n\n### workerSrc\n\nAllows you to specify a custom pdf worker url. Default = '//cdnjs.cloudflare.com/ajax/libs/pdf.js/\\${pdfjs.version}/pdf.worker.js'.\n\n### withCredentials\n\nAllows you to add the withCredentials flag. Default = false.\n\n## Returned values\n\n### pdfDocument\n\n`pdfjs`'s `PDFDocumentProxy` [object](https://github.com/mozilla/pdf.js/blob/master/src/display/api.js#L579).\nThis can be undefined if document has not been loaded yet.\n\n### pdfPage\n\n`pdfjs`'s `PDFPageProxy` [object](https://github.com/mozilla/pdf.js/blob/master/src/display/api.js#L897)\nThis can be undefined if page has not been loaded yet.\n\n# License\n\nMIT © [mikecousins](https://github.com/mikecousins)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikecousins%2Freact-pdf-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmikecousins%2Freact-pdf-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikecousins%2Freact-pdf-js/lists"}