Comments (9)
Changes from @mweimerskirch have been included in 1.1.2
In this release, a getDocument
function was also attached to the exported module. So that you can load the PDF document outside the component as follows:
<template>
<div>
<div v-if="pdfSource">
<vue-pdf-embed :source="pdfSource" :page="1" />
<vue-pdf-embed :source="pdfSource" :page="3" />
</div>
</div>
</template>
<script>
import VuePdfEmbed from 'vue-pdf-embed'
export default {
components: {
VuePdfEmbed,
},
data() {
return {
pdfSource: null,
}
},
async mounted() {
this.pdfSource = await VuePdfEmbed.getDocument('<PDF_SOURCE>').promise
},
}
</script>
Hope this helps
from vue-pdf-embed.
Hi @EHadoux,
Thanks for your feedback.
Unfortunately, I cannot check right now if it actually shares the loaded document, but I doubt it yet. Although I'm pretty sure that if you're rendering all pages with a single component, there's definitely only one source used.
If the reason it's unacceptable for you to render all pages with a single component is due to styling, you can reuse the .vue-pdf-embed
class or assign any other one.
I'm still not sure if this is the solution for you, so please share your thoughts if this can be solved in any other way.
from vue-pdf-embed.
Hey, thanks for you response.
Here is what I mean:
As you can see, each page is decorated with checkboxes and a button. It's not just styling but actual elements.
In order to do that, I iterate across all the pages and display them 1 by 1 with the checkboxes.
<div v-for="i in pages" :key="i">
<q-checkbox label="Cover" />
...
<vue-pdf-embed :source="src" disableAnnotationLayer disableTextLayer :page="i" />
</div>
Problem 1: as you can see, I'm multiplying the instances of the component, one per page.
Problem 2: this pages
variable can contain a number only once the document has been loaded. But it can be loaded only if we execute the v-for
which requires pages
to contain a number (that's a deadlock).
So to solve that, I've put yet another instance at the very top, that loads but is not displayed:
<vue-pdf-embed :source="src" disableAnnotationLayer disableTextLayer @rendered="loaded" v-show="false" />
When that instance emits rendered
, I can populate pages
that in turns triggers the v-for
and displays the individual pages.
So going back to the initial issue and the one in #9.
For problem 1, it's actually not a problem if the underlying resource (the PDF) is loaded only once in memory and shared.
For problem 2, this is due to the fact that the loading of the PDF is done inside the VuePdfEmbed component, and not outside like in, e.g., vue-pdf.
I'm not bothered that much by the workaround, this part is not client-facing, but I was wondering if there is a better way of doing it.
Cheers!
from vue-pdf-embed.
I see the problem, thanks for the details.
Could you address the question about memory usage (if it is loaded once for the same sources) in the PDF.js repo? At first glance it doesn't seem that way, but I can be wrong.
from vue-pdf-embed.
@EHadoux
I prepared a pull request (#32) that could be useful for your use case.
Alternatively, you can render thumbnails and display those in a for-loop instead of using the vue-pdf-embed component. In that case however, you would loose the annotation layer as well as the text layer.
Example code:
<vue-pdf-embed ... @loaded="onLoaded" />
<img
v-for="thumbnail in thumbnails"
:src="thumbnail"
/>
onLoaded (pdf: PDFDocumentProxy) {
for (let pageNumber = 1; pageNumber <= pdf.numPages; pageNumber++) {
pdf.getPage(pageNumber).then((page: PDFPageProxy) => {
const scale = .5;
const viewport = page.getViewport({scale: scale});
const canvas = document.createElement('canvas') as HTMLCanvasElement;
const context = canvas.getContext('2d');
canvas.height = viewport.height;
canvas.width = viewport.width;
const renderContext = {canvasContext: context, viewport: viewport};
const renderTask = page.render(renderContext);
renderTask.promise.then(() => {
this.thumbnails.push(canvas.toDataURL('image/png'))
});
});
}
from vue-pdf-embed.
That's amazing, thanks a lot! I'll check that out soon. Cheers 👍
from vue-pdf-embed.
We've tested on our end, and we're not exactly sure about this bit:
vue-pdf-embed/src/vue-pdf-embed.vue
Line 165 in c1e20be
When packed, all the class names are supposed to be minimised, so I don't think "PDFDocumentProxy"
actually exists. When we run
(await VuePdfEmbed.getDocument('<PDF_SOURCE>').promise).constructor.name
it gives us e
, the minimised name, so it seems we never end up in the true side of the if.
from vue-pdf-embed.
@mweimerskirch could you take a look at that?
from vue-pdf-embed.
Nevermind, a fix for this was included in 1.1.3
@EHadoux thanks for the feedback!
from vue-pdf-embed.
Related Issues (20)
- vue3 中 pdf 内容错乱 HOT 2
- The requested module 'pdfjs-dist' does not provide an export named 'PasswordResponses' HOT 3
- redundant render base64 pdf cause same canvas render multiple time error HOT 2
- Import font package not found
- Vulnerabilities HOT 1
- xiaomi phone in have this a problem t.a is not a function
- [Bug Report] Memory leaks after changing the page width
- PDF.js Critical Vulnerability HOT 5
- InvalidAccessError: Failed to set the 'responseType' property on 'XMLHttpRequest': The response type cannot be changed for synchronous requests made from a document.
- pdf加载失败 HOT 3
- Page canvases in the wrong order HOT 4
- when I use vue-pdf-embed in my Pad by H5 App,I get a error.How can I solve it??
- images/cursor-editorInk.svg Image loading failed HOT 1
- support zooming gestures HOT 2
- SyntaxError: The requested module '/node_modules/.pnpm/@[email protected][email protected]/node_modules/@dcloudio/uni-h5-vue/dist/vue.runtime.esm.js' does not provide an export named 'toValue' (at index.mjs:20:47) HOT 3
- If it support disableAutoFetch and Rendering Piecewise Loaded PDF Files?
- npm packages deprecations HOT 1
- pdf files have xss and cannot be displayed properly
- [Ask Help]How to set cMapUrl correctly for using useVuePdfEmbed HOT 3
- Print pop-up window display slow.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue-pdf-embed.