Skip to content

Commit 67b1cc7

Browse files
committed
Update readme
1 parent c768e49 commit 67b1cc7

1 file changed

Lines changed: 28 additions & 62 deletions

File tree

README.md

Lines changed: 28 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,21 @@ Supported in all [major browsers](https://caniuse.com/custom-elementsv1), and wo
1414

1515
## Features
1616

17-
- Simple PDF.js viewer integration to any web application
18-
- PDF.js viewer options and parameters support, access the viewer application instance
19-
- Customize viewer styles and themes
17+
- Standalone web component with no runtime dependencies
18+
- Drop-in, iframe-based PDF.js default viewer for any web app
19+
- Configure via attributes and URL parameters (page, zoom, search, pagemode, locale, named destination)
20+
- Programmatic access to `PDFViewerApplication` and `PDFViewerApplicationOptions` via the `initialized` event
21+
- Theme control (automatic/light/dark) plus custom CSS injection or external stylesheets
22+
- Locale override support using PDF.js viewer locales
23+
- Works in modern browsers and most JS frameworks
2024

2125
## Docs
2226

2327
[Getting started](https://alekswebnet.github.io/pdfjs-viewer-element/)
2428

2529
[API playground](https://alekswebnet.github.io/pdfjs-viewer-element/#api)
2630

27-
[Usage with frameworks](https://alekswebnet.github.io/pdfjs-viewer-element/#demo)
28-
29-
[Various usecases](https://github.com/alekswebnet/pdfjs-viewer-element/tree/master/demo)
30-
31-
## How it works
32-
33-
**⚠️ This is an important part, please read this FIRST !!!**
34-
35-
**You should download and place the PDF.js prebuilt files in the project.**
36-
37-
`pdfjs-viewer-element` requires [PDF.js prebuilt](http://mozilla.github.io/pdf.js/getting_started/), that includes the generic build of PDF.js and the viewer.
38-
39-
The prebuilt comes with each PDF.js release. [PDF.JS releases](https://github.com/mozilla/pdf.js/releases)
40-
41-
✅ All v3, v4 and v5 releases are fully supported.
42-
43-
After placing the prebuild specify the path to the directory with the `viewer-path` property (`/pdfjs` by default) and PDF file URL with `src` property (should refer to the [same origin](https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#can-i-load-a-pdf-from-another-server-cross-domain-request)).
31+
[Various use cases](https://github.com/alekswebnet/pdfjs-viewer-element/tree/master/demo)
4432

4533
## Install
4634

@@ -49,8 +37,6 @@ After placing the prebuild specify the path to the directory with the `viewer-pa
4937
```bash
5038
# With npm
5139
npm install pdfjs-viewer-element
52-
# With yarn
53-
yarn add pdfjs-viewer-element
5440
# With pnpm
5541
pnpm add pdfjs-viewer-element
5642
```
@@ -68,21 +54,17 @@ import 'pdfjs-viewer-element'
6854
## Usage
6955

7056
```html
71-
<pdfjs-viewer-element src="/file.pdf" viewer-path="/pdfjs-5.3.93-dist"></pdfjs-viewer-element>
57+
<pdfjs-viewer-element src="path-to/file.pdf"></pdfjs-viewer-element>
7258
```
7359

7460
## Attributes
7561

7662
`src` - PDF file URL, should refer to the [same origin](https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#can-i-load-a-pdf-from-another-server-cross-domain-request)
7763

78-
`viewer-path` - Path to PDF.js [prebuilt](http://mozilla.github.io/pdf.js/getting_started/)
79-
8064
`iframe-title` - The title of the `iframe` element, required for better accessibility
8165

8266
`page` - Page number.
8367

84-
`nameddest` - Go to a named destination.
85-
8668
`search` - Search text.
8769

8870
`phrase` - Search by phrase, `true` to enable.
@@ -91,20 +73,6 @@ import 'pdfjs-viewer-element'
9173

9274
`pagemode` - Page mode, `thumbs | bookmarks | attachments | layers | none`.
9375

94-
`disable-worker` - Disables the worker, `true` to enable.
95-
96-
`text-layer` - Disables or reveals the text layer that is used for text selection, `off | visible | shadow | hover`.
97-
98-
`disable-font-face` - Disables standard `@font-face` font loading and uses the internal font renderer instead, `true` to enable.
99-
100-
`disable-range` - Disables HTTP range requests when fetching the document, `true` to enable.
101-
102-
`disable-stream` - Disables streaming when fetching the document, `true` to enable.
103-
104-
`disable-auto-fetch`- Disables auto fetching of the document; only gets necessary data to display the current view. Note: streaming also needs to be disabled for this to have any effect, `true` to enable.
105-
106-
`verbosity`- Specifies the verbosity level of console messages. `0` - only errors, `1` - warnings and errors, `5` - warnings, errors and information messages.
107-
10876
`locale` - Specifies which language to use in the viewer UI, `en-US | ...`. [Available locales](https://github.com/mozilla/pdf.js/tree/master/l10n)
10977

11078
`viewer-css-theme` - Apply automatic, light, or dark theme, `AUTOMATIC | LIGHT | DARK`
@@ -113,7 +81,7 @@ import 'pdfjs-viewer-element'
11381

11482
`viewer-extra-styles-urls` - Add external CSS files to the viewer application, pass an array with URLs.
11583

116-
Play with attributes on [Api docs page](https://alekswebnet.github.io/pdfjs-viewer-element/#api).
84+
Play with attributes on [API docs page](https://alekswebnet.github.io/pdfjs-viewer-element/#api).
11785

11886
## Viewer CSS theme
11987

@@ -122,7 +90,6 @@ Use `viewer-css-theme` attribute to set light or dark theme manually:
12290
```html
12391
<pdfjs-viewer-element
12492
src="/file.pdf"
125-
viewer-path="/pdfjs-5.3.93-dist"
12693
viewer-css-theme="DARK">
12794
</pdfjs-viewer-element>
12895
```
@@ -134,7 +101,6 @@ You can add your own CSS rules to the viewer application using `viewer-extra-sty
134101
```html
135102
<pdfjs-viewer-element
136103
src="/file.pdf"
137-
viewer-path="/pdfjs-5.3.93-dist"
138104
viewer-extra-styles="#toolbarViewerMiddle { display: none; }"
139105
viewer-extra-styles-urls="['/demo/viewer-custom-theme.css']">
140106
</pdfjs-viewer-element>
@@ -162,23 +128,30 @@ Build your own theme with viewer's custom variables and `viewer-extra-styles-url
162128
}
163129
```
164130

165-
## PDF.js Viewer Application
166-
167-
`initialize` - using this method you can access PDFViewerApplication and use methods and events of PDF.js default viewer
131+
## PDF.js Viewer Application and Options
168132

169133
```html
170-
<pdfjs-viewer-element viewer-path="/pdfjs-5.3.93-dist"></pdfjs-viewer-element>
134+
<pdfjs-viewer-element></pdfjs-viewer-element>
171135
```
172136

173137
```javascript
174-
const viewer = document.querySelector('pdfjs-viewer-element')
175-
// Wait for the viewer initialization, receive PDFViewerApplication
176-
const viewerApp = await viewer.initialize()
177-
// Open PDF file data using Uint8Array instead of URL
178-
viewerApp.open({ data: pdfData })
138+
// Open PDF file programmatically accessing the viewer application
139+
document.addEventListener('DOMContentLoaded', async () => {
140+
document.querySelector('pdfjs-viewer-element').addEventListener('initialized', (event) => {
141+
const { viewerApp, viewerOptions } = event.detail
142+
viewerApp.open({ data: pdfData })
143+
})
144+
})
179145
```
180146

181-
## Accessiblity
147+
## Events
148+
149+
`initialized` - Fired after the PDF.js viewer is ready (after `PDFViewerApplication.initializedPromise` resolves). The event `detail` contains:
150+
151+
- `viewerApp` (`PDFViewerApplication`)
152+
- `viewerOptions` (`PDFViewerApplicationOptions`)
153+
154+
## Accessibility
182155

183156
Use `iframe-title` to add a title to the `iframe` element and improve accessibility.
184157

@@ -188,7 +161,7 @@ Use `iframe-title` to add a title to the `iframe` element and improve accessibil
188161

189162
Since v4 PDF.js requires `.mjs` files support, make sure your server has it.
190163

191-
In case of `nginx` this may causes to errors, see https://github.com/mozilla/pdf.js/issues/17296
164+
In case of `nginx` this may cause errors, see https://github.com/mozilla/pdf.js/issues/17296
192165

193166
Add `.mjs` files support for `nginx` example:
194167

@@ -209,13 +182,6 @@ server {
209182
}
210183
```
211184

212-
### Problem with range requests / streaming
213-
214-
Sometimes a PDF file fails to load when working with range requests / streaming.
215-
If you encounter this issue, you can try disabling the broken functionality of PDF.js:
216-
217-
`disable-range="true"`
218-
219185
## Support via Ko-fi
220186

221187
If you find `pdfjs-viewer-element` useful and want to support its development, consider making a donation via Ko-fi:

0 commit comments

Comments
 (0)