DoK
DoK

Reputation: 871

Save PDF DataUri as pdf with jsPDF

Is it possible to create and save a PDF file from dataUri-string with jsPDF? This is my saved string in the database:

var pdfAsDataUri = "data:application/pdf;base64,JVBERi0xLjUK...";

Thanks

Upvotes: 0

Views: 3961

Answers (1)

cocco
cocco

Reputation: 16716

The HTML5 download attribute allows you to specify the desidered filename. This works only in some browsers.

http://caniuse.com/download

So instead of using

window.open("data:application/pdf;base64,JVBERi0xLjUK...");

you can create a download link:

<a href="data:text/plain;charset=utf-8,HELLO!!!!" download="hello.txt">download</a>

To create your download link in javascript using the download attribute and downloading it directly:

var a=document.createElement('a');
a.download='FileName.pdf';
a.href=pdfAsDataUri;
a.click();

else, like i said

window.open(pdfAsDataUri);

but no filename can be specified.


Another solution is to use php and output the correct headers, a binary file and the filename.

As it's not clear which db you are using and where do you want to save the file, btw, if i maybe didn't understand your question correctly and you want to store the pdf somewhere on the server than you need in any case some serverside programming language like php, asp, nodejs and many more.

Upvotes: 3

Related Questions