3

I have a new problem with an old script. The problem is already exist with an old (1.5.3) and the newest (2.5.1) jsPDF version.

Until recently, the Save or View dialog was displayed when creating a PDF in the browser. Now it works only if the browser (Firefox) is disabled to show PDF. In default mode the PDF is displayed as blob and has a URL without the filename specified by the script in jsPDF.

The console displays the message Warning: Invalid absolute docBaseUrl: "blob:https://www.example.com/25dao98-787zhz98-098kiio54". and PDF 7a55842e15bbd5545545114f2211 [1.3 jsPDF 2.5.1 / example.com] (PDF.js: 2.14.13) .

What do I have to do to open the Save or View dialog in the browser again when creating the PDF?

I use the CDN (jspdf.min.js) versions in my website and only uncomplicated draw, text, font and image function.

Here a example from the jsPDF Github page:

<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
</head>
<body>
<script>
function myfunc() {
var { jsPDF } = window.jspdf;
var doc = new jsPDF();
    doc.setFont(undefined, 'normal');
    doc.text("Hello world! " + Date.now(), 10, 10);
    doc.setFont(undefined, 'bold');
    doc.text("Hello world! " + Date.now(), 10, 20);
    doc.save("a4.pdf");
}
</script>
<button onclick="myfunc();">Button</button>
</body>

This as jspdf.html on my webspace and in firefox opens a blob. And the same on jsfiddle save the pdf file in the default download directory with the correct filename and opens it in a new tab.

https://jsfiddle.net/awk6hd7t/

I don't need blob.

Andramox
  • 43
  • 7
  • Thanks, but... you have not understood the problem. The problem is not that it is different for you or me, or for different browsers, but that it is different between the HTML page on my webspace and on jsFiddle. So it's not because of the browser settings, because they are the same both times. But what is the problem? I have edited the HTML code in my question. Now it is a complete and working HTML page. You can use it. – Andramox Apr 17 '22 at 18:47
  • "or at users discretion" is not the case when something else happens to me both times in the same browser. HTML-Page=blob. jsFiddle=download. The problem here is the display in the browser. With the HTML page the blob is displayed. With jsFiddle the just locally saved PDF is displayed = The PDF has been successfully saved to disk and can be opened offline. This is not the case with blob. – Andramox Apr 17 '22 at 19:50
  • Thanks. But please note that I am not looking for a solution for me (browser settings), but for the script, because it is for the website visitors. So the default browser settings must be set. These are in Firefox for PDF: "Open in Firefox." This will open the blob and not save and open the PDF, or show the dialog popup. This is the problem. – Andramox Apr 18 '22 at 17:25
  • That's something else entirely. The user can decide that for himself anyway. But, in default browser mode it should not be a blob. So how can the script be written, that with default browser settings no blob appears? This is my question since the beginning. – Andramox Apr 20 '22 at 19:13
  • So you're saying that it's not possible for jsPDF to open a file instead of a blob in Firefox default browser settings? How does jsFiddle open a file instead of a blob? – Andramox Apr 21 '22 at 11:07

0 Answers0