forked from FranckFreiburger/vue-pdf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- remove server-side PDFJS support by default (import vue-pdf/src/vue…
…PdfSss.vue otherwise) - move babel-plugin-syntax-dynamic-import to devDependencies
- Loading branch information
1 parent
33bfa3a
commit 21fa08e
Showing
7 changed files
with
521 additions
and
477 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import resizeSensor from 'vue-resize-sensor' | ||
import './annotationLayer.css' | ||
|
||
export default function(pdfjsWrapper) { | ||
|
||
var createLoadingTask = pdfjsWrapper.createLoadingTask; | ||
var PDFJSWrapper = pdfjsWrapper.PDFJSWrapper; | ||
|
||
return { | ||
createLoadingTask: createLoadingTask, | ||
render: function(h) { | ||
return h('div', { | ||
attrs: { | ||
style: 'position: relative' | ||
} | ||
}, [ | ||
h('canvas', { | ||
style: { | ||
display: 'block', | ||
width: '100%', | ||
}, | ||
ref:'canvas' | ||
}), | ||
h('div', { | ||
class: 'annotationLayer', | ||
ref:'annotationLayer' | ||
}), | ||
h(resizeSensor, { | ||
props: { | ||
initial: true | ||
}, | ||
on: { | ||
resize: this.resize | ||
}, | ||
}) | ||
]) | ||
}, | ||
props: { | ||
src: { | ||
type: [String, Object], | ||
default: '', | ||
}, | ||
page: { | ||
type: Number, | ||
default: 1, | ||
}, | ||
rotate: { | ||
type: Number, | ||
default: 0, | ||
}, | ||
}, | ||
watch: { | ||
src: function() { | ||
|
||
this.pdf.loadDocument(this.src); | ||
}, | ||
page: function() { | ||
|
||
this.pdf.loadPage(this.page, this.rotate); | ||
}, | ||
rotate: function() { | ||
|
||
this.pdf.renderPage(this.rotate); | ||
}, | ||
}, | ||
methods: { | ||
resize: function(size) { | ||
|
||
// check if the element is attached to the dom tree | ||
if ( this.$el.parentNode === null ) | ||
return; | ||
|
||
// on IE10- canvas height must be set | ||
this.$refs.canvas.style.height = this.$refs.canvas.offsetWidth * (this.$refs.canvas.height / this.$refs.canvas.width) + 'px'; | ||
|
||
// update the page when the resolution is too poor | ||
var resolutionScale = this.pdf.getResolutionScale(); | ||
|
||
if ( resolutionScale < 0.85 || resolutionScale > 1.15 ) | ||
this.pdf.renderPage(this.rotate); | ||
|
||
this.$refs.annotationLayer.style.transform = 'scale('+resolutionScale+')'; | ||
}, | ||
print: function(dpi, pageList) { | ||
|
||
this.pdf.printPage(dpi, pageList); | ||
} | ||
}, | ||
|
||
// doc: mounted hook is not called during server-side rendering. | ||
mounted: function() { | ||
|
||
this.pdf = new PDFJSWrapper(this.$refs.canvas, this.$refs.annotationLayer, this.$emit.bind(this)); | ||
|
||
this.$on('loaded', function() { | ||
|
||
this.pdf.loadPage(this.page, this.rotate); | ||
}); | ||
|
||
this.$on('page-size', function(width, height) { | ||
|
||
this.$refs.canvas.style.height = this.$refs.canvas.offsetWidth * (height / width) + 'px'; | ||
}); | ||
|
||
this.pdf.loadDocument(this.src); | ||
}, | ||
|
||
// doc: destroyed hook is not called during server-side rendering. | ||
destroyed: function() { | ||
|
||
this.pdf.destroy(); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.