vue-pdf-search-viewer
Version:
Pdf viewer base on Vue.js and Pdf.js, support pdf view, search by keyword and change page
84 lines (62 loc) • 2.08 kB
Markdown
Pdf viewer base on Vue.js and Pdf.js, support pdf view, search by keyword and change page.
```
npm install --save vue-pdf-search-viewer
```
```
//vue.config.js
module.exports = {
chainWebpack: config => {
//...your configs
config
.plugin('copy')
.tap(args => {
args[0].push(
{
context: 'node_modules/vue-pdf-search-viewer/lib/',
from: '*.umd.min.*.js',
to: 'js/',
toType: 'dir'
},
{
from: 'node_modules/vue-pdf-search-viewer/lib/pdf.worker.js',
to: 'pdf.worker.js',
toType: 'file'
},
)
return args
})
}
}
```
```
//main.js
import PdfViewer from 'vue-pdf-search-viewer'
Vue.use(PdfViewer)
```
```
<template>
<pdf-viewer src="./compressed.tracemonkey-pldi-09.pdf"></<pdf-viewer>
</template>
```
| Props | Type | Description |
|-------------|-------------|-------------|
| **src** | string or other(detail to see pdf.js getDocument()) | Pdf url |
| **autoWidth** | boolean, default `false` | Whether to zoom pdf to container width when initial |
| Events | Parameters | Description |
|-------------|-------------|-------------|
| **on-loaded** | number | Pdf total page number |
| **on-search** | object: { current, total } | Search keyword matched current number and total count |
| **on-page-change** | number | Current page number |
| Methods | Parameters | Description |
|-------------|-------------|-------------|
| **search** | string | Search keyword in pdf |
| **searchAgain** | param1:string, param2: boolean | Param1 is search keyword, param2 is dicided to find pre(true) or find next(false)|
| **cancelSearch** | none | Cancel search |
| **zoom** | number/ string('auto') | Number: The ratio of pdf zoom, 'auto': zoom to container width |
| **jumpToPage** | number | The page number of pdf jumped to |