vue.js pdf viewer
vue.js pdf viewer is a package for Vue that enables you to display and view PDF's easily via vue components.
npm install vue-pdf
yarn add vue-pdf
<template>
<pdf src="./path/to/static/relativity.pdf"></pdf>
</template>
<script>
import pdf from 'vue-pdf'
export default {
components: {
pdf
}
}
TBD: fix the demo
Same browser support as Vue.js 2
since v2.x, the script is exported as esm.
The url of the given pdf. src may also be a string|TypedArray|DocumentInitParameters|PDFDataRangeTransport for more details, see PDFJS.getDocument().
The page number to display.
The page rotation in degrees, only multiple of 90 are valid. EG: 90, 180, 270, 360, ...
updatePassword: The function to call with the pdf password.reason: the reason why this function is called 'NEED_PASSWORD' or 'INCORRECT_PASSWORD'Document loading progress. Range [0, 1].
Triggers when the document is loaded.
Triggers when a page is loaded.
The sum of all pages from the given pdf.
Triggers when an error occurs.
Triggers when an internal link is clicked
dpi: the print resolution of the document (try 100).pageList: the list (array) of pages to print.src: see :src prop options: an object of options.
This function creates a PDFJS loading task that can be used and reused as :src property.numPages property (see example below). beware: when the component is destroyed, the object returned by createLoadingTask() become invalid.
Supported options:
<template>
</template>
<script>
import pdf from 'vue-pdf'
export default {
components: {
pdf
},
data() {
return {
currentPage: 0,
pageCount: 0,
}
}
}
</script>
Example - display multiple pages of the same pdf document
<template>
</template>
<script>
import pdf from 'vue-pdf'
var loadingTask = pdf.createLoadingTask('https://cdn.mozilla.net/pdfjs/tracemonkey.pdf');
export default {
components: {
pdf
},
data() {
return {
src: loadingTask,
numPages: undefined,
}
},
mounted() {
this.src.promise.then(pdf => {
this.numPages = pdf.numPages;
});
}
}
</script>
Example - print all pages
<template>
<button @click="$refs.myPdfComponent.print()">print</button>
<pdf ref="myPdfComponent" src="https://cdn.mozilla.net/pdfjs/tracemonkey.pdf"></pdf>
</template>
Example - print multiple pages
<template>
<button @click="$refs.myPdfComponent.print(100, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])">print</button>
<pdf ref="myPdfComponent" src="https://cdn.mozilla.net/pdfjs/tracemonkey.pdf"></pdf>
</template>
Example - get text content
<template>
</template>
<script>
import pdf from 'vue-pdf'
export default {
components: {
pdf
},
methods: {
logContent() {
this.$refs.myPdfComponent.pdf.forEachPage(function(page) {
return page.getTextContent()
.then(function(content) {
var text = content.items.map(item => item.str);
console.log(text);
})
});
}
}
}
</script>
Example - complete
…
No open issues yet, or sync has not completed.