
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
react-ipdf-viewer-lite
Advanced tools
A lightweight, dependency-free media viewer for PDFs and other media types with advanced controls
A React component for viewing PDF documents using Mozilla's pdf.js
. Embed a customizable PDF viewer in your React applications with page zoom, theme, Full Screen, Page Count and download support.
Explore a live demo of react-ipdf-viewer-lite
in action:
See the PDF viewer with zoom, navigation, and theme support directly in your browser.
Install the package via npm:
npm install react-ipdf-viewer-lite
Or using Yarn:
yarn add react-ipdf-viewer-lite
Ensure you have the following peer dependencies installed:
react
(>=16.8.0)react-dom
(>=16.8.0)pdfjs-dist
(>=2.9.359)Install them if needed:
npm install react react-dom pdfjs-dist
Import the ReactIPdfViewerLite
component and provide a PDF file URL or path via the src
prop. The component supports PDF documents only; place local PDFs in your public/
folder or use a hosted URL.
import React from "react";
import { ReactIPdfViewerLite } from "react-ipdf-viewer-lite";
import "./App.css";
const PDF = "sample.pdf";
const App = () => {
return (
<div className="App">
<ReactIPdfViewerLite src={PDF} theme='light'/>
</div>
);
};
export default App;
ReactIPdfViewerLite
A React component to render a PDF viewer with customizable controls.
Prop | Type | Description | Default | Example |
---|---|---|---|---|
src | string | URL or path to the PDF file to render. Also accepts document={{ url }} . | None | 'sample.pdf' or 'https://example.com/sample.pdf' |
theme | string | Sets the viewer’s theme. Options: 'light' , 'dark' . | 'dark' | 'light' |
The ReactIPdfViewerLite
component may encounter issues when loading or rendering PDFs. Below are common errors and solutions.
Invalid PDF URL
src
prop points to an invalid or inaccessible URL.public/
or a hosted HTTPS URL.<ReactIPdfViewer src="/sample.pdf" />
CORS Restrictions
public/
.const App = () => {
const pdfUrl =
process.env.NODE_ENV === "development"
? "/sample.pdf"
: "https://your-domain.com/sample.pdf";
return <ReactIPdfViewerLite src={pdfUrl} />;
};
Content Security Policy (CSP) Error
pdf.js
are blocked by your app’s CSP.connect-src
directive.
<meta
http-equiv="Content-Security-Policy"
content="connect-src 'self' blob:;"
/>
Mobile Rendering Issues
pdf.js
canvas rendering. Test with a local PDF.<ReactIPdfViewerLite src="/sample.pdf" autoHeight />
File Loading Failure
Error: "PDF.js: Failed to fetch" or "Corrupted PDF".
Cause: The PDF file is corrupted or unsupported by pdf.js
.
Solution: Validate the PDF with Adobe Acrobat. Use a try-catch block for error handling.
Example:
import React, { useState } from "react";
import {ReactIPdfViewerLite} from "react-ipdf-viewer-lite";
const App = () => {
const [error, setError] = useState(null);
const handleError = (err) => setError(err.message);
return (
<div>
{error ? <p>Error: {error}</p> : null}
<ReactIPdfViewerLite
src="sample.pdf"
/>
</div>
);
};
src
is a valid string. Use a fallback URL if needed.
const pdfUrl = src || "/fallback.pdf";
<ReactIPdfViewer src={pdfUrl} />;
onError
(if supported) or wrap in try-catch.pdf.js
warnings (e.g., missing CMaps).Beyond the core props, ReactIPdfViewerLite
offers:
Contributions are welcome! To contribute:
git checkout -b feature/YourFeature
).git commit -m 'Add YourFeature'
).git push origin feature/YourFeature
).Please ensure your code follows the existing style and includes tests where applicable.
This project is licensed under the MIT License. See the LICENSE file for details.
For issues, questions, or feature requests, please open an issue on the GitHub repository or contact Sudeepa R.# react-ipdf-viewer
FAQs
A lightweight, dependency-free media viewer for PDFs and other media types with advanced controls
We found that react-ipdf-viewer-lite demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.