2

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?

Community
  • 1
  • 1
MarieCarroll
  • 21
  • 1
  • 3
  • 2
    What's unprofessional about "blob"? It stands for "Binary Large OBject". – Joe C Jan 11 '17 at 20:58
  • To a programmer maybe, but to the man on the street it has other meanings - http://www.dictionary.com/browse/blob - so I'd like to call my file results.pdf – MarieCarroll Jan 11 '17 at 21:50
  • I tried to use the various options in the var declaration, such aspdf.output('D','charts') but that stops it working at all – MarieCarroll Jan 12 '17 at 18:09

1 Answers1

1

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,
    });
סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68