how to use jsPDF and jspdf-autotable in angular 5












2















I am trying to use jsPDF and jspdf-autotable in my Angular 5.2.0 project. My package.json is below (related parts):



"dependencies": {
...
"jspdf": "^1.3.5",
"jspdf-autotable": "^2.3.2"
...
}


My angular-cli.json is below (related parts):



"scripts": [
...
"../node_modules/jspdf/dist/jspdf.min.js",
"../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"
...
]


My component (related parts ):



import * as jsPDF from 'jspdf';
import 'jspdf-autotable';

@Component({
selector: "energy-login",
templateUrl: "./login.component.html",
styleUrls: ["./login.component.scss"]
})
export class MyComponent implements OnInit {

constructor() {}

ngOnInit() {}

downloadPDF() {

let columns = ["ID", "Name", "Country"];
let rows = [
[1, "Shaw", "Tanzania"],
[2, "Nelson", "Kazakhstan"],
[3, "Garcia", "Madagascar"],
];

let doc = new jsPDF('l', 'pt');
doc.autoTable(columns, rows); // typescript compile time error
doc.save('table.pdf');
}
}


It says:



[ts] Property 'autoTable' does not exist on type 'jsPDF'.


I tried to replace imports in my component with



// import * as jsPDF from 'jspdf';
// import 'jspdf-autotable';
declare var jsPDF: any;


then there is no compile time error but while running downloadPDF() function it says :



ERROR ReferenceError: jsPDF is not defined









