Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 80 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


# vue-pdf
vue.js pdf viewer

Expand Down Expand Up @@ -219,8 +221,6 @@ export default {

</script>
```


##### Example - complete
```
<template>
Expand Down Expand Up @@ -279,5 +279,83 @@ export default {
</script>
```

##### Example - consume pdf from secured REST endpoint with next, previous, print and current page of total pages navigations
```
<template>
<div>
<div>
<button @click="previousPage">Prev</button>
<p style="font-weight:bold;font-size:14px;display:inline;">{{page}} of {{numPages}} </p>
<button @click="nextPage">Next</button>
<button @click="$refs.pdf.print()">Print</button>
</div>
<div>
<div style="width: 100%;">
<pdf :src="pdfContent"
:page="page"
@page-loaded="currentPage = $event"
@error="error"
@num-pages="numPages = $event"
ref="pdf">
</pdf>
</div>
</div>
</div>
</template>

<script>
import pdf from 'vue-pdf'
import axios from 'axios' //library to make ajax request below

export default {
data() {
return {
pdfContent: null,
numPages: 0,
page:1,
loadedRatio: 1
}
},
components: {
pdf: pdf
},
mounted() {
var self = this;

//Use axios library to make ajax call to REST endpoint that returns pdf as octet stream
const authHeader = "Bearer yourAccessTokenGoesHere";

axios({
url: 'http://localhost:8080/sample/pdf',
method: 'GET',
responseType: 'blob',
headers: {
'Authorization': authHeader,
},
}).then((response) => {
var blob = new Blob([response.data], {type: 'application/pdf'});
var blobURL = window.URL.createObjectURL(blob);
self.pdfContent = blobURL;
});
},
methods: {
nextPage: function() {
//Go to next page if any
if(this.page < this.numPages)
this.page++;
},
previousPage: function() {
//Go to previous page if not already at page 1
if(this.page > 1)
this.page--;
},
error: function(err) {
console.log(err);
}
}
}
</script>
```

## Credits
[<img src="https://www.franck-freiburger.com/FF.png" width="16"> Franck Freiburger](https://www.franck-freiburger.com)