Overview:
React-pdf-js is a component that utilizes PDF.js to render PDF documents in a React application. It provides functionalities for loading and displaying PDF files with various customization options.
Features:
- PDF Rendering: Render PDF documents using PDF.js in a React application.
- UsePdf Hook: Utilize the usePdf hook to integrate PDF functionality into the app easily.
- Customization Options: Scale, rotate, and specify callback functions for document and page loading/rendering events.
- Error Handling: Specify callbacks for handling errors during document and page loading/rendering.
- CMap Configuration: Customize the cmap URL and specify whether cmaps are packed or not.
- Worker Configuration: Specify custom PDF worker URL for rendering PDF files.
- Credential Handling: Add the withCredentials flag for handling credentials during PDF operations.
Installation:
To install react-pdf-js, use either yarn or npm:
yarn add @mikecousins/react-pdf pdfjs-dist
or
npm install @mikecousins/react-pdf pdfjs-dist
Then, utilize the usePdf hook in your application. Remember to pass in necessary props like canvasRef, file, and page.
Summary:
React-pdf-js is a useful component for integrating PDF rendering capabilities into a React application. With features like the usePdf hook, customization options, error handling, and configuration settings for cmaps and workers, developers can efficiently work with PDF files while building React applications.