Are you using the latest version of jsPDF?
I can demo the effect on http://rawgit.com/MrRio/jsPDF/master/ so I guess it is the latest version.
Have you tried using jspdf.debug.js?
no
Steps to reproduce
var doc = new jsPDF();
doc.setFontSize(40);
doc.text(35, 25, "onesingle line");
doc.output('dataurlnewwindow');
and wait for another tab to open showing the resulting pdf.
What I saw
with Chrome Windows 10 Version 60.0.3112.90 (Offizieller Build) (64-Bit)
it opens a new tab but the pdf is not shown in the tab.
Chrome console says "Not allowed to navigate top frame to data URL: "
I googled around and found:
https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/GbVcuwg_QjM
Intent to Deprecate and Remove: Top-frame navigations to data URLs
It does work Chrome MacOs Version 59.0.3071.115 and firefox windows 54.0.1 (32-Bit)
I tried to wrap the pdf in an iframe as proposed here : https://bugs.chromium.org/p/chromium/issues/detail?id=594215#c64
It works on chrome but not in firefox.
// You'll need to make your image into a Data URL
// Use http://dataurl.net/#dataurlmaker
var doc = new jsPDF();
function open_data_uri_window(url) {
var html = '<html>' +
'<style>html, body { padding: 0; margin: 0; } iframe { width: 100%; height: 100%; border: 0;} </style>' +
'<body>' +
'<iframe src="' + url + '"></iframe>' +
'</body></html>';
a = window.open()
a.document.write(html)
}
doc.setFontSize(40);
doc.text(35, 25, "onesingle line");
a = doc.output('datauri');
open_data_uri_window(a);
it works in chrome but not in firefox which hangs.
What I expected
I expected another tab to open and to show the pdf.
Need more documentation
I would appreciate if documentation also would show examples, how to display the generated PDF,
In particular how it is done in http://rawgit.com/MrRio/jsPDF/master/ where the embedded pdf browser works on any platform I mentioned above.
I found a solution which also works in Firefox. See https://stackoverflow.com/questions/45585921/firefox-hangs-when-displaying-a-pdf-via-data-url/45585922#45585922
maybe jspdf could add a suggested filename to output('datauri')
for example:
data:application/pdf;name=document.pdf;base64,BASE64_DATA_ENCODED
I am experiencing the same/similar problem in the latest update of Chrome (60.0.3112.90) on OSX. I just see a blank screen. Firefox is ok. It was working without a problem before.
If you follow the code in my ticket, it works fine in chrome on osx.
Thanks. @bwl21
Nice @bwl21 thank you!
I have used your code, with the only variation in
a = doc.output('datauri');
replaced with
a = doc.output('datauristring');
this to avoid the error in console.
@Estrusco indeed, my code now also uses datauristring.
As a pity, the stuff does not work on Microsoft Edge. I could not yet find out why.
Even the jspdf demo page (http://rawgit.com/MrRio/jsPDF/master/) does not show the resulting pdf.
@bwl21 The scope of this issue is not limited to Chrome on Windows. Chrome on other platforms is affected. Perhaps the issue name can be updated to:
Cannot open PDF in new window on Chrome
Implemented
Most helpful comment
If you follow the code in my ticket, it works fine in chrome on osx.