VUEjs v2 PDF viewer based on Mozilla's PDFJS.
100% PDFJS functionality:
:pdf
```
ID config specification
```
```
```
- zoom
- open
- download
- rotate
- text selection
- search panel
- pdf document password
- thumbnail, outline, attachments, annotation layers
Example
```vue
```
Live demo
Live demo 2
Examples source code
FAQ
API
- Type:
string | null | ArrayBuffer | TypedArray
- Required:
false
- Usage:
:title
- Description:
true
renames document title to pdf file name.
- Type:
boolean
- Required:
false
- Default:
false
- Usage:
:theme.sync
- Type:
"dark" | "light"
- Required:
false
- Usage:
new :fileName
- Description: when pdf is passed like an array buffer default download file name is
document.pdf
. Set this prop to override it.
- Type:
string
- Required:
false
- Usage:
new :pageScale
- Description: default page scale.
- Type:
number | "page-actual"| "page-width"| "page-height"| "page-fit"| "auto"
- Required:
false
- Usage:
new :pageNumber
- Description: pdfjs stores last viewed page of a file in
window.localStorage.getItem("pdfjs.history")
. Specify the prop to override it.
- Type:
number
- Required:
false
- Usage:
:config
- Description: toolbar configuration. Toolbar is available by default. Specify
false
for buttons or whole group of buttons to disable them.
- Type:
toolbar config (see below)
- Required:
false
- Default:
toolbar config
- Usage:
{
sidebar: {
viewThumbnail: true,
viewOutline: true,
viewAttachments: true,
},
secondaryToolbar: {
secondaryPresentationMode: true,
secondaryOpenFile: true,
secondaryPrint: true,
secondaryDownload: true,
secondaryViewBookmark: true,
firstPage: true,
lastPage: true,
pageRotateCw: true,
pageRotateCcw: true,
cursorSelectTool: true,
cursorHandTool: true,
scrollVertical: true,
scrollHorizontal: true,
scrollWrapped: true,
spreadNone: true,
spreadOdd: true,
spreadEven: true,
documentProperties: true,
},
toolbar: {
toolbarViewerLeft: {
findbar: true,
previous: true,
next: true,
pageNumber: true,
},
toolbarViewerRight: {
presentationMode: true,
openFile: true,
print: true,
download: true,
viewBookmark: true,
},
toolbarViewerMiddle: {
zoomOut: true,
zoomIn: true,
scaleSelectContainer: true,
},
},
errorWrapper: true,
};
new :id-config
- Description: If default toolbar UI doesn't suite you it is possible to build custom toolbar. The prop contains elements ID to which to bind functionality. If element ID is specified in this prop appropriate button will be hidden in a default toolbar. May not work with UI framework components. That is because pdfjs internally manages attributes specific to a certain HTML element (for instance pdfjs toggles
disabled
attribute of a button but it won't if a div is used instead of a button). So it is better to use native HTML element specified as recommended in ID config specification below. Four slots are specially designed to build custom toolbar (are situated near a pdf page):viewer-header, viewer-prepend, viewer-append, viewer-footer
(refer slots API). It is also possible to use other slots or elements outside vue-pdf-app.
- Type:
ID config (see below)
- Required:
false
- Usage:
<button :id="idConfig.zoomOut" type="button">Zoom out</button>
<vue-pdf-app :id-config="idConfig">
<template #viewer-prepend>
<div class="viewer-prepend">
<button :id="idConfig.zoomIn" type="button">Zoom in</button>
</div>
</template>
</vue-pdf-app>
{
cursorHandTool?: string; // <button> is recommended
cursorSelectTool?: string; // <button> is recommended
documentProperties?: string; // <button> is recommended
download?: string; // <button> is recommended
findbar?: string; // <div> is recommended
findEntireWord?: string; // <input type="checkbox"> is recommended
findHighlightAll?: string; // <input type="checkbox"> is recommended
findMessage?: string; // <span> is recommended
findInput?: string; // <input type="text"> is recommended
findMatchCase?: string; // <input type="checkbox"> is recommended
findNext?: string; // <button> is recommended
findPrevious?: string; // <button> is recommended
findResultsCount?: string; // <span> is recommended
firstPage?: string; // <button> is recommended
lastPage?: string; // <button> is recommended
nextPage?: string; // <button> is recommended
numPages?: string; // total pages qty. <span> is recommended
openFile?: string; // <button> is recommended
pageNumber?: string; // input for page number. <input type="number"> is recommended
pageRotateCcw?: string; // <button> is recommended
pageRotateCw?: string; // <button> is recommended
presentationMode?: string; // <button> is recommended
previousPage?: string; // <button> is recommended
print?: string; // <button> is recommended
scrollHorizontal?: string; // <button> is recommended
scrollVertical?: string; // <button> is recommended
scrollWrapped?: string; // <button> is recommended
sidebarToggle?: string; // <button> is recommended
spreadEven?: string; // <button> is recommended
spreadNone?: string; // <button> is recommended
spreadOdd?: string; // <button> is recommended
toggleFindbar?: string; // <button> is recommended
viewAttachments?: string; // <button> is recommended
viewBookmark?: string; // <a> tag is recommended
viewOutline?: string; // <button> tag is recommended
viewThumbnail?: string; // <button> tag is recommended
zoomIn?: string; // <button> tag is recommended
zoomOut?: string; // <button> tag is recommended
}
ℹ️ Note that elements must be in HTML document by the time vue-pdf-app is mounting (usev-show
instead ofv-if
directive if necessary). Otherwise an error occurs.
@after-created(PDFViewerApplication)
- Description: emitted only once when Pdfjs library is binded to vue component. Can be used to set Pdfjs config before pdf document opening.
- Arguments:
- Usage:
@open(PDFViewerApplication)
- Description: emitted when pdf is opened but pages are not rendered.
- Arguments:
- Usage:
@pages-rendered(PDFViewerApplication)
- Description: emitted when pdf document pages are rendered. Can be used to set default pages scale, for instance.
- Arguments:
- Usage:
ℹ️ Events are triggered in the following order after-created (once) => open => pages-rendered
Slots
Slot names
- toolbar-left-prepend
- toolbar-left-append
- toolbar-middle-prepend
- toolbar-middle-append
- toolbar-right-prepend
- toolbar-right-append
- toolbar-sidebar-prepend
- toolbar-sidebar-append
- secondary-toolbar-prepend
- secondary-toolbar-append
- footer
- NEW viewer-header: slot before
viewer-prepend
slot. Can be used to build custom toolbar.
- NEW viewer-prepend: slot before
viewerContainer
div. Can be used to build custom toolbar.
- NEW viewer-append: slot after
viewerContainer
div. Can be used to build custom toolbar.
- NEW viewer-footer: slot after
viewer-append
slot. Can be used to build custom toolbar.
Slot props
Each slot has props:- toggleTheme
Type: (): void.
Description: toggle theme handler
- NEW isSidebarHidden
Type: boolean
Description: state of a sidebar (visible or hidden). Can be used to manage visibility of custom Attachments, Outline and Thumbnail buttons
- NEW isFindbarHidden
Type: boolean
Description: state of a findbar (visible or hidden). Can be used to manage visibility of custom findbar
```vue
<button @click="toggleTheme" type="button">Toggle theme</button>
```
Color customization (IE11 not supported)
Colors of the pdf viewer are customized via custom css properties:
```html
```
Custom css properties specification
Icons customization
To use default icons import "vue-pdf-app/dist/icons/main.css";
.
To use custom icons you have to implement icons.css:
```css
.vue-pdf-app-icon::before,
.vue-pdf-app-icon::after {
font-family: "your font family";
}
.vue-pdf-app-icon.zoom-out::before {
content: "icon code";
}
```
Light/dark themes
Algorithm of theme apply
Toggle theme button is not implemented by default.
It's up to you to decide where to place it.
The button can be implemented with slots:
```vue
<button @click="toggleTheme" type="button">Toggle theme</button>
```
Localized panel
English is the default language for panel.
Use <link rel="resource" type="application/l10n" href="path-to-localization-file">
in your html for localization.
See localization file examples.
Examples
Script tag (unpkg)
```html<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta charset="utf-8" />
<title>Vue-pdf-app demo</title>
<link
rel="stylesheet"
href="https://unpkg.com/vue-pdf-app@2.0.0/dist/icons/main.css"
/>
<script src="https://unpkg.com/vue"></script>
<script src="https://unpkg.com/vue-pdf-app@2.0.0"></script>
<style>
body,
html {
padding: 0;
margin: 0;
}
</style>
<div id="app" style="height: 100vh;">
<vue-pdf-app pdf="/sample.pdf"></vue-pdf-app>
</div>
<script>
new Vue({
components: {
VuePdfApp: window["vue-pdf-app"]
}
}).$mount("#app");
</script>
```
Typescript
```vue<vue-pdf-app pdf="/sample.pdf"></vue-pdf-app>
Lazy loading
PDFJS is a huge package (see the library size table above). So use lazy loading to split your bundle into small pieces. ```vue<vue-pdf-app></vue-pdf-app>
PDFJS interaction
You can interact with pdfjs library when pdf is opened viaopen
event.
```vue
<div id="pdf-wrapper">
<vue-pdf-app pdf="/sample.pdf" @open="openHandler"></vue-pdf-app>
</div>
<div id="info">
<h1>PDF info:</h1>
<div v-for="item in info" :key="item.name">
<span>{{ item.name }}: {{ item.value }}</span>
<br />
</div>
</div>