Skip to content

Commit 1257e18

Browse files
committed
Update docs and readme
1 parent a3ba18c commit 1257e18

File tree

2 files changed

+84
-36
lines changed

2 files changed

+84
-36
lines changed

README.md

+62-32
Original file line numberDiff line numberDiff line change
@@ -19,50 +19,38 @@
1919
<h2><a href="https://tato30.github.io/vue-pdf/">📖Documentation</a></h2>
2020
</div>
2121

22-
## Introduction
22+
# Introduction
2323

24-
VuePDF is a **Vue 3** component for pdf.js that allows you to flexibly display PDF pages within your project.
24+
VuePDF is a **client-side** component for **Vue 3** that allows you to flexibly render PDF pages within your project. This library wraps `pdf.js` library so all main features of `pdf.js` are supported by `VuePDF` as well.
2525

2626
## Installation
2727

28-
```console
28+
```sh
2929
npm i @tato30/vue-pdf
30-
```
31-
32-
```console
3330
yarn add @tato30/vue-pdf
3431
```
3532

3633
## Basic Usage
3734

35+
The most basic usage is as simple as import the `VuePDF` and `usePDF` and use them on your project :)
36+
3837
```vue
3938
<script setup>
4039
import { VuePDF, usePDF } from '@tato30/vue-pdf'
4140
42-
const { pdf, pages, info } = usePDF('document.pdf')
43-
44-
console.log(`Document has ${pages} pages`)
45-
console.log(`Document info: ${info}`)
41+
const { pdf } = usePDF('sample.pdf')
4642
</script>
4743
4844
<template>
4945
<VuePDF :pdf="pdf" />
5046
</template>
5147
```
5248

53-
## Reference
54-
55-
* [Props](./docs/guide/props.md)
56-
* [Events](./docs/guide/events.md)
57-
* [Methods](./docs/guide/methods.md)
58-
* [Slots](./docs/guide/slots.md)
59-
60-
6149
## Working With Layers
6250

6351
### Text and Annotations
6452

65-
This component supports text-selection and annotation-interaction by enabling them with `text-layer` and `annotation-layer` props respectively, but for this layers renders correctly is necessary setting `css` styles, it can be done by importing default styles from `@tato30/vue-pdf/style.css`.
53+
This component supports text selection and annotation interaction by enabling them with `text-layer` and `annotation-layer` props respectively, but for this layers renders correctly is necessary set some `css` styles, it can be done by importing default styles from `@tato30/vue-pdf/style.css`.
6654

6755
```vue
6856
<script setup>
@@ -77,13 +65,7 @@ const { pdf } = usePDF('sample.pdf')
7765
</template>
7866
```
7967

80-
You can also create your own custom styles and set them in your project, use this examples as guide:
81-
82-
- [text-layer styles](https://github.com/mozilla/pdf.js/blob/master/web/text_layer_builder.css)
83-
- [annotation-layer styles](https://github.com/mozilla/pdf.js/blob/master/web/annotation_layer_builder.css)
84-
85-
### XFA Forms <badge type="tip" text="v1.7" vertical="middle" />
86-
68+
### XFA Forms
8769
XFA forms also can be supported by enabling them from `usePDF`.
8870

8971
```vue
@@ -104,24 +86,72 @@ const { pdf } = usePDF({
10486

10587
## Server-Side Rendering
10688

107-
`VuePDF` is a client-side library, so if you are working with SSR frameworks like `nuxt`, surely will throw error during building stage, if that the case, you could wrap library in some "client only" directive or component, also `usePDF` should be wrapped.
89+
`VuePDF` is a client-side library, so if you are working with a SSR framework like `nuxt`, surely it will throw an error during the building stage, if that is the case, you could wrap `VuePDF` in some sort of "client only" directive or component, also `usePDF` should be wrapped.
90+
91+
## Supporting Non-Latin characters
92+
93+
If you are looking for display non-latin text or you are getting a warning like:
94+
> Warning: Error during font loading: CMapReaderFactory not initialized, see the useWorkerFetch parameter
95+
96+
you will probably need to copy the `cmaps` directory from `node_modules/pdfjs-dist` to your project's `public` directory, don't worry about no having `pdfjs-dist` it's installed alongside `vue-pdf` package.
97+
98+
99+
```
100+
.
101+
├─ node_modules
102+
│ ├─ pdfjs-dist
103+
│ │ └─ cmaps <--- Copy this directory
104+
├─ src
105+
├─ public
106+
| ├─ *cmaps* <--- Paste it here!
107+
├─ package.json
108+
| ...
109+
```
110+
111+
With that made the `cmaps` will be available on relative path `/cmaps/`, now you need the tell `usePDF` uses that `cmaps` url:
112+
113+
```js
114+
const { pdf } = usePDF({
115+
url: pdfsource,
116+
cMapUrl: '/cmaps/',
117+
})
118+
```
119+
120+
## Supporting legacy browsers
121+
122+
If you need to support legacy browsers you could use any polyfill to patch modern functions, but this workaround only works on the **main** thread, the *worker* that runs in other thread will not get reached by any polyfills you apply.
123+
124+
This package embed and configure the `pdf.js` *worker* for you but in case you need to support legacy environments you will need to configure the `legacy` *worker* by adding this code:
125+
126+
```vue
127+
<script setup lang="ts">
128+
+ import * as PDFJS from 'pdfjs-dist';
129+
+ import LegacyWorker from 'pdfjs-dist/legacy/build/pdf.worker.min?url';
130+
import { VuePDF, usePDF } from '@tato30/vue-pdf';
131+
132+
+ PDFJS.GlobalWorkerOptions.workerSrc = LegacyWorker
133+
134+
const { pdf } = usePDF(/** */)
135+
</script>
136+
```
137+
138+
Just be aware to set the `legacy` worker before use `usePDF`.
108139

109140
## Contributing
110141

111142
Any idea, suggestion or contribution to the code or documentation are very welcome.
112143

113144
```sh
114145
# Clone the repository
115-
git clone https://github.com/TaTo30/VuePDF.git
116-
146+
git clone https://github.com/TaTo30/vue-pdf.git
117147
# Change to code folder
118-
cd VuePDF
119-
148+
cd vue-pdf
120149
# Install node_modules
121150
npm install
122-
123151
# Run code with hot reload
124152
npm run dev
153+
# Run docs
154+
npm run dev:docs
125155
```
126156

127157
## Looking for maintainers and current status

docs/guide/introduction.md

+22-4
Original file line numberDiff line numberDiff line change
@@ -119,21 +119,39 @@ const { pdf } = usePDF({
119119
})
120120
```
121121

122+
## Supporting legacy browsers
123+
124+
If you need to support legacy browsers you could use any polyfill to patch modern functions, but this workaround only works on the **main** thread, the *worker* that runs in other thread will not get reached by any polyfills you apply.
125+
126+
This package embed and configure the `pdf.js` *worker* for you but in case you need to support legacy environments you will need to configure the `legacy` *worker* by adding this code:
127+
128+
```vue
129+
<script setup lang="ts">
130+
import * as PDFJS from 'pdfjs-dist'; // [!code ++]
131+
import LegacyWorker from 'pdfjs-dist/legacy/build/pdf.worker.min?url'; // [!code ++]
132+
import { VuePDF, usePDF } from '@tato30/vue-pdf';
133+
134+
PDFJS.GlobalWorkerOptions.workerSrc = LegacyWorker // [!code ++]
135+
136+
const { pdf } = usePDF(/** */)
137+
</script>
138+
```
139+
140+
Just be aware to set the `legacy` worker before use `usePDF`.
141+
122142
## Contributing
123143

124144
Any idea, suggestion or contribution to the code or documentation are very welcome.
125145

126146
```sh
127147
# Clone the repository
128148
git clone https://github.com/TaTo30/vue-pdf.git
129-
130149
# Change to code folder
131150
cd vue-pdf
132-
cd vue-pdf/docs # In case you want to update docs
133-
134151
# Install node_modules
135152
npm install
136-
137153
# Run code with hot reload
138154
npm run dev
155+
# Run docs
156+
npm run dev:docs
139157
```

0 commit comments

Comments
 (0)