简体   繁体   中英

download pdf generated by jspdf with non-default title

This is my first time using jspdf so please forgive me if this is a basic problem.

I have successfully generated the pdf, opening it in a new tab on my browser, with correct filename displayed on topleft. However, when I try to download the file, the filename is not the one thats shows there but the default "download.pdf" no matter what file it is.

I figure out that the simplest solution is

const doc = new jsPDF();
// add some content here.
doc.save("the real file name i want.pdf");

which saves the file locally with no issue, however, I still want to see the file on the browser first and then decide whether to download it or not......

I did some research around, these posts are relevant but they either do not directly solve my issue or seems kind of outdated.....

How to open generated pdf using jspdf in new window

Download PDF file using jsPDF

So far, my best approaches were:

doc.output('dataurlnewwindow'); // open in a new tab but save with default name
window.open(doc.output('bloburi', {filename: `${name} pos.pdf`}), '_blank') // open in a new tab but save with blob name

Any help will be appreciated, thank you in advance!

如果您创建对象 URI,则文件名无法更改,因此您可以改为使用 pdf 查看器库内联显示它,以便您可以更改下载按钮以使其正常工作或将其上传到某个服务器,以便您可以自定义名称.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM