kempsteven / vue-html2pdf

vue-html2pdf converts any vue component or element into PDF, vue-html2pdf is basically a vue wrapper only and uses html2pdf.js behind the scenes.
https://www.npmjs.com/package/vue-html2pdf
MIT License
439 stars 75 forks source link

How to open the pdf blob in the same window #82

Closed vanjoechua closed 3 years ago

vanjoechua commented 3 years ago

My app implements a PDF view by clicking on a print button on a form page. When the button is clicked a new tab is opened a the component where the PDF content resides is loaded. I purposely do not load/import the component which has the PDF component inside the same form due to complexity of the overall form component. So the page to print is actually another page. If i set download and preview to false to get the blob how can i open the blob within the same window? What is currently happening is that another page opens to show the PDF even though I have this code in the beforeDownload method:

async beforeDownload({ html2pdf, options, pdfContent }){ await html2pdf().set(options).from(pdfContent).toPdf().get('pdf').then((pdf) => { window.open(pdf.output('bloburl')); }) },

kempsteven commented 3 years ago

how can i open the blob within the same window

hmm one solution is just create an <iframe> that covers the whole page, and insert the blob file in the <iframe>, let me know if that works

vanjoechua commented 3 years ago

Thanks for this idea. It does work.