@iamjariwala/react-doc-viewer 1.0.0 → 1.1.1
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 +381 -113
- package/dist/DocViewer.d.ts +21 -0
- package/dist/components/DocumentNav.d.ts +3 -0
- package/dist/components/FileName.d.ts +3 -0
- package/dist/components/HeaderBar.d.ts +3 -0
- package/dist/components/LoadingTimout.d.ts +3 -0
- package/dist/components/ProxyRenderer.d.ts +3 -0
- package/dist/components/common/Button.d.ts +13 -0
- package/dist/components/common/index.d.ts +1 -0
- package/dist/components/icons/index.d.ts +8 -0
- package/dist/cssStyles.d.ts +1 -0
- package/dist/defaultTheme.d.ts +3 -0
- package/dist/empty-DBAFSQIv.cjs +1 -0
- package/dist/empty-GlqisfcO.js +4 -0
- package/dist/features/annotations/components/AnnotationLayer.d.ts +10 -0
- package/dist/features/annotations/components/AnnotationToolbar.d.ts +3 -0
- package/dist/features/annotations/components/ColorPicker.d.ts +3 -0
- package/dist/features/annotations/components/CommentMarker.d.ts +8 -0
- package/dist/features/annotations/components/CommentPopover.d.ts +9 -0
- package/dist/features/annotations/components/TextHighlight.d.ts +8 -0
- package/dist/features/annotations/components/icons/index.d.ts +13 -0
- package/dist/features/annotations/hooks/useAnnotationExport.d.ts +9 -0
- package/dist/features/annotations/hooks/useDrawingCanvas.d.ts +15 -0
- package/dist/features/annotations/hooks/useTextSelection.d.ts +10 -0
- package/dist/features/annotations/index.d.ts +13 -0
- package/dist/features/annotations/state/actions.d.ts +52 -0
- package/dist/features/annotations/state/index.d.ts +17 -0
- package/dist/features/annotations/state/reducer.d.ts +17 -0
- package/dist/features/annotations/types/index.d.ts +44 -0
- package/dist/features/drag-drop/components/DropZoneOverlay.d.ts +9 -0
- package/dist/features/drag-drop/hooks/useDragDrop.d.ts +11 -0
- package/dist/features/drag-drop/hooks/useFileProcessor.d.ts +13 -0
- package/dist/features/drag-drop/index.d.ts +4 -0
- package/dist/features/drag-drop/types/index.d.ts +19 -0
- package/dist/features/thumbnail-sidebar/components/ThumbnailItem.d.ts +11 -0
- package/dist/features/thumbnail-sidebar/components/ThumbnailSidebar.d.ts +8 -0
- package/dist/features/thumbnail-sidebar/components/ThumbnailToggle.d.ts +7 -0
- package/dist/features/thumbnail-sidebar/hooks/useThumbnailGenerator.d.ts +13 -0
- package/dist/features/thumbnail-sidebar/index.d.ts +6 -0
- package/dist/features/thumbnail-sidebar/state/actions.d.ts +31 -0
- package/dist/features/thumbnail-sidebar/state/index.d.ts +15 -0
- package/dist/features/thumbnail-sidebar/state/reducer.d.ts +11 -0
- package/dist/hooks/useDocumentLoader.d.ts +13 -0
- package/dist/hooks/useRendererSelector.d.ts +5 -0
- package/dist/hooks/useTranslation.d.ts +3 -0
- package/dist/hooks/useWindowSize.d.ts +4 -0
- package/dist/i18n.d.ts +158 -0
- package/dist/index-BRIDmekZ.js +3350 -0
- package/dist/index-BbWLdN1j.js +19664 -0
- package/dist/index-C5fDV20X.cjs +10 -0
- package/dist/index-Dr6cyq4L.js +42 -0
- package/dist/index-DtsNvZYP.cjs +1 -0
- package/dist/index-J-2Hm65K.cjs +46 -0
- package/dist/index.css +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/locales/ar.json.d.ts +13 -0
- package/dist/locales/de.json.d.ts +13 -0
- package/dist/locales/en.json.d.ts +26 -0
- package/dist/locales/es.json.d.ts +13 -0
- package/dist/locales/fr.json.d.ts +13 -0
- package/dist/locales/it.json.d.ts +13 -0
- package/dist/locales/ja.json.d.ts +13 -0
- package/dist/locales/pl.json.d.ts +13 -0
- package/dist/locales/pt.json.d.ts +13 -0
- package/dist/locales/ru.json.d.ts +13 -0
- package/dist/locales/se.json.d.ts +13 -0
- package/dist/locales/sr.json.d.ts +13 -0
- package/dist/locales/sr_cyr.json.d.ts +13 -0
- package/dist/locales/tr.json.d.ts +13 -0
- package/dist/models.d.ts +119 -0
- package/dist/react-doc-viewer.cjs +1 -0
- package/dist/react-doc-viewer.js +23 -0
- package/dist/renderers/bmp/index.d.ts +4 -0
- package/dist/renderers/csv/index.d.ts +4 -0
- package/dist/renderers/gif/index.d.ts +4 -0
- package/dist/renderers/html/index.d.ts +4 -0
- package/dist/renderers/image/index.d.ts +4 -0
- package/dist/renderers/index.d.ts +15 -0
- package/dist/renderers/jpg/index.d.ts +4 -0
- package/dist/renderers/msdoc/index.d.ts +4 -0
- package/dist/renderers/pdf/components/PDFControls.d.ts +4 -0
- package/dist/renderers/pdf/components/PDFPagination.d.ts +4 -0
- package/dist/renderers/pdf/components/PDFThumbnailGenerator.d.ts +3 -0
- package/dist/renderers/pdf/components/icons/index.d.ts +9 -0
- package/dist/renderers/pdf/components/pages/PDFAllPages.d.ts +7 -0
- package/dist/renderers/pdf/components/pages/PDFPages.d.ts +4 -0
- package/dist/renderers/pdf/components/pages/PDFSinglePage.d.ts +7 -0
- package/dist/renderers/pdf/index.d.ts +4 -0
- package/dist/renderers/pdf/state/actions.d.ts +32 -0
- package/dist/renderers/pdf/state/index.d.ts +13 -0
- package/dist/renderers/pdf/state/reducer.d.ts +15 -0
- package/dist/renderers/png/index.d.ts +4 -0
- package/dist/renderers/tiff/index.d.ts +4 -0
- package/dist/renderers/tiff/tiffToCanvas.d.ts +1 -0
- package/dist/renderers/txt/index.d.ts +4 -0
- package/dist/renderers/video/index.d.ts +4 -0
- package/dist/renderers/webp/index.d.ts +4 -0
- package/dist/store/DocViewerProvider.d.ts +22 -0
- package/dist/store/actions.d.ts +63 -0
- package/dist/store/mainStateReducer.d.ts +23 -0
- package/dist/url-5wjrlwUG.js +560 -0
- package/dist/url-DLGc3bZT.cjs +3 -0
- package/dist/utils/fileLoaders.d.ts +13 -0
- package/dist/utils/getFileName.d.ts +3 -0
- package/package.json +46 -9
package/README.md
CHANGED
|
@@ -1,24 +1,72 @@
|
|
|
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
|
| ------- | :--: | :--: | :--: | :--: |
|
|
@@ -27,17 +75,22 @@ Most React document viewers only handle PDFs or require expensive commercial lic
|
|
|
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,17 +98,20 @@ 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
|
|
|
53
|
-
### What's New in
|
|
106
|
+
### What's New in v1.1.0
|
|
107
|
+
|
|
108
|
+
- **Security: HTML XSS fix** -- HTML renderer now sanitizes content with DOMPurify before rendering
|
|
109
|
+
- **Security: MS Office docs** -- Removed external iframe dependency; Office files now render as download cards with file info
|
|
110
|
+
- **Removed styled-components** -- All styling migrated to plain CSS with CSS custom properties, reducing bundle size
|
|
111
|
+
- **Smaller bundle** -- Removed `styled-components`, `core-js`, and `ajv` dependencies (~300-400KB savings)
|
|
112
|
+
- **CSS custom properties** -- Theming now uses `--rdv-*` CSS variables for full customizability
|
|
54
113
|
|
|
55
|
-
|
|
56
|
-
- **Thumbnail Sidebar** -- Visual page navigation with auto-scroll for PDFs
|
|
57
|
-
- **Annotations** -- Highlight text, freehand draw, and add comments with export support
|
|
58
|
-
- **Page Jump** -- Navigate to any page programmatically via ref or prop
|
|
114
|
+
---
|
|
59
115
|
|
|
60
116
|
## Table of Contents
|
|
61
117
|
|
|
@@ -67,6 +123,11 @@ Most React document viewers only handle PDFs or require expensive commercial lic
|
|
|
67
123
|
- [Live Demo](#live-demo)
|
|
68
124
|
- [Installation](#installation)
|
|
69
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)
|
|
70
131
|
- [Documents](#documents)
|
|
71
132
|
- [Remote & Local Files](#remote--local-files)
|
|
72
133
|
- [Initial Active Document](#initial-active-document)
|
|
@@ -77,23 +138,26 @@ Most React document viewers only handle PDFs or require expensive commercial lic
|
|
|
77
138
|
- [Custom Renderer](#custom-renderer)
|
|
78
139
|
- [Custom File Loader](#custom-file-loader)
|
|
79
140
|
- [Features](#features)
|
|
80
|
-
- [Drag & Drop](#drag--drop)
|
|
141
|
+
- [Drag & Drop File Upload](#drag--drop-file-upload)
|
|
81
142
|
- [Thumbnail Sidebar](#thumbnail-sidebar)
|
|
82
|
-
- [Annotations](#annotations)
|
|
83
|
-
- [Page Navigation](#page-navigation)
|
|
143
|
+
- [Annotations (Highlight, Draw, Comment)](#annotations-highlight-draw-comment)
|
|
144
|
+
- [Page Navigation & Page Jump](#page-navigation--page-jump)
|
|
84
145
|
- [Configuration](#configuration)
|
|
85
146
|
- [Full Config Reference](#full-config-reference)
|
|
86
147
|
- [Overriding Header](#overriding-header)
|
|
87
148
|
- [Overriding Loading Renderer](#overriding-loading-renderer)
|
|
88
149
|
- [Overriding No Renderer (Error)](#overriding-no-renderer-error)
|
|
89
|
-
- [Theming](#theming)
|
|
90
|
-
- [Styling](#styling)
|
|
91
|
-
- [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)
|
|
92
155
|
- [Advanced](#advanced)
|
|
93
|
-
- [DocViewerRef](#docviewerref)
|
|
94
|
-
- [Custom HTTP Verb](#custom-http-verb)
|
|
95
|
-
- [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)
|
|
96
159
|
- [FAQ](#faq)
|
|
160
|
+
- [Migrating from Other Libraries](#migrating-from-other-libraries)
|
|
97
161
|
- [Contributing](#contributing)
|
|
98
162
|
- [License](#license)
|
|
99
163
|
|
|
@@ -101,32 +165,36 @@ Most React document viewers only handle PDFs or require expensive commercial lic
|
|
|
101
165
|
|
|
102
166
|
## Supported File Types
|
|
103
167
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
|
107
|
-
|
|
|
108
|
-
|
|
|
109
|
-
|
|
|
110
|
-
|
|
|
111
|
-
|
|
|
112
|
-
|
|
|
113
|
-
|
|
|
114
|
-
|
|
|
115
|
-
|
|
|
116
|
-
|
|
|
117
|
-
|
|
|
118
|
-
|
|
|
119
|
-
|
|
|
120
|
-
|
|
|
121
|
-
|
|
|
122
|
-
|
|
|
123
|
-
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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 |
|
|
183
|
+
| doc | `application/msword` | Download card |
|
|
184
|
+
| docx | `application/vnd.openxmlformats-officedocument.wordprocessingml.document` | Download card |
|
|
185
|
+
| xls | `application/vnd.ms-excel` | Download card |
|
|
186
|
+
| xlsx | `application/vnd.openxmlformats-officedocument.spreadsheetml.sheet` | Download card |
|
|
187
|
+
| ppt | `application/vnd.ms-powerpoint` | Download card |
|
|
188
|
+
| pptx | `application/vnd.openxmlformats-officedocument.presentationml.presentation` | Download card |
|
|
189
|
+
| odt | `application/vnd.oasis.opendocument.text` | Download card |
|
|
190
|
+
|
|
191
|
+
> [!NOTE]
|
|
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.
|
|
127
193
|
|
|
128
194
|
## Live Demo
|
|
129
195
|
|
|
196
|
+
Try all features interactively:
|
|
197
|
+
|
|
130
198
|
[Storybook Demo](https://mehuljariwala.github.io/react-doc-viewer)
|
|
131
199
|
|
|
132
200
|
## Installation
|
|
@@ -143,6 +211,10 @@ yarn add @iamjariwala/react-doc-viewer
|
|
|
143
211
|
pnpm add @iamjariwala/react-doc-viewer
|
|
144
212
|
```
|
|
145
213
|
|
|
214
|
+
```bash
|
|
215
|
+
bun add @iamjariwala/react-doc-viewer
|
|
216
|
+
```
|
|
217
|
+
|
|
146
218
|
## Quick Start
|
|
147
219
|
|
|
148
220
|
```tsx
|
|
@@ -159,7 +231,85 @@ function App() {
|
|
|
159
231
|
}
|
|
160
232
|
```
|
|
161
233
|
|
|
162
|
-
> 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
|
+
```
|
|
163
313
|
|
|
164
314
|
## Documents
|
|
165
315
|
|
|
@@ -239,7 +389,7 @@ import DocViewer, { DocViewerRenderers } from "@iamjariwala/react-doc-viewer";
|
|
|
239
389
|
<DocViewer pluginRenderers={DocViewerRenderers} documents={docs} />;
|
|
240
390
|
```
|
|
241
391
|
|
|
242
|
-
Or import only what you need:
|
|
392
|
+
Or import only what you need for smaller bundles:
|
|
243
393
|
|
|
244
394
|
```tsx
|
|
245
395
|
import DocViewer, { PDFRenderer, PNGRenderer } from "@iamjariwala/react-doc-viewer";
|
|
@@ -281,9 +431,9 @@ MyPNGRenderer.fileLoader = ({ documentURI, signal, fileLoaderComplete }) => {
|
|
|
281
431
|
|
|
282
432
|
## Features
|
|
283
433
|
|
|
284
|
-
### Drag & Drop
|
|
434
|
+
### Drag & Drop File Upload
|
|
285
435
|
|
|
286
|
-
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.
|
|
287
437
|
|
|
288
438
|
```tsx
|
|
289
439
|
<DocViewer
|
|
@@ -317,7 +467,7 @@ Enable file drag-and-drop to add or replace documents in the viewer.
|
|
|
317
467
|
|
|
318
468
|
### Thumbnail Sidebar
|
|
319
469
|
|
|
320
|
-
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.
|
|
321
471
|
|
|
322
472
|
```tsx
|
|
323
473
|
<DocViewer
|
|
@@ -339,9 +489,9 @@ Display a visual sidebar with page thumbnails for quick PDF navigation.
|
|
|
339
489
|
| `thumbnailWidth` | `number` | `120` | Width of each thumbnail in pixels |
|
|
340
490
|
| `sidebarDefaultOpen` | `boolean` | `false` | Open sidebar by default |
|
|
341
491
|
|
|
342
|
-
### Annotations
|
|
492
|
+
### Annotations (Highlight, Draw, Comment)
|
|
343
493
|
|
|
344
|
-
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.
|
|
345
495
|
|
|
346
496
|
```tsx
|
|
347
497
|
<DocViewer
|
|
@@ -393,7 +543,7 @@ function AnnotationControls() {
|
|
|
393
543
|
}
|
|
394
544
|
```
|
|
395
545
|
|
|
396
|
-
### Page Navigation
|
|
546
|
+
### Page Navigation & Page Jump
|
|
397
547
|
|
|
398
548
|
Jump to a specific page using a ref or the `jumpToPage` prop.
|
|
399
549
|
|
|
@@ -536,9 +686,9 @@ const MyError = ({ document, fileName }: { document: IDocument | undefined; file
|
|
|
536
686
|
/>;
|
|
537
687
|
```
|
|
538
688
|
|
|
539
|
-
## Theming
|
|
689
|
+
## Theming & CSS Variables
|
|
540
690
|
|
|
541
|
-
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.
|
|
542
692
|
|
|
543
693
|
```tsx
|
|
544
694
|
<DocViewer
|
|
@@ -556,17 +706,17 @@ Customize the viewer's appearance with a theme object:
|
|
|
556
706
|
/>
|
|
557
707
|
```
|
|
558
708
|
|
|
559
|
-
| Property |
|
|
560
|
-
| -------- |
|
|
561
|
-
| `primary` | `
|
|
562
|
-
| `secondary` | `
|
|
563
|
-
| `tertiary` | `
|
|
564
|
-
| `textPrimary` | `
|
|
565
|
-
| `textSecondary` | `
|
|
566
|
-
| `textTertiary` | `
|
|
567
|
-
| `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 |
|
|
568
718
|
|
|
569
|
-
## Styling
|
|
719
|
+
## Styling & CSS Customization
|
|
570
720
|
|
|
571
721
|
**CSS class:**
|
|
572
722
|
|
|
@@ -580,30 +730,56 @@ Customize the viewer's appearance with a theme object:
|
|
|
580
730
|
<DocViewer documents={docs} pluginRenderers={DocViewerRenderers} style={{ width: 500, height: 500 }} />
|
|
581
731
|
```
|
|
582
732
|
|
|
583
|
-
**
|
|
733
|
+
**Override internal elements with CSS classes:**
|
|
584
734
|
|
|
585
|
-
|
|
586
|
-
import styled from "styled-components";
|
|
587
|
-
import DocViewer from "@iamjariwala/react-doc-viewer";
|
|
735
|
+
All internal elements use `.rdv-*` class names that you can target:
|
|
588
736
|
|
|
589
|
-
|
|
737
|
+
```css
|
|
738
|
+
.rdv-container {
|
|
590
739
|
border-radius: 10px;
|
|
591
|
-
|
|
740
|
+
}
|
|
592
741
|
|
|
593
|
-
|
|
742
|
+
.rdv-header-bar {
|
|
743
|
+
background-color: #faf;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
.rdv-pdf-controls {
|
|
747
|
+
gap: 12px;
|
|
748
|
+
}
|
|
594
749
|
```
|
|
595
750
|
|
|
596
|
-
**Override
|
|
751
|
+
**Override CSS custom properties globally:**
|
|
597
752
|
|
|
598
753
|
```css
|
|
599
|
-
#react-doc-viewer
|
|
600
|
-
|
|
754
|
+
#react-doc-viewer {
|
|
755
|
+
--rdv-primary: #1a1a2e;
|
|
756
|
+
--rdv-secondary: #16213e;
|
|
757
|
+
--rdv-text-primary: #e94560;
|
|
601
758
|
}
|
|
602
759
|
```
|
|
603
760
|
|
|
604
|
-
|
|
761
|
+
**Common CSS class reference:**
|
|
605
762
|
|
|
606
|
-
|
|
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:
|
|
607
783
|
|
|
608
784
|
```tsx
|
|
609
785
|
<DocViewer documents={docs} pluginRenderers={DocViewerRenderers} language="pl" />
|
|
@@ -611,28 +787,53 @@ Pass a `language` prop to translate the UI:
|
|
|
611
787
|
|
|
612
788
|
**Supported languages:**
|
|
613
789
|
|
|
614
|
-
| Code | Language |
|
|
615
|
-
| ---- | -------- |
|
|
616
|
-
| `en` | English |
|
|
617
|
-
| `ar` | Arabic |
|
|
618
|
-
| `de` | German |
|
|
619
|
-
| `es` | Spanish |
|
|
620
|
-
| `fr` | French |
|
|
621
|
-
| `it` | Italian |
|
|
622
|
-
| `
|
|
623
|
-
| `pl` | Polish |
|
|
624
|
-
| `pt` | Portuguese |
|
|
625
|
-
| `ru` | Russian |
|
|
626
|
-
| `se` | Swedish |
|
|
627
|
-
| `sr` | Serbian (Latin) |
|
|
628
|
-
| `sr_cyr` | Serbian (Cyrillic) |
|
|
629
|
-
| `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) |
|
|
630
799
|
|
|
631
800
|
Translation files are in `src/locales/`. PRs for new languages are welcome.
|
|
632
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
|
+
|
|
633
834
|
## Advanced
|
|
634
835
|
|
|
635
|
-
### DocViewerRef
|
|
836
|
+
### DocViewerRef API
|
|
636
837
|
|
|
637
838
|
Control the viewer programmatically:
|
|
638
839
|
|
|
@@ -648,17 +849,23 @@ docViewerRef.current?.next();
|
|
|
648
849
|
docViewerRef.current?.goToPage(3);
|
|
649
850
|
```
|
|
650
851
|
|
|
651
|
-
|
|
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 |
|
|
857
|
+
|
|
858
|
+
### Custom HTTP Verb for S3 / Cloud Storage
|
|
652
859
|
|
|
653
|
-
Some services (like AWS S3) require a specific HTTP verb for pre-fetching. By default, `HEAD` is used:
|
|
860
|
+
Some services (like AWS S3 pre-signed URLs) require a specific HTTP verb for pre-fetching. By default, `HEAD` is used:
|
|
654
861
|
|
|
655
862
|
```tsx
|
|
656
863
|
<DocViewer documents={docs} pluginRenderers={DocViewerRenderers} prefetchMethod="GET" />
|
|
657
864
|
```
|
|
658
865
|
|
|
659
|
-
### Custom Request Headers
|
|
866
|
+
### Custom Request Headers for Authenticated APIs
|
|
660
867
|
|
|
661
|
-
Provide custom headers for authenticated requests:
|
|
868
|
+
Provide custom headers for authenticated requests (JWT, API keys, etc.):
|
|
662
869
|
|
|
663
870
|
```tsx
|
|
664
871
|
<DocViewer
|
|
@@ -675,25 +882,86 @@ Provide custom headers for authenticated requests:
|
|
|
675
882
|
## FAQ
|
|
676
883
|
|
|
677
884
|
**What is the best React document viewer library?**
|
|
678
|
-
|
|
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.
|
|
679
886
|
|
|
680
887
|
**How do I display a PDF in React?**
|
|
681
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).
|
|
682
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
|
+
|
|
683
893
|
**Can I view Word, Excel, and PowerPoint files in React?**
|
|
684
|
-
Yes. This library
|
|
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).
|
|
685
895
|
|
|
686
896
|
**Does it support annotations and highlighting?**
|
|
687
|
-
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.
|
|
688
901
|
|
|
689
902
|
**Does it work with Next.js?**
|
|
690
|
-
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).
|
|
691
907
|
|
|
692
908
|
**Can I add my own file type renderer?**
|
|
693
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).
|
|
694
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
|
+
|
|
695
917
|
**How does this compare to react-pdf?**
|
|
696
|
-
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
|
|
697
965
|
|
|
698
966
|
## Contributing
|
|
699
967
|
|
|
@@ -712,4 +980,4 @@ npm start
|
|
|
712
980
|
|
|
713
981
|
---
|
|
714
982
|
|
|
715
|
-
<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>
|