MarieCarroll
MarieCarroll

Reputation: 21

Give jspdf() blob a filename

I am using jspdf() on mobile devices which doesn't work in the same way as on desktops for saving the resulting pdf. I found this workaround on here using a blob - Download using jsPDF on a mobile devices which does create a pdf that opens on a mobile device. My only issue is the file is then called blob - which is not very professional in my view - and if the file is then opened in say ibooks it shows as unknown as there are no file details.

This is the code I am using

if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent))
{
   var blob = pdf.output();
   window.open(URL.createObjectURL(blob));
}
else
{
   pdf.save('results.pdf');
}

Is there a way to name the blob?

Upvotes: 2

Views: 5202

Answers (1)

abhinandan jain
abhinandan jain

Reputation: 21

Create a new file and then give a name to file:

pdfAttachment : Files; //declare the file
newName = 'new_file_name'      
this.pdfAttachment = new File([doc.output('blob')], newName, {
      type: doc.output('blob').type,
      lastModified: doc.output('blob').lastModified,
    });

Upvotes: 1

Related Questions