react-doc-viewer vs react-file-viewer vs react-pdf
PDF and Document Rendering Solutions in React
react-doc-viewerreact-file-viewerreact-pdfSimilar Packages:

PDF and Document Rendering Solutions in React

react-doc-viewer, react-file-viewer, and react-pdf are npm packages designed to help developers embed document viewing capabilities directly into React applications. While all three aim to simplify rendering documents like PDFs, Word files, or spreadsheets, they differ significantly in scope, underlying technology, and maintenance status. react-pdf focuses exclusively on PDF rendering using Mozilla's PDF.js, offering fine-grained control and active development. In contrast, react-file-viewer and react-doc-viewer attempt broader file-type support but vary in reliability and current viability.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
react-doc-viewer0361152 kB89a month agoISC
react-file-viewer0576-1586 years agoMIT
react-pdf011,041309 kB242 months agoMIT

PDF and Document Rendering in React: react-doc-viewer vs react-file-viewer vs react-pdf

When you need to show documents inside a React app—whether it’s a PDF invoice, a Word report, or a PowerPoint deck—you’ll quickly realize browsers don’t natively support most office formats. That’s where libraries like react-doc-viewer, react-file-viewer, and react-pdf come in. But they solve the problem in very different ways, with major implications for security, maintainability, and user experience.

⚠️ Maintenance Status: One Is Officially Deprecated

Before diving into features, check the health of the project:

  • react-file-viewer is deprecated. Its npm page and GitHub README clearly state: “This library is no longer maintained.” It hasn’t seen meaningful updates since 2019 and uses legacy React patterns (createClass, PropTypes from prop-types without modern context). Do not use it in new projects.

  • react-doc-viewer and react-pdf are both actively maintained as of 2024, with recent releases and responsive issue tracking.

This alone eliminates react-file-viewer from serious consideration unless you’re maintaining old code.

📄 Core Capabilities: What File Types Can Each Render?

react-pdf: PDF Only, But Done Right

react-pdf focuses exclusively on PDFs using Mozilla’s battle-tested PDF.js. It renders entirely in the browser—no iframes, no external services.

// react-pdf: Client-side PDF rendering
import { Document, Page } from 'react-pdf';

function PDFViewer({ fileUrl }) {
  return (
    <Document file={fileUrl}>
      <Page pageNumber={1} />
      <Page pageNumber={2} />
    </Document>
  );
}

You get full control: lazy-load pages, handle loading states, customize scale, and even extract text.

react-doc-viewer: Multi-Format via Third-Party Embeds

react-doc-viewer supports PDF, DOCX, XLSX, PPTX, TXT, and images—but not all client-side. For non-PDF files, it falls back to embedding Google Docs Viewer or Microsoft Office Online in an <iframe>.

// react-doc-viewer: Unified API, mixed rendering strategies
import DocViewer, { DocViewerRenderers } from 'react-doc-viewer';

const docs = [{ uri: "/report.docx", fileType: "docx" }];

function DocumentViewer() {
  return (
    <DocViewer
      documents={docs}
      pluginRenderers={DocViewerRenderers}
    />
  );
}

For PDFs, it uses react-pdf under the hood. For .docx, it loads https://docs.google.com/gview?url=...&embedded=true in an iframe. This means:

  • Requires internet access
  • Your document URL must be publicly accessible (or configured for CORS)
  • You’re dependent on Google/Microsoft uptime and policies

react-file-viewer: Deprecated Multi-Format Attempt

Historically, react-file-viewer tried to render multiple formats using various client-side parsers (e.g., mammoth for DOCX, pdfjs-dist for PDFs). But due to lack of maintenance, many dependencies are outdated and insecure.

// react-file-viewer (deprecated — do not use)
import FileViewer from 'react-file-viewer';

// This may break in modern React apps
<FileViewer fileType="docx" filePath="/report.docx" />

It never handled complex formats reliably, and today it’s incompatible with React 18+ in strict mode.

🔒 Security and Deployment Constraints

react-pdf: Safe for Sensitive Data

Since everything runs in-browser, you can serve PDFs from private, authenticated endpoints. No data leaves your user’s machine.

// Works with private URLs (e.g., behind auth)
<Document file={{ url: '/api/documents/secret.pdf', httpHeaders: { Authorization: 'Bearer ...' } }} />

react-doc-viewer: Public URLs Required for Non-PDF

Google Docs Viewer cannot access private or localhost URLs. Your .docx file must be publicly reachable so Google’s servers can fetch it. This is a dealbreaker for internal apps or confidential documents.

// ❌ Fails if /report.docx requires authentication
const docs = [{ uri: "/report.docx", fileType: "docx" }]; // Will show blank or error in iframe

Workarounds involve pre-converting files to PDF on the backend—which defeats the purpose of using a multi-format viewer.

react-file-viewer: Unmaintained = Risky

Outdated dependencies (like old versions of pdfjs-dist) may contain unpatched vulnerabilities. Not suitable for production.

🎛️ Customization and User Experience

react-pdf: Full Control Over UI

You build the viewer UI yourself—pagination, zoom buttons, thumbnails. This gives pixel-perfect control but requires more work.

