
Security News
The Next Open Source Security Race: Triage at Machine Speed
Claude Opus 4.6 has uncovered more than 500 open source vulnerabilities, raising new considerations for disclosure, triage, and patching at scale.
react-doc-viewer
Advanced tools
| MIME Type | Available |
|---|---|
| application/pdf | ✓ |
| image/png | ✓ |
| image/jpg, image/jpeg | ✓ |
npm i react-doc-viewer
# or
yarn add react-doc-viewer
Warning - By default the component height will expand and contract to the current loaded file. The width will expand to fill the parent.
DocViewer requires at least an array of document objects to function. Each document object must have a uri to a file, either a url that returns a file or a local file.
import DocViewer from "react-doc-viewer";
// Don't forget to import included renderers / custom renderers
import "react-doc-viewer-plugins";
function App() {
const docs = [
{ uri: "https://url-to-my-pdf.pdf" },
{ uri: require("./example-files/pdf.pdf") }, // Local File
];
return <DocViewer documents={docs} />;
}
To use the included renderers.
DocViewerRenderers is an Array of all the included renderers.
import DocViewer, { DocViewerRenderers } from "react-doc-viewer";
<DocViewer
pluginRenderers={DocViewerRenderers}
documents={
[
// ...
]
}
/>;
To create a custom renderer, that will just exist for your project. Follow Step 2 under Contributing
And supply it to DocViewer > pluginRenderers inside an Array.
import DocViewer, { DocViewerRenderers } from "react-doc-viewer";
<DocViewer
pluginRenderers={[MyCustomRenderer]}
documents={
[
// ...
]
}
/>;
You can provide a theme object with one or all of the available properties.
<DocViewer
documents={docs}
theme={{
primary: "#5296d8",
secondary: "#ffffff",
tertiary: "#5296d899",
text_primary: "#ffffff",
text_secondary: "#5296d8",
text_tertiary: "#00000099",
disableThemeScrollbar: false,
}}
/>
Any styling applied to the <DocViewer> component, is directly applied to the main div container.
<DocViewer documents={docs} className="my-doc-viewer-style" />
Each component / div already has a DOM id that can be used to style any part of the document viewer.
#react-doc-viewer #header-bar {
background-color: #faf;
}
<DocViewer documents={docs} style={{width: 500, height: 500}} />
import styled from "styled-components";
//...
<MyDocViewer documents={docs}/>
//...
const MyDocViewer = styled(DocViewer`
border-radius: 10px;
`
You can provide a config object, which configures parts of the component as required.
<DocViewer documents={docs} config={{
header: {
disableHeader: false,
disableFileName: false
}
}} />
Step 1 - Create a new folder inside src/plugins.
e.g.
src/plugins/jpg
Inside this folder, create a Renderer React Typescript file.
e.g.
index.tsx
Step 2 - Inside JPGRenderer, export a functional component of type DocRenderer
import React from "react";
import { useRecoilValue } from "recoil";
import styled from "styled-components";
import { DocViewerState } from "../../state";
import { DocRenderer } from "../../types";
// Be sure that Renderer correctly uses type DocRenderer
const JPGRenderer: DocRenderer = () => {
// Fetch the currentDocument loaded from main state
const currentDocument = useRecoilValue(DocViewerState.currentDocument);
if (!currentDocument) return null;
return (
<div id="jpg-renderer">
<img id="jpg-img" src={currentDocument.base64Data} />
</div>
);
};
export default JPGRenderer;
// List the MIME types that this renderer will respond to
JPGRenderer.fileTypes = ["image/jpg", "image/jpeg"];
// If you have more than one renderer for the same MIME type, use weight. higher is more preferable.
// Included renderers have a weight of zero
JPGRenderer.weight = 1;
If you are creating a new renderer, also update src/plugins/index.ts with an import to your new renderer file, and Export it as part of the DocViewerRenderers Array.
// ...
import JPGRenderer from "./jpg";
export const DocViewerRenderers = [
// ...
JPGRenderer,
];
DocViewer props| name | type |
|---|---|
| documents | IDocument[] |
| className? | string |
| style? | React.CSSProperties |
| config? | IConfig |
| theme? | ITheme |
IDocument| name | type |
|---|---|
| uri | string |
| fileType? | string - Used Internally - Ignored if passed into props |
| base64Data? | string - Used Internally - Ignored if passed into props |
IConfig| name | type |
|---|---|
| header? | IHeaderConfig |
IHeaderConfig| name | type |
|---|---|
| disableHeader? | boolean |
| disableFileName? | boolean |
ITheme| name | type |
|---|---|
| primary? | string |
| secondary? | string |
| tertiary? | string |
| text_primary? | string |
| text_secondary? | string |
| text_tertiary? | string |
| disableThemeScrollbar? | boolean |
DocRenderer| name | type |
|---|---|
| fileTypes | string[] |
| weight | number |
FAQs
Document viewer for react. Renders online/local documents.
The npm package react-doc-viewer receives a total of 27,156 weekly downloads. As such, react-doc-viewer popularity was classified as popular.
We found that react-doc-viewer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers 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.

Security News
Claude Opus 4.6 has uncovered more than 500 open source vulnerabilities, raising new considerations for disclosure, triage, and patching at scale.

Research
/Security News
Malicious dYdX client packages were published to npm and PyPI after a maintainer compromise, enabling wallet credential theft and remote code execution.

Security News
gem.coop is testing registry-level dependency cooldowns to limit exposure during the brief window when malicious gems are most likely to spread.