Search code examples
nativescriptjspdfnativescript-plugin

Nativescript TypeScript jsPDF


i'm currently working on creating a pdf files using jsPDF in nativescript/typescript,

I need help on how to save generated pdf files in my internal storage.

I'm quite confusing either doc.save('filename.pdf') line of code did the saving and i try search the files but nothing founds.

Here is my code :

    var doc = new jsPDF('p','pt');
    var fontSize = 16;
    var offsetY = 10;//4.797777777777778;
    var lineHeight = 20;//6.49111111111111;

    doc.setFontSize(fontSize);
    doc.setFontType("bold");
    doc.text(20, 10 + lineHeight * 0 + offsetY, 'My Details ');
    doc.setFontSize(14);
    doc.setFontType("bold");
    doc.text(20, 30 + lineHeight * 1 + offsetY, 'Profiles');
    doc.text(20, 30 + lineHeight * 2 + offsetY, '------------------------------');
    doc.setFontType("normal");
    doc.setFontSize(12);
    doc.text(20, 30 + lineHeight * 3 + offsetY, ' First Name :');
    doc.text(20, 30 + lineHeight * 4 + offsetY, 'Last Name:');

    doc.save('fileName.pdf');
  1. How to perform email services automatically without using email app (install in phone) to manually email to recipients. For this i'm using nativescript-email.

Your help is much appreciated

Thanks in advance


Solution

    1. JSPdf is something designed to work within web browser. The save method would try to open a new browser window and load the base64 PDF string which will not work inside NativeScript environment as it's not a browser but your native app. So you will have to manually write the file using file-system module with the data returned JSPdf library.

    2. Simply you can't do that. None of the email apps allows you to send email in background without user attention. If you want to send a email in background, you will have to hit your server and let your server send a email to recipients.