// Example: Custom zoom control
import { Document, Page, pdfjs } from 'react-pdf';
pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.min.js`;

function CustomPDFViewer({ file }) {
  const [numPages, setNumPages] = useState(null);
  const [pageNumber, setPageNumber] = useState(1);

  function onDocumentLoadSuccess({ numPages }) {
    setNumPages(numPages);
  }

  return (
    <div>
      <Document file={file} onLoadSuccess={onDocumentLoadSuccess}>
        <Page pageNumber={pageNumber} />
      </Document>
      <p>Page {pageNumber} of {numPages}</p>
    </div>
  );
}

react-doc-viewer: Opinionated, Limited Customization

It provides a built-in toolbar and layout, but customization options are minimal. You can’t easily change colors, add annotations, or override the iframe behavior for non-PDF files.

react-file-viewer: No Meaningful Customization Today

Even if it worked, its theming system is based on legacy CSS modules and doesn’t integrate well with modern styling solutions like Tailwind or CSS-in-JS.

🧪 Error Handling and Loading States

react-pdf: Explicit and Reliable

Offers callbacks for loading, success, and error states per page or document.

<Document
  file={file}
  loading={<div>Loading PDF...</div>}
  error={<div>Failed to load PDF</div>}
  noData={<div>No PDF provided</div>}
/>

react-doc-viewer: Basic Error Handling

Provides an onError callback, but iframe-based renderers often fail silently (e.g., Google Docs returns a blank page instead of an error).

<DocViewer
  documents={docs}
  onError={(error) => console.error('DocViewer error:', error)}
/>

react-file-viewer: Unreliable Error Reporting

Error props exist but often don’t fire due to unhandled promise rejections in outdated dependencies.

✅ When to Use Which

ScenarioRecommended Package
Only PDFs, client-side, secure environmentreact-pdf
Multiple formats, public files, quick prototypereact-doc-viewer
Legacy app already using itKeep react-file-viewer temporarily, but migrate ASAP
Need offline DOCX renderingNone of these — convert to PDF on backend first

💡 Final Recommendation

  • For PDF-only needs: react-pdf is the clear winner—secure, customizable, and actively maintained.
  • For occasional multi-format viewing of public files: react-doc-viewer offers convenience at the cost of third-party dependency.
  • Never start a new project with react-file-viewer—its deprecation notice exists for good reason.

If your app handles sensitive documents, invest in server-side conversion to PDF and use react-pdf. It’s more work upfront but pays off in security, reliability, and long-term maintainability.

How to Choose: react-doc-viewer vs react-file-viewer vs react-pdf

  • react-doc-viewer:

    Choose react-doc-viewer if you need a modern, actively maintained solution that supports multiple file types (including PDF, DOCX, XLSX, PPTX, and images) through a unified API and relies on external services like Google Docs Viewer or Microsoft Office Online for non-PDF formats. It’s suitable for internal tools or dashboards where you can accept third-party rendering dependencies and don’t require offline or fully client-side processing.

  • react-file-viewer:

    Avoid react-file-viewer in new projects — it is officially deprecated as of its latest npm release, with the README explicitly stating it is no longer maintained. The package depends on outdated libraries and lacks support for modern React features like hooks or concurrent rendering. If you encounter it in legacy code, plan a migration to react-doc-viewer or react-pdf depending on your file-type needs.

  • react-pdf:

    Choose react-pdf if your primary requirement is robust, client-side PDF rendering without external dependencies. It provides full control over pagination, text selection, zoom, and loading states using PDF.js under the hood. Ideal for applications requiring offline PDF support, custom UI controls, accessibility compliance, or integration into secure environments where third-party iframes are prohibited.

README for react-doc-viewer

react-doc-viewer

Contents



Current Renderable File Types

ExtensionMIME TypeAvailable
bmpimage/bmp
docapplication/msword
docxapplication/vnd.openxmlformats-officedocument.wordprocessingml.document
htmtext/htm
htmltext/html
jpgimage/jpg
jpegimage/jpeg
pdfapplication/pdf
pngimage/png
pptapplication/vnd.ms-powerpoint
pptxapplication/vnd.openxmlformats-officedocument.presentationml.presentation
tiffimage/tiff
txttext/plain
xlsapplication/vnd.ms-excel
xlsxapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet


Installation

Core

 npm i react-doc-viewer
 # or
 yarn add react-doc-viewer

Usage

Warning - By default the component height will expand and contract to the current loaded file. The width will expand to fill the parent.



Basic

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";

function App() {
  const docs = [
    { uri: "https://url-to-my-pdf.pdf" },
    { uri: require("./example-files/pdf.pdf") }, // Local File
  ];

  return <DocViewer documents={docs} />;
}

Included Renderers

To use the included renderers. DocViewerRenderers is an Array of all the included renderers.

import DocViewer, { DocViewerRenderers } from "react-doc-viewer";

<DocViewer
  pluginRenderers={DocViewerRenderers}
  {/* ... */}
/>;

Or you can import individual renderers.

import DocViewer, { PDFRenderer, PNGRenderer } from "react-doc-viewer";

<DocViewer
  pluginRenderers={[PDFRenderer, PNGRenderer]}
  {/* ... */}
/>;


Custom Renderer

To create a custom renderer, that will just exist for your project.

import React from "react";
import DocViewer from "react-doc-viewer";

const MyCustomPNGRenderer: DocRenderer = ({
  mainState: { currentDocument },
}) => {
  if (!currentDocument) return null;

  return (
    <div id="my-png-renderer">
      <img id="png-img" src={currentDocument.fileData as string} />
    </div>
  );
};

MyCustomPNGRenderer.fileTypes = ["png", "image/png"];
MyCustomPNGRenderer.weight = 1;

And supply it to DocViewer > pluginRenderers inside an Array.

import DocViewer, { DocViewerRenderers } from "react-doc-viewer";

<DocViewer
  pluginRenderers={[MyCustomPNGRenderer]}
  documents={
    [
      // ...
    ]
  }
/>;


Custom File Loader

If you need to prevent the actual loading of the file by react-doc-viewer. you can decorate your custom renderer with a callback to do as you wish. e.g. Load the file yourself in an iFrame.

MyCustomPNGRenderer.fileLoader = ({
  documentURI,
  signal,
  fileLoaderComplete,
}) => {
  myCustomFileLoaderCode().then(() => {
    // Whenever you have finished you must call fileLoaderComplete() to remove the loading animation
    fileLoaderComplete();
  });
};


Themed

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,
  }}
/>

Styling

Any styling applied to the <DocViewer> component, is directly applied to the main div container.

- CSS Class

<DocViewer documents={docs} className="my-doc-viewer-style" />

- CSS Class Default Override

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;
}

- React Inline

<DocViewer documents={docs} style={{width: 500, height: 500}} />

- StyledComponent

import styled from "styled-components";
//...
<MyDocViewer documents={docs} />;
//...
const MyDocViewer = styled(DocViewer)`
  border-radius: 10px;
