@iamjariwala/react-doc-viewer 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +352 -94
- package/dist/docs-site/docusaurus.config.d.ts +4 -0
- package/dist/docs-site/sidebars.d.ts +4 -0
- package/dist/docs-site/src/components/HomepageFeatures/index.d.ts +3 -0
- package/dist/docs-site/src/pages/index.d.ts +3 -0
- package/package.json +41 -2
- /package/dist/{DocViewer.d.ts → src/DocViewer.d.ts} +0 -0
- /package/dist/{components → src/components}/DocumentNav.d.ts +0 -0
- /package/dist/{components → src/components}/FileName.d.ts +0 -0
- /package/dist/{components → src/components}/HeaderBar.d.ts +0 -0
- /package/dist/{components → src/components}/LoadingTimout.d.ts +0 -0
- /package/dist/{components → src/components}/ProxyRenderer.d.ts +0 -0
- /package/dist/{components → src/components}/common/Button.d.ts +0 -0
- /package/dist/{components → src/components}/common/index.d.ts +0 -0
- /package/dist/{components → src/components}/icons/index.d.ts +0 -0
- /package/dist/{cssStyles.d.ts → src/cssStyles.d.ts} +0 -0
- /package/dist/{defaultTheme.d.ts → src/defaultTheme.d.ts} +0 -0
- /package/dist/{features → src/features}/annotations/components/AnnotationLayer.d.ts +0 -0
- /package/dist/{features → src/features}/annotations/components/AnnotationToolbar.d.ts +0 -0
- /package/dist/{features → src/features}/annotations/components/ColorPicker.d.ts +0 -0
- /package/dist/{features → src/features}/annotations/components/CommentMarker.d.ts +0 -0
- /package/dist/{features → src/features}/annotations/components/CommentPopover.d.ts +0 -0
- /package/dist/{features → src/features}/annotations/components/TextHighlight.d.ts +0 -0
- /package/dist/{features → src/features}/annotations/components/icons/index.d.ts +0 -0
- /package/dist/{features → src/features}/annotations/hooks/useAnnotationExport.d.ts +0 -0
- /package/dist/{features → src/features}/annotations/hooks/useDrawingCanvas.d.ts +0 -0
- /package/dist/{features → src/features}/annotations/hooks/useTextSelection.d.ts +0 -0
- /package/dist/{features → src/features}/annotations/index.d.ts +0 -0
- /package/dist/{features → src/features}/annotations/state/actions.d.ts +0 -0
- /package/dist/{features → src/features}/annotations/state/index.d.ts +0 -0
- /package/dist/{features → src/features}/annotations/state/reducer.d.ts +0 -0
- /package/dist/{features → src/features}/annotations/types/index.d.ts +0 -0
- /package/dist/{features → src/features}/drag-drop/components/DropZoneOverlay.d.ts +0 -0
- /package/dist/{features → src/features}/drag-drop/hooks/useDragDrop.d.ts +0 -0
- /package/dist/{features → src/features}/drag-drop/hooks/useFileProcessor.d.ts +0 -0
- /package/dist/{features → src/features}/drag-drop/index.d.ts +0 -0
- /package/dist/{features → src/features}/drag-drop/types/index.d.ts +0 -0
- /package/dist/{features → src/features}/thumbnail-sidebar/components/ThumbnailItem.d.ts +0 -0
- /package/dist/{features → src/features}/thumbnail-sidebar/components/ThumbnailSidebar.d.ts +0 -0
- /package/dist/{features → src/features}/thumbnail-sidebar/components/ThumbnailToggle.d.ts +0 -0
- /package/dist/{features → src/features}/thumbnail-sidebar/hooks/useThumbnailGenerator.d.ts +0 -0
- /package/dist/{features → src/features}/thumbnail-sidebar/index.d.ts +0 -0
- /package/dist/{features → src/features}/thumbnail-sidebar/state/actions.d.ts +0 -0
- /package/dist/{features → src/features}/thumbnail-sidebar/state/index.d.ts +0 -0
- /package/dist/{features → src/features}/thumbnail-sidebar/state/reducer.d.ts +0 -0
- /package/dist/{hooks → src/hooks}/useDocumentLoader.d.ts +0 -0
- /package/dist/{hooks → src/hooks}/useRendererSelector.d.ts +0 -0
- /package/dist/{hooks → src/hooks}/useTranslation.d.ts +0 -0
- /package/dist/{hooks → src/hooks}/useWindowSize.d.ts +0 -0
- /package/dist/{i18n.d.ts → src/i18n.d.ts} +0 -0
- /package/dist/{index.d.ts → src/index.d.ts} +0 -0
- /package/dist/{locales → src/locales}/ar.json.d.ts +0 -0
- /package/dist/{locales → src/locales}/de.json.d.ts +0 -0
- /package/dist/{locales → src/locales}/en.json.d.ts +0 -0
- /package/dist/{locales → src/locales}/es.json.d.ts +0 -0
- /package/dist/{locales → src/locales}/fr.json.d.ts +0 -0
- /package/dist/{locales → src/locales}/it.json.d.ts +0 -0
- /package/dist/{locales → src/locales}/ja.json.d.ts +0 -0
- /package/dist/{locales → src/locales}/pl.json.d.ts +0 -0
- /package/dist/{locales → src/locales}/pt.json.d.ts +0 -0
- /package/dist/{locales → src/locales}/ru.json.d.ts +0 -0
- /package/dist/{locales → src/locales}/se.json.d.ts +0 -0
- /package/dist/{locales → src/locales}/sr.json.d.ts +0 -0
- /package/dist/{locales → src/locales}/sr_cyr.json.d.ts +0 -0
- /package/dist/{locales → src/locales}/tr.json.d.ts +0 -0
- /package/dist/{models.d.ts → src/models.d.ts} +0 -0
- /package/dist/{renderers → src/renderers}/bmp/index.d.ts +0 -0
- /package/dist/{renderers → src/renderers}/csv/index.d.ts +0 -0
- /package/dist/{renderers → src/renderers}/gif/index.d.ts +0 -0
- /package/dist/{renderers → src/renderers}/html/index.d.ts +0 -0
- /package/dist/{renderers → src/renderers}/image/index.d.ts +0 -0
- /package/dist/{renderers → src/renderers}/index.d.ts +0 -0
- /package/dist/{renderers → src/renderers}/jpg/index.d.ts +0 -0
- /package/dist/{renderers → src/renderers}/msdoc/index.d.ts +0 -0
- /package/dist/{renderers → src/renderers}/pdf/components/PDFControls.d.ts +0 -0
- /package/dist/{renderers → src/renderers}/pdf/components/PDFPagination.d.ts +0 -0
- /package/dist/{renderers → src/renderers}/pdf/components/PDFThumbnailGenerator.d.ts +0 -0
- /package/dist/{renderers → src/renderers}/pdf/components/icons/index.d.ts +0 -0
- /package/dist/{renderers → src/renderers}/pdf/components/pages/PDFAllPages.d.ts +0 -0
- /package/dist/{renderers → src/renderers}/pdf/components/pages/PDFPages.d.ts +0 -0
- /package/dist/{renderers → src/renderers}/pdf/components/pages/PDFSinglePage.d.ts +0 -0
- /package/dist/{renderers → src/renderers}/pdf/index.d.ts +0 -0
- /package/dist/{renderers → src/renderers}/pdf/state/actions.d.ts +0 -0
- /package/dist/{renderers → src/renderers}/pdf/state/index.d.ts +0 -0
- /package/dist/{renderers → src/renderers}/pdf/state/reducer.d.ts +0 -0
- /package/dist/{renderers → src/renderers}/png/index.d.ts +0 -0
- /package/dist/{renderers → src/renderers}/tiff/index.d.ts +0 -0
- /package/dist/{renderers → src/renderers}/tiff/tiffToCanvas.d.ts +0 -0
- /package/dist/{renderers → src/renderers}/txt/index.d.ts +0 -0
- /package/dist/{renderers → src/renderers}/video/index.d.ts +0 -0
- /package/dist/{renderers → src/renderers}/webp/index.d.ts +0 -0
- /package/dist/{store → src/store}/DocViewerProvider.d.ts +0 -0
- /package/dist/{store → src/store}/actions.d.ts +0 -0
- /package/dist/{store → src/store}/mainStateReducer.d.ts +0 -0
- /package/dist/{utils → src/utils}/fileLoaders.d.ts +0 -0
- /package/dist/{utils → src/utils}/getFileName.d.ts +0 -0
package/README.md
CHANGED
|
@@ -1,43 +1,96 @@
|
|
|
1
1
|
[](https://www.npmjs.com/package/@iamjariwala/react-doc-viewer)
|
|
2
|
-
[](https://www.npmjs.com/package/@iamjariwala/react-doc-viewer)
|
|
3
|
+
[](https://www.npmjs.com/package/@iamjariwala/react-doc-viewer)
|
|
4
|
+
[](https://bundlephobia.com/package/@iamjariwala/react-doc-viewer)
|
|
3
5
|
[](https://github.com/mehuljariwala/react-doc-viewer/blob/main/LICENSE)
|
|
4
6
|
[](https://www.typescriptlang.org/)
|
|
5
|
-
[](https://reactjs.org/)
|
|
8
|
+
[](https://github.com/mehuljariwala/react-doc-viewer/pulls)
|
|
9
|
+
[](https://github.com/mehuljariwala/react-doc-viewer)
|
|
6
10
|
|
|
7
11
|
# @iamjariwala/react-doc-viewer
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
**The most feature-complete open-source document viewer for React.** Render PDF, Word, Excel, PowerPoint, images, video, CSV, HTML, and 20+ file types in a single drop-in component. Built-in annotations, drag-and-drop file upload, thumbnail sidebar, zoom controls, page navigation, theming, and i18n (14 languages) -- all with full TypeScript support.
|
|
14
|
+
|
|
15
|
+
> **One component. 20+ file types. Zero hassle.**
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @iamjariwala/react-doc-viewer
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import DocViewer, { DocViewerRenderers } from "@iamjariwala/react-doc-viewer";
|
|
23
|
+
import "@iamjariwala/react-doc-viewer/dist/index.css";
|
|
24
|
+
|
|
25
|
+
<DocViewer
|
|
26
|
+
documents={[{ uri: "https://example.com/sample.pdf" }]}
|
|
27
|
+
pluginRenderers={DocViewerRenderers}
|
|
28
|
+
/>;
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
[Live Demo (Storybook)](https://mehuljariwala.github.io/react-doc-viewer) | [npm](https://www.npmjs.com/package/@iamjariwala/react-doc-viewer) | [GitHub](https://github.com/mehuljariwala/react-doc-viewer)
|
|
32
|
+
|
|
33
|
+
---
|
|
10
34
|
|
|
11
35
|
## Why @iamjariwala/react-doc-viewer?
|
|
12
36
|
|
|
13
|
-
Most React document viewers only handle PDFs or require expensive commercial licenses. This library
|
|
37
|
+
Most React document viewers only handle PDFs or require expensive commercial licenses. This library gives you **everything in one package**:
|
|
38
|
+
|
|
39
|
+
- **20+ file types** in a single `<DocViewer />` component -- no need to install separate libraries for PDF, images, CSV, video, etc.
|
|
40
|
+
- **Annotations** -- highlight text, freehand draw, add comments, and export as JSON
|
|
41
|
+
- **Drag & Drop** -- drop files directly onto the viewer to add or replace documents
|
|
42
|
+
- **Thumbnail Sidebar** -- visual page navigation with click-to-jump for PDFs
|
|
43
|
+
- **Programmatic Control** -- jump to any page via ref or prop, navigate documents programmatically
|
|
44
|
+
- **14 Languages** -- built-in i18n with community translations
|
|
45
|
+
- **Theming & CSS Variables** -- full color control via theme object or `--rdv-*` CSS custom properties
|
|
46
|
+
- **Custom Renderers** -- extend or replace any file type renderer with your own React component
|
|
47
|
+
- **TypeScript First** -- complete type definitions, generics, and IntelliSense support
|
|
48
|
+
- **Tree-Shakeable** -- import only the renderers you need to minimize bundle size
|
|
49
|
+
- **No External Services** -- all rendering happens client-side, no data leaves the browser
|
|
50
|
+
- **Works Everywhere** -- Next.js, Vite, Create React App, Remix, Gatsby, and any React 17+ project
|
|
51
|
+
|
|
52
|
+
### Best for
|
|
53
|
+
|
|
54
|
+
| Use Case | Why this library |
|
|
55
|
+
| -------- | ---------------- |
|
|
56
|
+
| **Document Management Systems (DMS)** | Preview any uploaded file without leaving the app |
|
|
57
|
+
| **Legal & Compliance Platforms** | Annotate, highlight, and comment on contracts and filings |
|
|
58
|
+
| **Education & LMS** | Display course materials in PDF, DOCX, video, and image formats |
|
|
59
|
+
| **Healthcare & Medical Records** | View lab reports, imaging files, and clinical documents |
|
|
60
|
+
| **Real Estate & Insurance** | Preview property documents, claims, and inspection photos |
|
|
61
|
+
| **File Browsers & Cloud Storage** | Inline file preview for any storage UI |
|
|
62
|
+
| **Internal Tools & Admin Panels** | Quick document preview without downloading |
|
|
63
|
+
| **Content Platforms & CMS** | Embedded viewer for user-uploaded content |
|
|
14
64
|
|
|
15
|
-
|
|
16
|
-
- Apps that need to preview multiple file types (PDF, Word, Excel, images, video) without separate libraries for each
|
|
17
|
-
- Document management systems, file browsers, and content platforms
|
|
18
|
-
- Projects that need annotation, highlighting, or commenting on documents
|
|
19
|
-
- Teams that want a single drop-in component instead of stitching together 5+ libraries
|
|
65
|
+
---
|
|
20
66
|
|
|
21
|
-
|
|
67
|
+
## How It Compares
|
|
68
|
+
|
|
69
|
+
Looking for the best React document viewer? Here's how `@iamjariwala/react-doc-viewer` stacks up against popular alternatives:
|
|
22
70
|
|
|
23
71
|
| Feature | @iamjariwala/react-doc-viewer | react-pdf | @cyntler/react-doc-viewer | react-file-viewer |
|
|
24
72
|
| ------- | :--: | :--: | :--: | :--: |
|
|
25
73
|
| PDF rendering | Yes | Yes | Yes | Yes |
|
|
26
|
-
| Office docs (Word, Excel, PPT) |
|
|
74
|
+
| Office docs (Word, Excel, PPT) | Yes | -- | Yes | Partial |
|
|
27
75
|
| Images (PNG, JPG, GIF, WebP, TIFF, BMP) | Yes | -- | Yes | Partial |
|
|
28
76
|
| Video (MP4) | Yes | -- | Yes | Yes |
|
|
29
77
|
| CSV / TXT / HTML | Yes | -- | Yes | Partial |
|
|
30
|
-
| Drag & Drop | Yes | -- | -- | -- |
|
|
78
|
+
| Drag & Drop file upload | Yes | -- | -- | -- |
|
|
31
79
|
| Annotations (highlight, draw, comment) | Yes | -- | -- | -- |
|
|
32
|
-
| Thumbnail sidebar | Yes | -- | -- | -- |
|
|
33
|
-
| Programmatic page
|
|
80
|
+
| Thumbnail sidebar navigation | Yes | -- | -- | -- |
|
|
81
|
+
| Programmatic page jump | Yes | Yes | -- | -- |
|
|
34
82
|
| i18n (14 languages) | Yes | -- | -- | -- |
|
|
35
83
|
| Custom renderers | Yes | -- | Yes | -- |
|
|
36
|
-
| Theming | Yes | -- | Yes | -- |
|
|
84
|
+
| Theming (CSS variables) | Yes | -- | Yes | -- |
|
|
37
85
|
| TypeScript | Yes | Yes | Yes | -- |
|
|
38
|
-
|
|
|
86
|
+
| Tree-shakeable | Yes | Yes | -- | -- |
|
|
87
|
+
| No external services | Yes | Yes | -- | -- |
|
|
88
|
+
| Zero styled-components | Yes | Yes | -- | -- |
|
|
89
|
+
| Actively maintained (2025) | Yes | Yes | -- | -- |
|
|
39
90
|
| License | Apache-2.0 | MIT | MIT | MIT |
|
|
40
91
|
|
|
92
|
+
> **TL;DR** -- If you only render PDFs, `react-pdf` is lighter. If you need multi-format support, annotations, drag-and-drop, or thumbnails, this library covers more ground in a single package.
|
|
93
|
+
|
|
41
94
|
---
|
|
42
95
|
|
|
43
96
|
### Feature Highlights
|
|
@@ -45,8 +98,8 @@ Most React document viewers only handle PDFs or require expensive commercial lic
|
|
|
45
98
|
| | | |
|
|
46
99
|
|:--|:--|:--|
|
|
47
100
|
| **Multi-Format Support** -- PDF, DOCX, images, video, CSV & more | **Drag & Drop** -- Drop files directly onto the viewer | **Annotations** -- Highlight, draw, and comment on documents |
|
|
48
|
-
| **Thumbnail Sidebar** -- Visual page navigation for PDFs | **14 Languages** -- Built-in i18n with community translations | **Theming** -- Full color control via
|
|
49
|
-
| **Custom Renderers** -- Extend or replace any file type
|
|
101
|
+
| **Thumbnail Sidebar** -- Visual page navigation for PDFs | **14 Languages** -- Built-in i18n with community translations | **Theming** -- Full color control via CSS variables |
|
|
102
|
+
| **Custom Renderers** -- Extend or replace any file type | **Page Navigation** -- Programmatic page jump via ref or prop | **Security** -- DOMPurify sanitization, no external iframes |
|
|
50
103
|
|
|
51
104
|
---
|
|
52
105
|
|
|
@@ -58,6 +111,8 @@ Most React document viewers only handle PDFs or require expensive commercial lic
|
|
|
58
111
|
- **Smaller bundle** -- Removed `styled-components`, `core-js`, and `ajv` dependencies (~300-400KB savings)
|
|
59
112
|
- **CSS custom properties** -- Theming now uses `--rdv-*` CSS variables for full customizability
|
|
60
113
|
|
|
114
|
+
---
|
|
115
|
+
|
|
61
116
|
## Table of Contents
|
|
62
117
|
|
|
63
118
|
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
|
@@ -68,6 +123,11 @@ Most React document viewers only handle PDFs or require expensive commercial lic
|
|
|
68
123
|
- [Live Demo](#live-demo)
|
|
69
124
|
- [Installation](#installation)
|
|
70
125
|
- [Quick Start](#quick-start)
|
|
126
|
+
- [Framework Guides](#framework-guides)
|
|
127
|
+
- [Next.js (App Router & Pages Router)](#nextjs-app-router--pages-router)
|
|
128
|
+
- [Vite](#vite)
|
|
129
|
+
- [Create React App](#create-react-app)
|
|
130
|
+
- [Remix](#remix)
|
|
71
131
|
- [Documents](#documents)
|
|
72
132
|
- [Remote & Local Files](#remote--local-files)
|
|
73
133
|
- [Initial Active Document](#initial-active-document)
|
|
@@ -78,23 +138,26 @@ Most React document viewers only handle PDFs or require expensive commercial lic
|
|
|
78
138
|
- [Custom Renderer](#custom-renderer)
|
|
79
139
|
- [Custom File Loader](#custom-file-loader)
|
|
80
140
|
- [Features](#features)
|
|
81
|
-
- [Drag & Drop](#drag--drop)
|
|
141
|
+
- [Drag & Drop File Upload](#drag--drop-file-upload)
|
|
82
142
|
- [Thumbnail Sidebar](#thumbnail-sidebar)
|
|
83
|
-
- [Annotations](#annotations)
|
|
84
|
-
- [Page Navigation](#page-navigation)
|
|
143
|
+
- [Annotations (Highlight, Draw, Comment)](#annotations-highlight-draw-comment)
|
|
144
|
+
- [Page Navigation & Page Jump](#page-navigation--page-jump)
|
|
85
145
|
- [Configuration](#configuration)
|
|
86
146
|
- [Full Config Reference](#full-config-reference)
|
|
87
147
|
- [Overriding Header](#overriding-header)
|
|
88
148
|
- [Overriding Loading Renderer](#overriding-loading-renderer)
|
|
89
149
|
- [Overriding No Renderer (Error)](#overriding-no-renderer-error)
|
|
90
|
-
- [Theming](#theming)
|
|
91
|
-
- [Styling](#styling)
|
|
92
|
-
- [Internationalization (i18n)](#internationalization-i18n)
|
|
150
|
+
- [Theming & CSS Variables](#theming--css-variables)
|
|
151
|
+
- [Styling & CSS Customization](#styling--css-customization)
|
|
152
|
+
- [Internationalization (i18n) -- 14 Languages](#internationalization-i18n----14-languages)
|
|
153
|
+
- [Performance & Bundle Size](#performance--bundle-size)
|
|
154
|
+
- [Security](#security)
|
|
93
155
|
- [Advanced](#advanced)
|
|
94
|
-
- [DocViewerRef](#docviewerref)
|
|
95
|
-
- [Custom HTTP Verb](#custom-http-verb)
|
|
96
|
-
- [Custom Request Headers](#custom-request-headers)
|
|
156
|
+
- [DocViewerRef API](#docviewerref-api)
|
|
157
|
+
- [Custom HTTP Verb for S3 / Cloud Storage](#custom-http-verb-for-s3--cloud-storage)
|
|
158
|
+
- [Custom Request Headers for Authenticated APIs](#custom-request-headers-for-authenticated-apis)
|
|
97
159
|
- [FAQ](#faq)
|
|
160
|
+
- [Migrating from Other Libraries](#migrating-from-other-libraries)
|
|
98
161
|
- [Contributing](#contributing)
|
|
99
162
|
- [License](#license)
|
|
100
163
|
|
|
@@ -102,32 +165,36 @@ Most React document viewers only handle PDFs or require expensive commercial lic
|
|
|
102
165
|
|
|
103
166
|
## Supported File Types
|
|
104
167
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
|
108
|
-
|
|
|
109
|
-
|
|
|
110
|
-
|
|
|
111
|
-
|
|
|
112
|
-
|
|
|
113
|
-
|
|
|
114
|
-
|
|
|
115
|
-
|
|
|
116
|
-
|
|
|
117
|
-
|
|
|
168
|
+
`@iamjariwala/react-doc-viewer` supports **20+ file formats** out of the box:
|
|
169
|
+
|
|
170
|
+
| Extension | MIME Type | Renderer |
|
|
171
|
+
| --------- | --------- | -------- |
|
|
172
|
+
| pdf | `application/pdf` | Full viewer with zoom, pagination, thumbnails |
|
|
173
|
+
| png | `image/png` | Image with checkerboard background |
|
|
174
|
+
| jpg / jpeg | `image/jpg`, `image/jpeg` | Image viewer |
|
|
175
|
+
| gif | `image/gif` | Image viewer (animated GIF support) |
|
|
176
|
+
| bmp | `image/bmp` | Image viewer |
|
|
177
|
+
| tiff | `image/tiff` | Canvas-based TIFF renderer |
|
|
178
|
+
| webp | `image/webp` | Image viewer |
|
|
179
|
+
| csv | `text/csv` | Parsed table with configurable delimiter |
|
|
180
|
+
| txt | `text/plain` | Monospace text viewer |
|
|
181
|
+
| htm / html | `text/htm`, `text/html` | Sandboxed iframe with DOMPurify sanitization |
|
|
182
|
+
| mp4 | `video/mp4` | Native video player with controls |
|
|
118
183
|
| doc | `application/msword` | Download card |
|
|
119
184
|
| docx | `application/vnd.openxmlformats-officedocument.wordprocessingml.document` | Download card |
|
|
120
185
|
| xls | `application/vnd.ms-excel` | Download card |
|
|
121
186
|
| xlsx | `application/vnd.openxmlformats-officedocument.spreadsheetml.sheet` | Download card |
|
|
122
187
|
| ppt | `application/vnd.ms-powerpoint` | Download card |
|
|
123
188
|
| pptx | `application/vnd.openxmlformats-officedocument.presentationml.presentation` | Download card |
|
|
124
|
-
| odt | `application/vnd.oasis.opendocument.text` | |
|
|
189
|
+
| odt | `application/vnd.oasis.opendocument.text` | Download card |
|
|
125
190
|
|
|
126
191
|
> [!NOTE]
|
|
127
|
-
> MS Office documents (doc, docx, xls, xlsx, ppt, pptx) render as download cards showing file name, type, and a download link. No external service or public URL is required.
|
|
192
|
+
> MS Office documents (doc, docx, xls, xlsx, ppt, pptx) render as download cards showing file name, type, and a download link. No external service or public URL is required. Need inline rendering? Create a [Custom Renderer](#custom-renderer) with your preferred conversion service.
|
|
128
193
|
|
|
129
194
|
## Live Demo
|
|
130
195
|
|
|
196
|
+
Try all features interactively:
|
|
197
|
+
|
|
131
198
|
[Storybook Demo](https://mehuljariwala.github.io/react-doc-viewer)
|
|
132
199
|
|
|
133
200
|
## Installation
|
|
@@ -144,6 +211,10 @@ yarn add @iamjariwala/react-doc-viewer
|
|
|
144
211
|
pnpm add @iamjariwala/react-doc-viewer
|
|
145
212
|
```
|
|
146
213
|
|
|
214
|
+
```bash
|
|
215
|
+
bun add @iamjariwala/react-doc-viewer
|
|
216
|
+
```
|
|
217
|
+
|
|
147
218
|
## Quick Start
|
|
148
219
|
|
|
149
220
|
```tsx
|
|
@@ -160,7 +231,85 @@ function App() {
|
|
|
160
231
|
}
|
|
161
232
|
```
|
|
162
233
|
|
|
163
|
-
> The CSS import is required for correct rendering of PDF and
|
|
234
|
+
> The CSS import (`@iamjariwala/react-doc-viewer/dist/index.css`) is required for correct rendering of PDF pages, annotations, thumbnails, and all styled elements.
|
|
235
|
+
|
|
236
|
+
## Framework Guides
|
|
237
|
+
|
|
238
|
+
### Next.js (App Router & Pages Router)
|
|
239
|
+
|
|
240
|
+
```tsx
|
|
241
|
+
"use client";
|
|
242
|
+
|
|
243
|
+
import DocViewer, { DocViewerRenderers } from "@iamjariwala/react-doc-viewer";
|
|
244
|
+
import "@iamjariwala/react-doc-viewer/dist/index.css";
|
|
245
|
+
|
|
246
|
+
export default function DocumentPage() {
|
|
247
|
+
return (
|
|
248
|
+
<DocViewer
|
|
249
|
+
documents={[{ uri: "/documents/report.pdf" }]}
|
|
250
|
+
pluginRenderers={DocViewerRenderers}
|
|
251
|
+
/>
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
> The `"use client"` directive is required when using the App Router since DocViewer uses browser APIs. A working Next.js example is included at `use-cases/nextjs/`.
|
|
257
|
+
|
|
258
|
+
### Vite
|
|
259
|
+
|
|
260
|
+
```tsx
|
|
261
|
+
import DocViewer, { DocViewerRenderers } from "@iamjariwala/react-doc-viewer";
|
|
262
|
+
import "@iamjariwala/react-doc-viewer/dist/index.css";
|
|
263
|
+
|
|
264
|
+
function App() {
|
|
265
|
+
return (
|
|
266
|
+
<DocViewer
|
|
267
|
+
documents={[{ uri: "/sample.pdf" }]}
|
|
268
|
+
pluginRenderers={DocViewerRenderers}
|
|
269
|
+
/>
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### Create React App
|
|
275
|
+
|
|
276
|
+
```tsx
|
|
277
|
+
import DocViewer, { DocViewerRenderers } from "@iamjariwala/react-doc-viewer";
|
|
278
|
+
import "@iamjariwala/react-doc-viewer/dist/index.css";
|
|
279
|
+
|
|
280
|
+
function App() {
|
|
281
|
+
return (
|
|
282
|
+
<DocViewer
|
|
283
|
+
documents={[{ uri: `${process.env.PUBLIC_URL}/sample.pdf` }]}
|
|
284
|
+
pluginRenderers={DocViewerRenderers}
|
|
285
|
+
/>
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
### Remix
|
|
291
|
+
|
|
292
|
+
```tsx
|
|
293
|
+
import { ClientOnly } from "remix-utils/client-only";
|
|
294
|
+
|
|
295
|
+
export default function DocumentRoute() {
|
|
296
|
+
return (
|
|
297
|
+
<ClientOnly fallback={<p>Loading viewer...</p>}>
|
|
298
|
+
{() => {
|
|
299
|
+
const DocViewer = require("@iamjariwala/react-doc-viewer").default;
|
|
300
|
+
const { DocViewerRenderers } = require("@iamjariwala/react-doc-viewer");
|
|
301
|
+
require("@iamjariwala/react-doc-viewer/dist/index.css");
|
|
302
|
+
return (
|
|
303
|
+
<DocViewer
|
|
304
|
+
documents={[{ uri: "/documents/report.pdf" }]}
|
|
305
|
+
pluginRenderers={DocViewerRenderers}
|
|
306
|
+
/>
|
|
307
|
+
);
|
|
308
|
+
}}
|
|
309
|
+
</ClientOnly>
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
```
|
|
164
313
|
|
|
165
314
|
## Documents
|
|
166
315
|
|
|
@@ -240,7 +389,7 @@ import DocViewer, { DocViewerRenderers } from "@iamjariwala/react-doc-viewer";
|
|
|
240
389
|
<DocViewer pluginRenderers={DocViewerRenderers} documents={docs} />;
|
|
241
390
|
```
|
|
242
391
|
|
|
243
|
-
Or import only what you need:
|
|
392
|
+
Or import only what you need for smaller bundles:
|
|
244
393
|
|
|
245
394
|
```tsx
|
|
246
395
|
import DocViewer, { PDFRenderer, PNGRenderer } from "@iamjariwala/react-doc-viewer";
|
|
@@ -282,9 +431,9 @@ MyPNGRenderer.fileLoader = ({ documentURI, signal, fileLoaderComplete }) => {
|
|
|
282
431
|
|
|
283
432
|
## Features
|
|
284
433
|
|
|
285
|
-
### Drag & Drop
|
|
434
|
+
### Drag & Drop File Upload
|
|
286
435
|
|
|
287
|
-
Enable file drag-and-drop to add or replace documents in the viewer.
|
|
436
|
+
Enable file drag-and-drop to add or replace documents in the viewer. Supports file type filtering, size limits, and callbacks.
|
|
288
437
|
|
|
289
438
|
```tsx
|
|
290
439
|
<DocViewer
|
|
@@ -318,7 +467,7 @@ Enable file drag-and-drop to add or replace documents in the viewer.
|
|
|
318
467
|
|
|
319
468
|
### Thumbnail Sidebar
|
|
320
469
|
|
|
321
|
-
Display a visual sidebar with page thumbnails for quick PDF navigation.
|
|
470
|
+
Display a visual sidebar with page thumbnails for quick PDF navigation. Click any thumbnail to jump to that page.
|
|
322
471
|
|
|
323
472
|
```tsx
|
|
324
473
|
<DocViewer
|
|
@@ -340,9 +489,9 @@ Display a visual sidebar with page thumbnails for quick PDF navigation.
|
|
|
340
489
|
| `thumbnailWidth` | `number` | `120` | Width of each thumbnail in pixels |
|
|
341
490
|
| `sidebarDefaultOpen` | `boolean` | `false` | Open sidebar by default |
|
|
342
491
|
|
|
343
|
-
### Annotations
|
|
492
|
+
### Annotations (Highlight, Draw, Comment)
|
|
344
493
|
|
|
345
|
-
Add highlights, freehand drawings, and comments to your documents.
|
|
494
|
+
Add highlights, freehand drawings, and comments to your documents. Export annotations as JSON for persistence.
|
|
346
495
|
|
|
347
496
|
```tsx
|
|
348
497
|
<DocViewer
|
|
@@ -394,7 +543,7 @@ function AnnotationControls() {
|
|
|
394
543
|
}
|
|
395
544
|
```
|
|
396
545
|
|
|
397
|
-
### Page Navigation
|
|
546
|
+
### Page Navigation & Page Jump
|
|
398
547
|
|
|
399
548
|
Jump to a specific page using a ref or the `jumpToPage` prop.
|
|
400
549
|
|
|
@@ -537,9 +686,9 @@ const MyError = ({ document, fileName }: { document: IDocument | undefined; file
|
|
|
537
686
|
/>;
|
|
538
687
|
```
|
|
539
688
|
|
|
540
|
-
## Theming
|
|
689
|
+
## Theming & CSS Variables
|
|
541
690
|
|
|
542
|
-
Customize the viewer's appearance with a theme object
|
|
691
|
+
Customize the viewer's appearance with a theme object. Values are injected as CSS custom properties (`--rdv-*`) on the container element.
|
|
543
692
|
|
|
544
693
|
```tsx
|
|
545
694
|
<DocViewer
|
|
@@ -557,17 +706,17 @@ Customize the viewer's appearance with a theme object:
|
|
|
557
706
|
/>
|
|
558
707
|
```
|
|
559
708
|
|
|
560
|
-
| Property |
|
|
561
|
-
| -------- |
|
|
562
|
-
| `primary` | `
|
|
563
|
-
| `secondary` | `
|
|
564
|
-
| `tertiary` | `
|
|
565
|
-
| `textPrimary` | `
|
|
566
|
-
| `textSecondary` | `
|
|
567
|
-
| `textTertiary` | `
|
|
568
|
-
| `disableThemeScrollbar` |
|
|
709
|
+
| Property | CSS Variable | Default | Description |
|
|
710
|
+
| -------- | ------------ | ------- | ----------- |
|
|
711
|
+
| `primary` | `--rdv-primary` | `"#fff"` | Primary background color |
|
|
712
|
+
| `secondary` | `--rdv-secondary` | `"#000"` | Secondary background color |
|
|
713
|
+
| `tertiary` | `--rdv-tertiary` | `"#ffffff99"` | Tertiary background color |
|
|
714
|
+
| `textPrimary` | `--rdv-text-primary` | `"#000"` | Primary text color |
|
|
715
|
+
| `textSecondary` | `--rdv-text-secondary` | `"#fff"` | Secondary text color |
|
|
716
|
+
| `textTertiary` | `--rdv-text-tertiary` | `"#00000044"` | Tertiary text color |
|
|
717
|
+
| `disableThemeScrollbar` | -- | `false` | Disable themed scrollbar styling |
|
|
569
718
|
|
|
570
|
-
## Styling
|
|
719
|
+
## Styling & CSS Customization
|
|
571
720
|
|
|
572
721
|
**CSS class:**
|
|
573
722
|
|
|
@@ -599,9 +748,7 @@ All internal elements use `.rdv-*` class names that you can target:
|
|
|
599
748
|
}
|
|
600
749
|
```
|
|
601
750
|
|
|
602
|
-
**Override CSS custom properties:**
|
|
603
|
-
|
|
604
|
-
Theming is powered by CSS variables. Override them on the container or globally:
|
|
751
|
+
**Override CSS custom properties globally:**
|
|
605
752
|
|
|
606
753
|
```css
|
|
607
754
|
#react-doc-viewer {
|
|
@@ -611,9 +758,28 @@ Theming is powered by CSS variables. Override them on the container or globally:
|
|
|
611
758
|
}
|
|
612
759
|
```
|
|
613
760
|
|
|
614
|
-
|
|
761
|
+
**Common CSS class reference:**
|
|
615
762
|
|
|
616
|
-
|
|
763
|
+
| Class | Element |
|
|
764
|
+
| ----- | ------- |
|
|
765
|
+
| `.rdv-container` | Root container |
|
|
766
|
+
| `.rdv-header-bar` | Top header bar |
|
|
767
|
+
| `.rdv-file-name` | File name display |
|
|
768
|
+
| `.rdv-doc-nav-prev` / `.rdv-doc-nav-next` | Document navigation buttons |
|
|
769
|
+
| `.rdv-pdf-controls` | PDF control bar (zoom, pagination) |
|
|
770
|
+
| `.rdv-pdf-page-wrapper` | Individual PDF page wrapper |
|
|
771
|
+
| `.rdv-thumbnail-sidebar` | Thumbnail sidebar container |
|
|
772
|
+
| `.rdv-annotation-toolbar` | Annotation toolbar |
|
|
773
|
+
| `.rdv-image-container` | Image renderer container |
|
|
774
|
+
| `.rdv-csv-container` | CSV table container |
|
|
775
|
+
| `.rdv-txt-container` | Text renderer container |
|
|
776
|
+
| `.rdv-video-container` | Video player container |
|
|
777
|
+
| `.rdv-msdoc-container` | Office document download card |
|
|
778
|
+
| `.rdv-loading-container` | Loading spinner container |
|
|
779
|
+
|
|
780
|
+
## Internationalization (i18n) -- 14 Languages
|
|
781
|
+
|
|
782
|
+
Pass a `language` prop to translate the UI into any of the 14 supported languages:
|
|
617
783
|
|
|
618
784
|
```tsx
|
|
619
785
|
<DocViewer documents={docs} pluginRenderers={DocViewerRenderers} language="pl" />
|
|
@@ -621,28 +787,53 @@ Pass a `language` prop to translate the UI:
|
|
|
621
787
|
|
|
622
788
|
**Supported languages:**
|
|
623
789
|
|
|
624
|
-
| Code | Language |
|
|
625
|
-
| ---- | -------- |
|
|
626
|
-
| `en` | English |
|
|
627
|
-
| `ar` | Arabic |
|
|
628
|
-
| `de` | German |
|
|
629
|
-
| `es` | Spanish |
|
|
630
|
-
| `fr` | French |
|
|
631
|
-
| `it` | Italian |
|
|
632
|
-
| `
|
|
633
|
-
| `pl` | Polish |
|
|
634
|
-
| `pt` | Portuguese |
|
|
635
|
-
| `ru` | Russian |
|
|
636
|
-
| `se` | Swedish |
|
|
637
|
-
| `sr` | Serbian (Latin) |
|
|
638
|
-
| `sr_cyr` | Serbian (Cyrillic) |
|
|
639
|
-
| `tr` | Turkish |
|
|
790
|
+
| Code | Language | Code | Language |
|
|
791
|
+
| ---- | -------- | ---- | -------- |
|
|
792
|
+
| `en` | English | `ja` | Japanese |
|
|
793
|
+
| `ar` | Arabic | `pl` | Polish |
|
|
794
|
+
| `de` | German | `pt` | Portuguese |
|
|
795
|
+
| `es` | Spanish | `ru` | Russian |
|
|
796
|
+
| `fr` | French | `se` | Swedish |
|
|
797
|
+
| `it` | Italian | `sr` | Serbian (Latin) |
|
|
798
|
+
| `tr` | Turkish | `sr_cyr` | Serbian (Cyrillic) |
|
|
640
799
|
|
|
641
800
|
Translation files are in `src/locales/`. PRs for new languages are welcome.
|
|
642
801
|
|
|
802
|
+
## Performance & Bundle Size
|
|
803
|
+
|
|
804
|
+
v1.1.0 significantly reduced bundle size by removing heavy dependencies:
|
|
805
|
+
|
|
806
|
+
| Dependency removed | Size saved |
|
|
807
|
+
| ------------------ | ---------- |
|
|
808
|
+
| `styled-components` | ~160KB minified |
|
|
809
|
+
| `core-js` | ~150KB minified |
|
|
810
|
+
| `ajv` | ~70KB minified |
|
|
811
|
+
| **Total savings** | **~380KB** |
|
|
812
|
+
|
|
813
|
+
**Optimization tips:**
|
|
814
|
+
|
|
815
|
+
- **Tree-shake renderers** -- Import only the renderers you need instead of `DocViewerRenderers`
|
|
816
|
+
- **Lazy load the viewer** -- Use `React.lazy()` to code-split the viewer into its own chunk
|
|
817
|
+
- **Set dimensions** -- Always give the viewer explicit `width` and `height` via `style` prop to prevent layout shifts
|
|
818
|
+
|
|
819
|
+
```tsx
|
|
820
|
+
const DocViewer = React.lazy(() => import("@iamjariwala/react-doc-viewer"));
|
|
821
|
+
|
|
822
|
+
<Suspense fallback={<div>Loading viewer...</div>}>
|
|
823
|
+
<DocViewer documents={docs} pluginRenderers={[PDFRenderer]} />
|
|
824
|
+
</Suspense>
|
|
825
|
+
```
|
|
826
|
+
|
|
827
|
+
## Security
|
|
828
|
+
|
|
829
|
+
- **HTML sanitization** -- All HTML content is sanitized with [DOMPurify](https://github.com/cure53/DOMPurify) before rendering. Script tags, object embeds, and form elements are stripped.
|
|
830
|
+
- **No external services** -- All document rendering happens client-side. No file data is sent to third-party servers.
|
|
831
|
+
- **No external iframes** -- MS Office documents render as local download cards instead of being sent to Microsoft's viewing service.
|
|
832
|
+
- **Sandboxed HTML** -- HTML documents render inside an iframe with sanitized content.
|
|
833
|
+
|
|
643
834
|
## Advanced
|
|
644
835
|
|
|
645
|
-
### DocViewerRef
|
|
836
|
+
### DocViewerRef API
|
|
646
837
|
|
|
647
838
|
Control the viewer programmatically:
|
|
648
839
|
|
|
@@ -658,17 +849,23 @@ docViewerRef.current?.next();
|
|
|
658
849
|
docViewerRef.current?.goToPage(3);
|
|
659
850
|
```
|
|
660
851
|
|
|
661
|
-
|
|
852
|
+
| Method | Description |
|
|
853
|
+
| ------ | ----------- |
|
|
854
|
+
| `prev()` | Navigate to the previous document |
|
|
855
|
+
| `next()` | Navigate to the next document |
|
|
856
|
+
| `goToPage(n)` | Jump to page `n` in the current PDF |
|
|
662
857
|
|
|
663
|
-
|
|
858
|
+
### Custom HTTP Verb for S3 / Cloud Storage
|
|
859
|
+
|
|
860
|
+
Some services (like AWS S3 pre-signed URLs) require a specific HTTP verb for pre-fetching. By default, `HEAD` is used:
|
|
664
861
|
|
|
665
862
|
```tsx
|
|
666
863
|
<DocViewer documents={docs} pluginRenderers={DocViewerRenderers} prefetchMethod="GET" />
|
|
667
864
|
```
|
|
668
865
|
|
|
669
|
-
### Custom Request Headers
|
|
866
|
+
### Custom Request Headers for Authenticated APIs
|
|
670
867
|
|
|
671
|
-
Provide custom headers for authenticated requests:
|
|
868
|
+
Provide custom headers for authenticated requests (JWT, API keys, etc.):
|
|
672
869
|
|
|
673
870
|
```tsx
|
|
674
871
|
<DocViewer
|
|
@@ -685,25 +882,86 @@ Provide custom headers for authenticated requests:
|
|
|
685
882
|
## FAQ
|
|
686
883
|
|
|
687
884
|
**What is the best React document viewer library?**
|
|
688
|
-
|
|
885
|
+
`@iamjariwala/react-doc-viewer` is the most feature-complete open-source React document viewer. It supports 20+ file types (PDF, Word, Excel, PowerPoint, images, video, CSV, HTML, and more) in a single component with built-in annotations, drag-and-drop, thumbnail navigation, theming, and i18n -- features that most alternatives require paid licenses or multiple libraries to achieve.
|
|
689
886
|
|
|
690
887
|
**How do I display a PDF in React?**
|
|
691
888
|
Install `@iamjariwala/react-doc-viewer`, import `DocViewer` and `DocViewerRenderers`, pass your PDF URL as a document, and the component handles rendering, zoom, pagination, and page navigation automatically. See [Quick Start](#quick-start).
|
|
692
889
|
|
|
890
|
+
**How do I display a PDF in Next.js?**
|
|
891
|
+
Add the `"use client"` directive to your component, import `DocViewer` with the CSS file, and pass your PDF document. Works with both App Router and Pages Router. See [Next.js guide](#nextjs-app-router--pages-router).
|
|
892
|
+
|
|
693
893
|
**Can I view Word, Excel, and PowerPoint files in React?**
|
|
694
|
-
Yes. This library recognizes `.doc`, `.docx`, `.xls`, `.xlsx`, `.ppt`, and `.pptx` files and renders them as download cards showing file name, type, and a download link. No external service or public URL is required.
|
|
894
|
+
Yes. This library recognizes `.doc`, `.docx`, `.xls`, `.xlsx`, `.ppt`, and `.pptx` files and renders them as download cards showing file name, type, and a download link. No external service or public URL is required. For inline rendering, you can create a [Custom Renderer](#custom-renderer).
|
|
695
895
|
|
|
696
896
|
**Does it support annotations and highlighting?**
|
|
697
|
-
Yes. Enable annotations via config to get text highlighting, freehand drawing, comments, and an eraser tool. Annotations can be exported as JSON and pre-loaded from saved data. See [Annotations](#annotations).
|
|
897
|
+
Yes. Enable annotations via config to get text highlighting, freehand drawing, comments, and an eraser tool. Annotations can be exported as JSON and pre-loaded from saved data. See [Annotations](#annotations-highlight-draw-comment).
|
|
898
|
+
|
|
899
|
+
**Can I annotate a PDF in React?**
|
|
900
|
+
Yes. Enable `config.annotations.enableAnnotations` to get a full annotation toolbar with highlighting, freehand drawing, comments, color picker, and eraser. Annotations are per-page and can be exported/imported as JSON.
|
|
698
901
|
|
|
699
902
|
**Does it work with Next.js?**
|
|
700
|
-
Yes. The library works with Next.js and
|
|
903
|
+
Yes. The library works with Next.js (App Router and Pages Router), Vite, Create React App, Remix, Gatsby, and any React 17+ project. See [Framework Guides](#framework-guides).
|
|
904
|
+
|
|
905
|
+
**Does it work with Vite?**
|
|
906
|
+
Yes. Import the component and CSS file -- no additional configuration needed. See [Vite guide](#vite).
|
|
701
907
|
|
|
702
908
|
**Can I add my own file type renderer?**
|
|
703
909
|
Yes. Create a custom renderer component with `fileTypes` and `weight` properties and pass it via `pluginRenderers`. You can also override the file loading logic. See [Custom Renderer](#custom-renderer).
|
|
704
910
|
|
|
911
|
+
**How do I style or theme the document viewer?**
|
|
912
|
+
Use the `theme` prop for color customization, the `className` or `style` props for container styling, or override `.rdv-*` CSS classes and `--rdv-*` CSS custom properties for fine-grained control. See [Theming](#theming--css-variables) and [Styling](#styling--css-customization).
|
|
913
|
+
|
|
914
|
+
**Is it secure? Does it send data to external servers?**
|
|
915
|
+
No data leaves the browser. All rendering is client-side. HTML content is sanitized with DOMPurify to prevent XSS. MS Office files render locally as download cards -- no Microsoft iframe. See [Security](#security).
|
|
916
|
+
|
|
705
917
|
**How does this compare to react-pdf?**
|
|
706
|
-
react-pdf only handles PDF files.
|
|
918
|
+
react-pdf only handles PDF files. `@iamjariwala/react-doc-viewer` handles 20+ file types including PDF, and adds drag-and-drop, annotations, thumbnails, theming, and i18n on top. If you only need PDF rendering, react-pdf is lighter. If you need multi-format support or advanced features, this library covers more ground.
|
|
919
|
+
|
|
920
|
+
**How do I reduce bundle size?**
|
|
921
|
+
Import only the renderers you need (`PDFRenderer`, `PNGRenderer`, etc.) instead of `DocViewerRenderers`. Use `React.lazy()` to code-split the viewer. See [Performance](#performance--bundle-size).
|
|
922
|
+
|
|
923
|
+
**Does it support drag-and-drop file upload?**
|
|
924
|
+
Yes. Enable `config.dragDrop.enableDragDrop` to allow users to drag files onto the viewer. Supports file type filtering, size limits, append/replace behavior, and rejection callbacks. See [Drag & Drop](#drag--drop-file-upload).
|
|
925
|
+
|
|
926
|
+
**Does it support thumbnail navigation?**
|
|
927
|
+
Yes. Enable `config.thumbnail.enableThumbnails` to show a sidebar with page thumbnails for PDFs. Click any thumbnail to jump to that page. See [Thumbnail Sidebar](#thumbnail-sidebar).
|
|
928
|
+
|
|
929
|
+
**Can I jump to a specific page in a PDF?**
|
|
930
|
+
Yes. Use `docViewerRef.current?.goToPage(5)` for programmatic navigation, or the `jumpToPage` prop for declarative control. See [Page Navigation](#page-navigation--page-jump).
|
|
931
|
+
|
|
932
|
+
**Does it support TypeScript?**
|
|
933
|
+
Yes. The library is written in TypeScript and ships with complete type definitions. All props, config options, and hooks are fully typed with IntelliSense support.
|
|
934
|
+
|
|
935
|
+
**What React versions are supported?**
|
|
936
|
+
React 17, 18, and 19 are supported via `peerDependencies: "react": ">=17.0.0"`.
|
|
937
|
+
|
|
938
|
+
**Is it accessible?**
|
|
939
|
+
The viewer uses semantic HTML, keyboard-navigable controls, and appropriate ARIA attributes where applicable.
|
|
940
|
+
|
|
941
|
+
## Migrating from Other Libraries
|
|
942
|
+
|
|
943
|
+
### From @cyntler/react-doc-viewer
|
|
944
|
+
|
|
945
|
+
`@iamjariwala/react-doc-viewer` is a fork of `@cyntler/react-doc-viewer` with additional features. Migration is straightforward:
|
|
946
|
+
|
|
947
|
+
1. Replace the package: `npm uninstall @cyntler/react-doc-viewer && npm install @iamjariwala/react-doc-viewer`
|
|
948
|
+
2. Update imports: replace `@cyntler/react-doc-viewer` with `@iamjariwala/react-doc-viewer`
|
|
949
|
+
3. Add the CSS import: `import "@iamjariwala/react-doc-viewer/dist/index.css"`
|
|
950
|
+
4. All existing props and config options are compatible
|
|
951
|
+
|
|
952
|
+
### From react-pdf
|
|
953
|
+
|
|
954
|
+
If you're using `react-pdf` and need multi-format support:
|
|
955
|
+
|
|
956
|
+
1. Install: `npm install @iamjariwala/react-doc-viewer`
|
|
957
|
+
2. Replace `<Document>` + `<Page>` with `<DocViewer documents={[{ uri: pdfUrl }]} />`
|
|
958
|
+
3. The built-in PDF renderer handles zoom, pagination, and page navigation automatically
|
|
959
|
+
|
|
960
|
+
### From react-file-viewer
|
|
961
|
+
|
|
962
|
+
1. Install: `npm install @iamjariwala/react-doc-viewer`
|
|
963
|
+
2. Replace `<FileViewer fileType={type} filePath={path} />` with `<DocViewer documents={[{ uri: path }]} />`
|
|
964
|
+
3. File type is detected automatically from the URL or can be specified via `fileType` property
|
|
707
965
|
|
|
708
966
|
## Contributing
|
|
709
967
|
|
|
@@ -722,4 +980,4 @@ npm start
|
|
|
722
980
|
|
|
723
981
|
---
|
|
724
982
|
|
|
725
|
-
<sub>Forked from [@cyntler/react-doc-viewer](https://github.com/cyntler/react-doc-viewer).</sub>
|
|
983
|
+
<sub>Forked from [@cyntler/react-doc-viewer](https://github.com/cyntler/react-doc-viewer). Built and maintained by [Mehul Jariwala](https://github.com/mehuljariwala).</sub>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iamjariwala/react-doc-viewer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "React document viewer and PDF viewer component — render PDF, Word, Excel, PowerPoint, images, video, CSV and 20+ file types with drag-and-drop, annotations, thumbnails and i18n.",
|
|
5
5
|
"author": "Mehul Jariwala",
|
|
6
6
|
"type": "module",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"file-preview",
|
|
15
15
|
"pdf-viewer",
|
|
16
16
|
"pdf-reader",
|
|
17
|
+
"pdf-renderer",
|
|
17
18
|
"pdf",
|
|
18
19
|
"doc-viewer",
|
|
19
20
|
"office-viewer",
|
|
@@ -27,8 +28,11 @@
|
|
|
27
28
|
"image-viewer",
|
|
28
29
|
"video-player",
|
|
29
30
|
"html-viewer",
|
|
31
|
+
"tiff-viewer",
|
|
30
32
|
"tiff",
|
|
31
33
|
"webp",
|
|
34
|
+
"bmp",
|
|
35
|
+
"gif",
|
|
32
36
|
"odt",
|
|
33
37
|
"viewer",
|
|
34
38
|
"preview",
|
|
@@ -36,23 +40,58 @@
|
|
|
36
40
|
"renderer",
|
|
37
41
|
"drag-and-drop",
|
|
38
42
|
"file-upload",
|
|
43
|
+
"dropzone",
|
|
39
44
|
"annotations",
|
|
40
45
|
"pdf-annotations",
|
|
41
46
|
"highlight",
|
|
42
47
|
"drawing",
|
|
48
|
+
"freehand-drawing",
|
|
49
|
+
"commenting",
|
|
50
|
+
"markup",
|
|
43
51
|
"thumbnail",
|
|
52
|
+
"thumbnail-sidebar",
|
|
44
53
|
"page-navigation",
|
|
54
|
+
"page-jump",
|
|
45
55
|
"zoom",
|
|
46
56
|
"react-pdf",
|
|
47
57
|
"react-viewer",
|
|
48
58
|
"react-document",
|
|
49
59
|
"typescript",
|
|
50
60
|
"i18n",
|
|
61
|
+
"internationalization",
|
|
62
|
+
"localization",
|
|
51
63
|
"multi-format",
|
|
64
|
+
"multi-file",
|
|
52
65
|
"react17",
|
|
53
66
|
"react18",
|
|
67
|
+
"react19",
|
|
54
68
|
"nextjs",
|
|
55
|
-
"
|
|
69
|
+
"next-js",
|
|
70
|
+
"vite",
|
|
71
|
+
"remix",
|
|
72
|
+
"gatsby",
|
|
73
|
+
"create-react-app",
|
|
74
|
+
"cra",
|
|
75
|
+
"document-management",
|
|
76
|
+
"dms",
|
|
77
|
+
"file-browser",
|
|
78
|
+
"content-platform",
|
|
79
|
+
"pdf-component",
|
|
80
|
+
"embed-pdf",
|
|
81
|
+
"display-pdf",
|
|
82
|
+
"render-pdf",
|
|
83
|
+
"view-pdf",
|
|
84
|
+
"open-source",
|
|
85
|
+
"apache-2",
|
|
86
|
+
"tree-shakeable",
|
|
87
|
+
"css-variables",
|
|
88
|
+
"themeable",
|
|
89
|
+
"customizable",
|
|
90
|
+
"lightweight",
|
|
91
|
+
"responsive",
|
|
92
|
+
"accessible",
|
|
93
|
+
"ssr",
|
|
94
|
+
"server-side-rendering"
|
|
56
95
|
],
|
|
57
96
|
"license": "Apache-2.0",
|
|
58
97
|
"homepage": "https://github.com/mehuljariwala/react-doc-viewer",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|