7

My site draws a column chart. I have a button to save it as a PDF file showing it before saving.

The way it works now is this.

  1. google.visualization draws the chart.
  2. html2canvas takes a screenshot of the chart.
  3. jsPDF inserts the screenshot in a PDF file and shows it to the user.

The problem is the name of the PDF file. It is something like 5d78c1eb-0829-4e7e-8ffc-71cf1f102f56.pdf and the url is blob:http://example.com/5d78c1eb-0829-4e7e-8ffc-71cf1f102f56 When user sees the PDF and clicks save he receives this awful file name.

enter image description here Now I show the PDF this way:

window.open(doc.output('bloburl'), '_blank');

I can set desired file name if I change this line to this:

doc.save('sample-file.pdf');

But in such a case the file just downloads but I need to show it first.

Is there a way to show the PDF and give it a desirable name? I tried this:

window.open(doc.output('bloburl', {filename: 'myFileName.pdf'}), '_blank');

But it did not help.

Another way I see is not showing the PDF from jsPDF, but sending images to the server and making a PDF file there using TCPDF. The files made with TCPDF can have a name I give it, but I think it is dumb to send the images there and back.

So the question is how can I make a PDF and show it to the user with the name I want?

K J
  • 8,045
  • 3
  • 14
  • 36

1 Answers1

1

At the moment the answer is no. You can download it directly, as mentioned in the accepted answer of this question: Download with filename

But you create an objectUrl and therefore the filename is always the url. Maybe you could create an browser-extension for this...but I haven't had the time to try yet. Furthermore, you can't expect your visitors to have the extension installed.

Nikolaus
  • 1,859
  • 1
  • 10
  • 16