`;

Config

You can provide a config object, which configures parts of the component as required.

<DocViewer documents={docs} config={{
 header: {
  disableHeader: false,
  disableFileName: false,
  retainURLParams: false
 }
}} />


Contributing

Creating a Renderer Plugin

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 { DocRenderer } from "../../types";

// Be sure that Renderer correctly uses type DocRenderer
const JPGRenderer: DocRenderer = ({ mainState: { currentDocument } }) => {
  if (!currentDocument) return null;

  return (
    <div id="jpg-renderer">
      <img id="jpg-img" src={currentDocument.fileData as string} />
    </div>
  );
};

export default JPGRenderer;

// List the MIME types that this renderer will respond to
JPGRenderer.fileTypes = ["jpg", "jpeg", "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,
];


Overriding Header Component

You can pass a callback function to config.header.overrideComponent that returns a React Element. The function's parameters will be populated and usable, this function will also be re-called whenever the mainState updates. Parameters include the state object from the main component, and document navigation functions for previousDocument and nextDocument.

Example:


const myHeader: IHeaderOverride = (state, previousDocument, nextDocument) => {
    if (!state.currentDocument || state.config?.header?.disableFileName) {
      return null;
    }

    return (
      <>
        <div>{state.currentDocument.uri || ""}</div>
        <div>
          <button
            onClick={previousDocument}
            disabled={state.currentFileNo === 0}
          >
            Previous Document
          </button>
          <button
            onClick={nextDocument}
            disabled={state.currentFileNo >= state.documents.length - 1}
          >
            Next Document
          </button>
        </div>
      </>
    );
  };

<DocViewer
  pluginRenderers={DocViewerRenderers}
  documents={
    {
      /**/
    }
  }
  config={{
    header: {
      overrideComponent: myHeader;
      },
    },
  }
/>

API


DocViewer props

nametype
documentsIDocument[]
className?string
style?React.CSSProperties
config?IConfig
theme?ITheme
pluginRenderers?DocRenderer[]

IDocument

nametype
uristring
fileType?string
fileData?`string

IConfig

nametype
header?IHeaderConfig

IHeaderConfig

nametype
disableHeader?boolean
disableFileName?boolean
retainURLParams?boolean
overrideComponent?IHeaderOverride

IHeaderOverride () => ReactElement<any, any> | null

nametype
stateIMainState
previousDocument() => void
nextDocument() => void
returns`ReactElement<any, any>

ITheme

nametype
primary?string
secondary?string
tertiary?string
text_primary?string
text_secondary?string
text_tertiary?string
disableThemeScrollbar?boolean

DocRenderer extends React.FC<DocRendererProps>

nametype
fileTypesstring[]
weightnumber
fileLoader?FileLoaderFunction `

FileLoaderFunction

(props: FileLoaderFuncProps) => void


FileLoaderFuncProps

nametype
documentURIstring
signalAbortSignal
fileLoaderCompleteFileLoaderComplete

FileLoaderComplete

nametype
fileReaderFileReader

DocRendererProps

nametype
mainStateIMainState

IMainState

nametype
currentFileNonumber
documentsIDocument[]
documentLoading?boolean
currentDocument?IDocument
rendererRect?DOMRect
config?IConfig