share|improve this question





























    2















    I am trying to use jsPDF and jspdf-autotable in my Angular 5.2.0 project. My package.json is below (related parts):



    "dependencies": {
    ...
    "jspdf": "^1.3.5",
    "jspdf-autotable": "^2.3.2"
    ...
    }


    My angular-cli.json is below (related parts):



    "scripts": [
    ...
    "../node_modules/jspdf/dist/jspdf.min.js",
    "../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"
    ...
    ]


    My component (related parts ):



    import * as jsPDF from 'jspdf';
    import 'jspdf-autotable';

    @Component({
    selector: "energy-login",
    templateUrl: "./login.component.html",
    styleUrls: ["./login.component.scss"]
    })
    export class MyComponent implements OnInit {

    constructor() {}

    ngOnInit() {}

    downloadPDF() {

    let columns = ["ID", "Name", "Country"];
    let rows = [
    [1, "Shaw", "Tanzania"],
    [2, "Nelson", "Kazakhstan"],
    [3, "Garcia", "Madagascar"],
    ];

    let doc = new jsPDF('l', 'pt');
    doc.autoTable(columns, rows); // typescript compile time error
    doc.save('table.pdf');
    }
    }


    It says:



    [ts] Property 'autoTable' does not exist on type 'jsPDF'.


    I tried to replace imports in my component with



    // import * as jsPDF from 'jspdf';
    // import 'jspdf-autotable';
    declare var jsPDF: any;


    then there is no compile time error but while running downloadPDF() function it says :



    ERROR ReferenceError: jsPDF is not defined









    share|improve this question



























      2












      2








      2


      2






      I am trying to use jsPDF and jspdf-autotable in my Angular 5.2.0 project. My package.json is below (related parts):



      "dependencies": {
      ...
      "jspdf": "^1.3.5",
      "jspdf-autotable": "^2.3.2"
      ...
      }


      My angular-cli.json is below (related parts):



      "scripts": [
      ...
      "../node_modules/jspdf/dist/jspdf.min.js",
      "../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"
      ...
      ]


      My component (related parts ):



      import * as jsPDF from 'jspdf';
      import 'jspdf-autotable';

      @Component({
      selector: "energy-login",
      templateUrl: "./login.component.html",
      styleUrls: ["./login.component.scss"]
      })
      export class MyComponent implements OnInit {

      constructor() {}

      ngOnInit() {}

      downloadPDF() {

      let columns = ["ID", "Name", "Country"];
      let rows = [
      [1, "Shaw", "Tanzania"],
      [2, "Nelson", "Kazakhstan"],
      [3, "Garcia", "Madagascar"],
      ];

      let doc = new jsPDF('l', 'pt');
      doc.autoTable(columns, rows); // typescript compile time error
      doc.save('table.pdf');
      }
      }


      It says:



      [ts] Property 'autoTable' does not exist on type 'jsPDF'.


      I tried to replace imports in my component with



      // import * as jsPDF from 'jspdf';
      // import 'jspdf-autotable';
      declare var jsPDF: any;


      then there is no compile time error but while running downloadPDF() function it says :



      ERROR ReferenceError: jsPDF is not defined









      share|improve this question
















      I am trying to use jsPDF and jspdf-autotable in my Angular 5.2.0 project. My package.json is below (related parts):



      "dependencies": {
      ...
      "jspdf": "^1.3.5",
      "jspdf-autotable": "^2.3.2"
      ...
      }


      My angular-cli.json is below (related parts):



      "scripts": [
      ...
      "../node_modules/jspdf/dist/jspdf.min.js",
      "../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"
      ...
      ]


      My component (related parts ):



      import * as jsPDF from 'jspdf';
      import 'jspdf-autotable';

      @Component({
      selector: "energy-login",
      templateUrl: "./login.component.html",
      styleUrls: ["./login.component.scss"]
      })
      export class MyComponent implements OnInit {

      constructor() {}

      ngOnInit() {}

      downloadPDF() {

      let columns = ["ID", "Name", "Country"];
      let rows = [
      [1, "Shaw", "Tanzania"],
      [2, "Nelson", "Kazakhstan"],
      [3, "Garcia", "Madagascar"],
      ];

      let doc = new jsPDF('l', 'pt');
      doc.autoTable(columns, rows); // typescript compile time error
      doc.save('table.pdf');
      }
      }


      It says:



      [ts] Property 'autoTable' does not exist on type 'jsPDF'.


      I tried to replace imports in my component with



      // import * as jsPDF from 'jspdf';
      // import 'jspdf-autotable';
      declare var jsPDF: any;


      then there is no compile time error but while running downloadPDF() function it says :



      ERROR ReferenceError: jsPDF is not defined






      angular jspdf jspdf-autotable






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 23 '18 at 8:53







      RIDVAN TANIK

















      asked Mar 23 '18 at 8:26









      RIDVAN TANIKRIDVAN TANIK

      2116




      2116
























          7 Answers
          7






          active

          oldest

          votes


















          6














          Is working for me Angular 5.



          To work with jspdf-autotable in angular 5, one must install jspdf and jspdf-autotable via npm



          npm install jspdf --save
          npm install @types/jspdf --save-dev
          npm install jspdf-autotable --save


          also add the jspdf and jspdf-autotable files to the scripts array in angular-cli.json



          "scripts": [
          "../node_modules/jspdf/dist/jspdf.min.js",
          "../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"
          ],


          and in component never import jspdf or jspdf-autotable just.



          Forget about the following import.






          import * as jsPDF from 'jspdf';
          import 'jspdf-autotable';




          Just use Before @Component:



          declare var jsPDF: any;


          Your component (related parts ):



          declare var jsPDF: any;

          @Component({
          selector: "energy-login",
          templateUrl: "./login.component.html",
          styleUrls: ["./login.component.scss"]
          })

          export class MyComponent implements OnInit {

          constructor() {}

          ngOnInit() {}

          downloadPDF() {

          let columns = ["ID", "Name", "Country"];
          let rows = [
          [1, "Shaw", "Tanzania"],
          [2, "Nelson", "Kazakhstan"],
          [3, "Garcia", "Madagascar"],
          ];

          let doc = new jsPDF('l', 'pt');
          doc.autoTable(columns, rows); // typescript compile time error
          doc.save('table.pdf');
          }
          }





          share|improve this answer



















          • 1





            Thanks @Alciomar Hollanda, It help me a lot.

            – Mohammad Ali
            Sep 12 '18 at 5:30



















          2














          First you have declared .js files in styles property in angular-cli.json, you should add them to scripts. In the configuration that you have, you should add your jspdf scripts to scripts in angular-cli.json, So:



          "scripts": [ 
          "../node_modules/jspdf/dist/jspdf.min.js",
          "../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"
          ],


          then you don't have to import any jspdf to your component. declare var jsPdf: any will be enough to use it.






          share|improve this answer





















          • 1





            thank you. Your right .js files should be declared in scripts array, and I actually declared them in there - fixed it in the question. My previous attempt was installing dependencies via npm. That is why my dependencies object in package.json includes "jspdf": "^1.3.5", "jspdf-autotable": "^2.3.2" also devDependencies object includes "@types/jspdf": "^1.1.31". Anyway i solved my problem. Answering my question below.

            – RIDVAN TANIK
            Mar 23 '18 at 9:02





















          2














          In angular-cli.json



          "scripts": [
          "../node_modules/jspdf/dist/jspdf.min.js"
          ],


          In your project



          import * as jsPdf from 'jspdf';
          import 'jspdf-autotable';


          This work for me






          share|improve this answer































            1














            To work with jspdf-autotable in angular 5, one must install jspdf and jspdf-autotable via npm



            npm install jspdf-autotable --save


            also add the jspdf and jspdf-autotable files to the scripts array in angular-cli.json



            "scripts": [
            "../node_modules/jspdf/dist/jspdf.min.js",
            "../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"
            ],


            and in component never import jspdf or jspdf-autotable just



            declare var jsPDF: any;


            Of course before working with jspdf-autotable one should install jspdf and for development @types/jspdf via npm



            npm install jspdf --save
            npm install @types/jspdf --save-dev





            share|improve this answer































              1














              If you could use declare var jsPDF: any; it is working for Chrome, IE and other browsers too, but it is not working for Firefox browser.



              In this case, you could follow the below steps:



              declare const require: any;
              const jsPDF = require('jspdf');
              require('jspdf-autotable');


              and other parts remain same like:



              npm install jspdf --save
              npm install @types/jspdf --save-dev
              npm install jspdf-autotable --save


              "scripts": [
              "../node_modules/jspdf/dist/jspdf.min.js",
              "../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"
              ],


              So, it will defiantly work on all the browsers.
              how simple it is :)






              share|improve this answer































                0














                I solved this issue, first import the Jspdf import * as jsPDF from 'jspdf';
                i'm used a codesmells tatic, copied the content of jspdf autotable and pasted inside
                the jspdf.js, then works fine for me.



                in the official site said you have to use //declare var jsPDF: any; // Important . it doesnt work in my case, try import * as jsPDF from 'jspdf'; instead.



                in angular.json in scripts :



                "./node_modules/jspdf/dist/jspdf.min.js",
                "./node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js",






                share|improve this answer































                  0














                  I'm using angular 7, and just declare var jsPDF: any; doesn't work to me. After some googling, the solution was:



                  declare const require: any;
                  const jsPDF = require('jspdf');
                  require('jspdf-autotable');


                  And of course, I installed the modules from npm and include them into the scripts array in angular.json. It works fine to me.






                  share|improve this answer
























                    Your Answer






                    StackExchange.ifUsing("editor", function () {
                    StackExchange.using("externalEditor", function () {
                    StackExchange.using("snippets", function () {
                    StackExchange.snippets.init();
                    });
                    });
                    }, "code-snippets");

                    StackExchange.ready(function() {
                    var channelOptions = {
                    tags: "".split(" "),
                    id: "1"
                    };
                    initTagRenderer("".split(" "), "".split(" "), channelOptions);

                    StackExchange.using("externalEditor", function() {
                    // Have to fire editor after snippets, if snippets enabled
                    if (StackExchange.settings.snippets.snippetsEnabled) {
                    StackExchange.using("snippets", function() {
                    createEditor();
                    });
                    }
                    else {
                    createEditor();
                    }
                    });

                    function createEditor() {
                    StackExchange.prepareEditor({
                    heartbeatType: 'answer',
                    autoActivateHeartbeat: false,
                    convertImagesToLinks: true,
                    noModals: true,
                    showLowRepImageUploadWarning: true,
                    reputationToPostImages: 10,
                    bindNavPrevention: true,
                    postfix: "",
                    imageUploader: {
                    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                    allowUrls: true
                    },
                    onDemand: true,
                    discardSelector: ".discard-answer"
                    ,immediatelyShowMarkdownHelp:true
                    });


                    }
                    });














                    draft saved

                    draft discarded


















                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f49445269%2fhow-to-use-jspdf-and-jspdf-autotable-in-angular-5%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown

























                    7 Answers
                    7






                    active

                    oldest

                    votes








                    7 Answers
                    7






                    active

                    oldest

                    votes









                    active

                    oldest

                    votes






                    active

                    oldest

                    votes









                    6














                    Is working for me Angular 5.



                    To work with jspdf-autotable in angular 5, one must install jspdf and jspdf-autotable via npm



                    npm install jspdf --save
                    npm install @types/jspdf --save-dev
                    npm install jspdf-autotable --save


                    also add the jspdf and jspdf-autotable files to the scripts array in angular-cli.json



                    "scripts": [
                    "../node_modules/jspdf/dist/jspdf.min.js",
                    "../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"
                    ],


                    and in component never import jspdf or jspdf-autotable just.



                    Forget about the following import.






                    import * as jsPDF from 'jspdf';
                    import 'jspdf-autotable';




                    Just use Before @Component:



                    declare var jsPDF: any;


                    Your component (related parts ):



                    declare var jsPDF: any;

                    @Component({
                    selector: "energy-login",
                    templateUrl: "./login.component.html",
                    styleUrls: ["./login.component.scss"]
                    })

                    export class MyComponent implements OnInit {

                    constructor() {}

                    ngOnInit() {}

                    downloadPDF() {

                    let columns = ["ID", "Name", "Country"];
                    let rows = [
                    [1, "Shaw", "Tanzania"],
                    [2, "Nelson", "Kazakhstan"],
                    [3, "Garcia", "Madagascar"],
                    ];

                    let doc = new jsPDF('l', 'pt');
                    doc.autoTable(columns, rows); // typescript compile time error
                    doc.save('table.pdf');
                    }
                    }





                    share|improve this answer



















                    • 1





                      Thanks @Alciomar Hollanda, It help me a lot.

                      – Mohammad Ali
                      Sep 12 '18 at 5:30
















                    6














                    Is working for me Angular 5.



                    To work with jspdf-autotable in angular 5, one must install jspdf and jspdf-autotable via npm



                    npm install jspdf --save
                    npm install @types/jspdf --save-dev
                    npm install jspdf-autotable --save


                    also add the jspdf and jspdf-autotable files to the scripts array in angular-cli.json



                    "scripts": [
                    "../node_modules/jspdf/dist/jspdf.min.js",
                    "../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"
                    ],


                    and in component never import jspdf or jspdf-autotable just.



                    Forget about the following import.






                    import * as jsPDF from 'jspdf';
                    import 'jspdf-autotable';




                    Just use Before @Component:



                    declare var jsPDF: any;


                    Your component (related parts ):



                    declare var jsPDF: any;

                    @Component({
                    selector: "energy-login",
                    templateUrl: "./login.component.html",
                    styleUrls: ["./login.component.scss"]
                    })

                    export class MyComponent implements OnInit {

                    constructor() {}

                    ngOnInit() {}

                    downloadPDF() {

                    let columns = ["ID", "Name", "Country"];
                    let rows = [
                    [1, "Shaw", "Tanzania"],
                    [2, "Nelson", "Kazakhstan"],
                    [3, "Garcia", "Madagascar"],
                    ];

                    let doc = new jsPDF('l', 'pt');
                    doc.autoTable(columns, rows); // typescript compile time error
                    doc.save('table.pdf');
                    }
                    }





                    share|improve this answer



















                    • 1





                      Thanks @Alciomar Hollanda, It help me a lot.

                      – Mohammad Ali
                      Sep 12 '18 at 5:30














                    6












                    6








                    6







                    Is working for me Angular 5.



                    To work with jspdf-autotable in angular 5, one must install jspdf and jspdf-autotable via npm



                    npm install jspdf --save
                    npm install @types/jspdf --save-dev
                    npm install jspdf-autotable --save


                    also add the jspdf and jspdf-autotable files to the scripts array in angular-cli.json



                    "scripts": [
                    "../node_modules/jspdf/dist/jspdf.min.js",
                    "../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"
                    ],


                    and in component never import jspdf or jspdf-autotable just.



                    Forget about the following import.






                    import * as jsPDF from 'jspdf';
                    import 'jspdf-autotable';




                    Just use Before @Component:



                    declare var jsPDF: any;


                    Your component (related parts ):



                    declare var jsPDF: any;

                    @Component({
                    selector: "energy-login",
                    templateUrl: "./login.component.html",
                    styleUrls: ["./login.component.scss"]
                    })

                    export class MyComponent implements OnInit {

                    constructor() {}

                    ngOnInit() {}

                    downloadPDF() {

                    let columns = ["ID", "Name", "Country"];
                    let rows = [
                    [1, "Shaw", "Tanzania"],
                    [2, "Nelson", "Kazakhstan"],
                    [3, "Garcia", "Madagascar"],
                    ];

                    let doc = new jsPDF('l', 'pt');
                    doc.autoTable(columns, rows); // typescript compile time error
                    doc.save('table.pdf');
                    }
                    }





                    share|improve this answer













                    Is working for me Angular 5.



                    To work with jspdf-autotable in angular 5, one must install jspdf and jspdf-autotable via npm



                    npm install jspdf --save
                    npm install @types/jspdf --save-dev
                    npm install jspdf-autotable --save


                    also add the jspdf and jspdf-autotable files to the scripts array in angular-cli.json



                    "scripts": [
                    "../node_modules/jspdf/dist/jspdf.min.js",
                    "../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"
                    ],


                    and in component never import jspdf or jspdf-autotable just.



                    Forget about the following import.






                    import * as jsPDF from 'jspdf';
                    import 'jspdf-autotable';




                    Just use Before @Component:



                    declare var jsPDF: any;


                    Your component (related parts ):



                    declare var jsPDF: any;

                    @Component({
                    selector: "energy-login",
                    templateUrl: "./login.component.html",
                    styleUrls: ["./login.component.scss"]
                    })

                    export class MyComponent implements OnInit {

                    constructor() {}

                    ngOnInit() {}

                    downloadPDF() {

                    let columns = ["ID", "Name", "Country"];
                    let rows = [
                    [1, "Shaw", "Tanzania"],
                    [2, "Nelson", "Kazakhstan"],
                    [3, "Garcia", "Madagascar"],
                    ];

                    let doc = new jsPDF('l', 'pt');
                    doc.autoTable(columns, rows); // typescript compile time error
                    doc.save('table.pdf');
                    }
                    }






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jul 24 '18 at 21:37









                    Alciomar HollandaAlciomar Hollanda

                    34036




                    34036








                    • 1





                      Thanks @Alciomar Hollanda, It help me a lot.

                      – Mohammad Ali
                      Sep 12 '18 at 5:30














                    • 1





                      Thanks @Alciomar Hollanda, It help me a lot.

                      – Mohammad Ali
                      Sep 12 '18 at 5:30








                    1




                    1





                    Thanks @Alciomar Hollanda, It help me a lot.

                    – Mohammad Ali
                    Sep 12 '18 at 5:30





                    Thanks @Alciomar Hollanda, It help me a lot.

                    – Mohammad Ali
                    Sep 12 '18 at 5:30













                    2














                    First you have declared .js files in styles property in angular-cli.json, you should add them to scripts. In the configuration that you have, you should add your jspdf scripts to scripts in angular-cli.json, So:



                    "scripts": [ 
                    "../node_modules/jspdf/dist/jspdf.min.js",
                    "../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"
                    ],


                    then you don't have to import any jspdf to your component. declare var jsPdf: any will be enough to use it.






                    share|improve this answer





















                    • 1





                      thank you. Your right .js files should be declared in scripts array, and I actually declared them in there - fixed it in the question. My previous attempt was installing dependencies via npm. That is why my dependencies object in package.json includes "jspdf": "^1.3.5", "jspdf-autotable": "^2.3.2" also devDependencies object includes "@types/jspdf": "^1.1.31". Anyway i solved my problem. Answering my question below.

                      – RIDVAN TANIK
                      Mar 23 '18 at 9:02


















                    2














                    First you have declared .js files in styles property in angular-cli.json, you should add them to scripts. In the configuration that you have, you should add your jspdf scripts to scripts in angular-cli.json, So:



                    "scripts": [ 
                    "../node_modules/jspdf/dist/jspdf.min.js",
                    "../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"
                    ],


                    then you don't have to import any jspdf to your component. declare var jsPdf: any will be enough to use it.






                    share|improve this answer





















                    • 1





                      thank you. Your right .js files should be declared in scripts array, and I actually declared them in there - fixed it in the question. My previous attempt was installing dependencies via npm. That is why my dependencies object in package.json includes "jspdf": "^1.3.5", "jspdf-autotable": "^2.3.2" also devDependencies object includes "@types/jspdf": "^1.1.31". Anyway i solved my problem. Answering my question below.

                      – RIDVAN TANIK
                      Mar 23 '18 at 9:02
















                    2












                    2








                    2







                    First you have declared .js files in styles property in angular-cli.json, you should add them to scripts. In the configuration that you have, you should add your jspdf scripts to scripts in angular-cli.json, So:



                    "scripts": [ 
                    "../node_modules/jspdf/dist/jspdf.min.js",
                    "../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"
                    ],


                    then you don't have to import any jspdf to your component. declare var jsPdf: any will be enough to use it.






                    share|improve this answer















                    First you have declared .js files in styles property in angular-cli.json, you should add them to scripts. In the configuration that you have, you should add your jspdf scripts to scripts in angular-cli.json, So:



                    "scripts": [ 
                    "../node_modules/jspdf/dist/jspdf.min.js",
                    "../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"
                    ],


                    then you don't have to import any jspdf to your component. declare var jsPdf: any will be enough to use it.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Mar 23 '18 at 8:49

























                    answered Mar 23 '18 at 8:38









                    EfeEfe

                    1,4301524




                    1,4301524








                    • 1





                      thank you. Your right .js files should be declared in scripts array, and I actually declared them in there - fixed it in the question. My previous attempt was installing dependencies via npm. That is why my dependencies object in package.json includes "jspdf": "^1.3.5", "jspdf-autotable": "^2.3.2" also devDependencies object includes "@types/jspdf": "^1.1.31". Anyway i solved my problem. Answering my question below.

                      – RIDVAN TANIK
                      Mar 23 '18 at 9:02
















                    • 1





                      thank you. Your right .js files should be declared in scripts array, and I actually declared them in there - fixed it in the question. My previous attempt was installing dependencies via npm. That is why my dependencies object in package.json includes "jspdf": "^1.3.5", "jspdf-autotable": "^2.3.2" also devDependencies object includes "@types/jspdf": "^1.1.31". Anyway i solved my problem. Answering my question below.

                      – RIDVAN TANIK
                      Mar 23 '18 at 9:02










                    1




                    1





                    thank you. Your right .js files should be declared in scripts array, and I actually declared them in there - fixed it in the question. My previous attempt was installing dependencies via npm. That is why my dependencies object in package.json includes "jspdf": "^1.3.5", "jspdf-autotable": "^2.3.2" also devDependencies object includes "@types/jspdf": "^1.1.31". Anyway i solved my problem. Answering my question below.

                    – RIDVAN TANIK
                    Mar 23 '18 at 9:02







                    thank you. Your right .js files should be declared in scripts array, and I actually declared them in there - fixed it in the question. My previous attempt was installing dependencies via npm. That is why my dependencies object in package.json includes "jspdf": "^1.3.5", "jspdf-autotable": "^2.3.2" also devDependencies object includes "@types/jspdf": "^1.1.31". Anyway i solved my problem. Answering my question below.

                    – RIDVAN TANIK
                    Mar 23 '18 at 9:02













                    2














                    In angular-cli.json



                    "scripts": [
                    "../node_modules/jspdf/dist/jspdf.min.js"
                    ],


                    In your project



                    import * as jsPdf from 'jspdf';
                    import 'jspdf-autotable';


                    This work for me






                    share|improve this answer




























                      2














                      In angular-cli.json



                      "scripts": [
                      "../node_modules/jspdf/dist/jspdf.min.js"
                      ],


                      In your project



                      import * as jsPdf from 'jspdf';
                      import 'jspdf-autotable';


                      This work for me






                      share|improve this answer


























                        2












                        2








                        2







                        In angular-cli.json



                        "scripts": [
                        "../node_modules/jspdf/dist/jspdf.min.js"
                        ],


                        In your project



                        import * as jsPdf from 'jspdf';
                        import 'jspdf-autotable';


                        This work for me






                        share|improve this answer













                        In angular-cli.json



                        "scripts": [
                        "../node_modules/jspdf/dist/jspdf.min.js"
                        ],


                        In your project



                        import * as jsPdf from 'jspdf';
                        import 'jspdf-autotable';


                        This work for me







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Mar 28 '18 at 2:52









                        JimJim

                        6611




                        6611























                            1














                            To work with jspdf-autotable in angular 5, one must install jspdf and jspdf-autotable via npm



                            npm install jspdf-autotable --save


                            also add the jspdf and jspdf-autotable files to the scripts array in angular-cli.json



                            "scripts": [
                            "../node_modules/jspdf/dist/jspdf.min.js",
                            "../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"
                            ],


                            and in component never import jspdf or jspdf-autotable just



                            declare var jsPDF: any;


                            Of course before working with jspdf-autotable one should install jspdf and for development @types/jspdf via npm



                            npm install jspdf --save
                            npm install @types/jspdf --save-dev





                            share|improve this answer




























                              1














                              To work with jspdf-autotable in angular 5, one must install jspdf and jspdf-autotable via npm



                              npm install jspdf-autotable --save


                              also add the jspdf and jspdf-autotable files to the scripts array in angular-cli.json



                              "scripts": [
                              "../node_modules/jspdf/dist/jspdf.min.js",
                              "../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"
                              ],


                              and in component never import jspdf or jspdf-autotable just



                              declare var jsPDF: any;


                              Of course before working with jspdf-autotable one should install jspdf and for development @types/jspdf via npm



                              npm install jspdf --save
                              npm install @types/jspdf --save-dev





                              share|improve this answer


























                                1












                                1








                                1







                                To work with jspdf-autotable in angular 5, one must install jspdf and jspdf-autotable via npm



                                npm install jspdf-autotable --save


                                also add the jspdf and jspdf-autotable files to the scripts array in angular-cli.json



                                "scripts": [
                                "../node_modules/jspdf/dist/jspdf.min.js",
                                "../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"
                                ],


                                and in component never import jspdf or jspdf-autotable just



                                declare var jsPDF: any;


                                Of course before working with jspdf-autotable one should install jspdf and for development @types/jspdf via npm



                                npm install jspdf --save
                                npm install @types/jspdf --save-dev





                                share|improve this answer













                                To work with jspdf-autotable in angular 5, one must install jspdf and jspdf-autotable via npm



                                npm install jspdf-autotable --save


                                also add the jspdf and jspdf-autotable files to the scripts array in angular-cli.json



                                "scripts": [
                                "../node_modules/jspdf/dist/jspdf.min.js",
                                "../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"
                                ],


                                and in component never import jspdf or jspdf-autotable just



                                declare var jsPDF: any;


                                Of course before working with jspdf-autotable one should install jspdf and for development @types/jspdf via npm



                                npm install jspdf --save
                                npm install @types/jspdf --save-dev






                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Mar 23 '18 at 9:30









                                RIDVAN TANIKRIDVAN TANIK

                                2116




                                2116























                                    1














                                    If you could use declare var jsPDF: any; it is working for Chrome, IE and other browsers too, but it is not working for Firefox browser.



                                    In this case, you could follow the below steps:



                                    declare const require: any;
                                    const jsPDF = require('jspdf');
                                    require('jspdf-autotable');


                                    and other parts remain same like:



                                    npm install jspdf --save
                                    npm install @types/jspdf --save-dev
                                    npm install jspdf-autotable --save


                                    "scripts": [
                                    "../node_modules/jspdf/dist/jspdf.min.js",
                                    "../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"
                                    ],


                                    So, it will defiantly work on all the browsers.
                                    how simple it is :)






                                    share|improve this answer




























                                      1














                                      If you could use declare var jsPDF: any; it is working for Chrome, IE and other browsers too, but it is not working for Firefox browser.



                                      In this case, you could follow the below steps:



                                      declare const require: any;
                                      const jsPDF = require('jspdf');
                                      require('jspdf-autotable');


                                      and other parts remain same like:



                                      npm install jspdf --save
                                      npm install @types/jspdf --save-dev
                                      npm install jspdf-autotable --save


                                      "scripts": [
                                      "../node_modules/jspdf/dist/jspdf.min.js",
                                      "../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"
                                      ],


                                      So, it will defiantly work on all the browsers.
                                      how simple it is :)






                                      share|improve this answer


























                                        1












                                        1








                                        1







                                        If you could use declare var jsPDF: any; it is working for Chrome, IE and other browsers too, but it is not working for Firefox browser.



                                        In this case, you could follow the below steps:



                                        declare const require: any;
                                        const jsPDF = require('jspdf');
                                        require('jspdf-autotable');


                                        and other parts remain same like:



                                        npm install jspdf --save
                                        npm install @types/jspdf --save-dev
                                        npm install jspdf-autotable --save


                                        "scripts": [
                                        "../node_modules/jspdf/dist/jspdf.min.js",
                                        "../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"
                                        ],


                                        So, it will defiantly work on all the browsers.
                                        how simple it is :)






                                        share|improve this answer













                                        If you could use declare var jsPDF: any; it is working for Chrome, IE and other browsers too, but it is not working for Firefox browser.



                                        In this case, you could follow the below steps:



                                        declare const require: any;
                                        const jsPDF = require('jspdf');
                                        require('jspdf-autotable');


                                        and other parts remain same like:



                                        npm install jspdf --save
                                        npm install @types/jspdf --save-dev
                                        npm install jspdf-autotable --save


                                        "scripts": [
                                        "../node_modules/jspdf/dist/jspdf.min.js",
                                        "../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"
                                        ],


                                        So, it will defiantly work on all the browsers.
                                        how simple it is :)







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Mar 11 at 3:53









                                        Rahul ChavanRahul Chavan

                                        112




                                        112























                                            0














                                            I solved this issue, first import the Jspdf import * as jsPDF from 'jspdf';
                                            i'm used a codesmells tatic, copied the content of jspdf autotable and pasted inside
                                            the jspdf.js, then works fine for me.



                                            in the official site said you have to use //declare var jsPDF: any; // Important . it doesnt work in my case, try import * as jsPDF from 'jspdf'; instead.



                                            in angular.json in scripts :



                                            "./node_modules/jspdf/dist/jspdf.min.js",
                                            "./node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js",






                                            share|improve this answer




























                                              0














                                              I solved this issue, first import the Jspdf import * as jsPDF from 'jspdf';
                                              i'm used a codesmells tatic, copied the content of jspdf autotable and pasted inside
                                              the jspdf.js, then works fine for me.



                                              in the official site said you have to use //declare var jsPDF: any; // Important . it doesnt work in my case, try import * as jsPDF from 'jspdf'; instead.



                                              in angular.json in scripts :



                                              "./node_modules/jspdf/dist/jspdf.min.js",
                                              "./node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js",






                                              share|improve this answer


























                                                0












                                                0








                                                0







                                                I solved this issue, first import the Jspdf import * as jsPDF from 'jspdf';
                                                i'm used a codesmells tatic, copied the content of jspdf autotable and pasted inside
                                                the jspdf.js, then works fine for me.



                                                in the official site said you have to use //declare var jsPDF: any; // Important . it doesnt work in my case, try import * as jsPDF from 'jspdf'; instead.



                                                in angular.json in scripts :



                                                "./node_modules/jspdf/dist/jspdf.min.js",
                                                "./node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js",






                                                share|improve this answer













                                                I solved this issue, first import the Jspdf import * as jsPDF from 'jspdf';
                                                i'm used a codesmells tatic, copied the content of jspdf autotable and pasted inside
                                                the jspdf.js, then works fine for me.



                                                in the official site said you have to use //declare var jsPDF: any; // Important . it doesnt work in my case, try import * as jsPDF from 'jspdf'; instead.



                                                in angular.json in scripts :



                                                "./node_modules/jspdf/dist/jspdf.min.js",
                                                "./node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js",







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Jan 3 at 0:52









                                                gaston villafañegaston villafañe

                                                1




                                                1























                                                    0














                                                    I'm using angular 7, and just declare var jsPDF: any; doesn't work to me. After some googling, the solution was:



                                                    declare const require: any;
                                                    const jsPDF = require('jspdf');
                                                    require('jspdf-autotable');


                                                    And of course, I installed the modules from npm and include them into the scripts array in angular.json. It works fine to me.






                                                    share|improve this answer




























                                                      0














                                                      I'm using angular 7, and just declare var jsPDF: any; doesn't work to me. After some googling, the solution was:



                                                      declare const require: any;
                                                      const jsPDF = require('jspdf');
                                                      require('jspdf-autotable');


                                                      And of course, I installed the modules from npm and include them into the scripts array in angular.json. It works fine to me.






                                                      share|improve this answer


























                                                        0












                                                        0








                                                        0







                                                        I'm using angular 7, and just declare var jsPDF: any; doesn't work to me. After some googling, the solution was:



                                                        declare const require: any;
                                                        const jsPDF = require('jspdf');
                                                        require('jspdf-autotable');


                                                        And of course, I installed the modules from npm and include them into the scripts array in angular.json. It works fine to me.






                                                        share|improve this answer













                                                        I'm using angular 7, and just declare var jsPDF: any; doesn't work to me. After some googling, the solution was:



                                                        declare const require: any;
                                                        const jsPDF = require('jspdf');
                                                        require('jspdf-autotable');


                                                        And of course, I installed the modules from npm and include them into the scripts array in angular.json. It works fine to me.







                                                        share|improve this answer












                                                        share|improve this answer



                                                        share|improve this answer










                                                        answered Jan 23 at 17:25









                                                        André PachecoAndré Pacheco

                                                        396212




                                                        396212






























                                                            draft saved

                                                            draft discarded




















































                                                            Thanks for contributing an answer to Stack Overflow!


                                                            • Please be sure to answer the question. Provide details and share your research!

                                                            But avoid



                                                            • Asking for help, clarification, or responding to other answers.

                                                            • Making statements based on opinion; back them up with references or personal experience.


                                                            To learn more, see our tips on writing great answers.




                                                            draft saved


                                                            draft discarded














                                                            StackExchange.ready(
                                                            function () {
                                                            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f49445269%2fhow-to-use-jspdf-and-jspdf-autotable-in-angular-5%23new-answer', 'question_page');
                                                            }
                                                            );

                                                            Post as a guest















                                                            Required, but never shown





















































                                                            Required, but never shown














                                                            Required, but never shown












                                                            Required, but never shown







                                                            Required, but never shown

































                                                            Required, but never shown














                                                            Required, but never shown












                                                            Required, but never shown







                                                            Required, but never shown







                                                            Popular posts from this blog

                                                            MongoDB - Not Authorized To Execute Command

                                                            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

                                                            Npm cannot find a required file even through it is in the searched directory