Skip to content
Advertisement

Open jsPDF created pdf in Chrome’s new tab/window

How can I open with javascript link data:application/pdf;filename=generated.pdf;base64;DATA in Chrome 71?
Link from console opened successfully, but not from code – unfortunately.
The snippet does not work for security reason. Only for code demonstration.
I read some similar questions, but did not find an answer.

enter image description here

JavaScript
JavaScript

Advertisement

Answer

Try window.open() instead. The following code worked for me. You will need to modify the window/page size.

JavaScript

Update:

Didn’t realize that jsPDF comes with a built-in method pdf.output('dataurlnewwindow');, which uses iframe,

The downside of pdf.output('dataurlnewwindow') is that it opens a new tab/window with datauristring as the pdf file name and the download button doesn’t work, while window.open(pdf.output('bloburl')) seems fine with the download button.

Okay, pdf file can be renamed like this:

JavaScript

Update 2:

To avoid the page being cut off when a page is zoomed, you can set the html2canvas scale accordingly.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement