A lightweight React library for rendering PDF documents in HTML using PDF.js
- 🧩 Easy integration with React
- ⚡ Fast rendering using PDF.js
- 🖼️ Display PDFs directly in your HTML containers
- 🪶 Lightweight and dependency-minimal
Install using npm:
npm install --save react-pdfjs-dist
Or with Yarn:
yarn add react-pdfjs-dist
Here’s a basic example to render a PDF in your React component:
import React, { useEffect, useRef } from 'react';
import { useReactPdf } from 'react-pdfjs-dist';
const App = () => {
const ref = useRef(null);
const { renderPdf } = useReactPdf({ containerRef: ref });
useEffect(() => {
renderPdf('http://localhost:3000/sample_document.pdf');
}, [renderPdf]);
return (
<div className="App">
<div className="pdf-container" ref={ref} />
</div>
);
};
export default App;
Full documentation is coming soon. For now, check out the example code above or dive into the source code on GitHub.
Pull requests, issues, and feature requests are welcome! Feel free to check the issues page.
If you find this project helpful, consider donating via PayPal 🙏
This project is licensed under the MIT License.