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.
- google.visualization draws the chart.
- html2canvas takes a screenshot of the chart.
- 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.
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?
pdf.setProperties({ title: 'test' });
– Badajozpdfjsnewwindow
. you may be able to update the code and add a user-defined file name for downloading. – Badajoz