kmugi
kmugi

Reputation: 363

jsPDF - How to rename doc.output('dataurlnewwindow') url title to "doc.pdf"

When using doc.output('dataurlnewwindow') in jsPDF, the title of the window is a random and abstract url string. Is it actually possible to rename the url according to a website domain name followed by the file name, say doc.pdf?

enter image description here

Thanks!

Upvotes: 2

Views: 8126

Answers (1)

Vasiliki M.
Vasiliki M.

Reputation: 372

For me this is how I managed this. I created my own custom page, where I'd want the pdf to appear, and I added the logic in there. So the url would be something like this http://example.com/pdfpage

Setting some properties regarding the pdf title, author etc, and creating an iframe with text/html data inside. Since you will call this page, you can call it as link with target="_blank" and on pdf output you will use "datauristring" as I show below.

pdf.setProperties({
    title: 'PDF Title',
    subject: 'Info about PDF',
    author: 'PDFAuthor',
    keywords: 'generated, javascript, web 2.0, ajax',
    creator: 'My Company'
});

var iframe = document.createElement('iframe');
iframe.setAttribute('style','position:absolute; top:0;bottom:0;right:0;left:0; height:100%; width:100%');
document.body.appendChild(iframe);
iframe.src = pdf.output('datauristring');
pdf.save('doc.pdf'); /* download the file immediately on loading */

Upvotes: 8

Related Questions