Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't find name jsPdf in TypeScript

My task is to print the data's into a pdf file using JavaScript . So i selected jsPdf for my task and Succeeded in that also . My task task is to convert that print task into TypeScript . Here am facing a new problem Can't find name jsPdf in TypeScript i don't know the reason here because the code which was successfully run in my JavaScript is failed to do that when run with TypeScript . I spended two day's for finding solution for that but failed . Refer many site's but didn't find out any solutions . Can someone Help me out from this.

index.html ,

<script src="common/jspdf.min.js"></script>
<script src="common/jspdf.plugin.autotable.js"></script>

My Js File ,

 this.print=function(){
   {
var columns = [" Data","StepData","CateData","CritiData","CheckyData"];
               
      
                var rows = [];
                for (var i = 0 ; i<Data.length; i++) 
                {
                	
                    rows.push([
                        
                        Data[i],
                        StepData[i],
                        CateData[i],
                        CritiData[i],
                        CheckyData[i]
                        
                    ]);
                };
                
                var pdfsize='b2';
               var doc = new jsPDF('p', 'pt',pdfsize);
     
                doc.autoTable(columns, rows, {
                	theme: 'grid', // 'striped', 'grid' or 'plain'
                	headerStyles: {
                        fillColor: [12, 234, 227],
                        textColor: [12, 1, 1]
                    },
                	styles: {
                	      overflow: 'linebreak',
                	      columnWidth: 400
                	    },
                	    beforePageContent: function(data) {
                	    	
                	        doc.text("Process Name :"+mainData.name+"  ||   "+"Description :"+mainData.description, 40, 30);
                	        
                	    },
                    columnStyles: {
                      1: {columnWidth: 60}
                    }
                  });

                  doc.save(mainData.name+".pdf");
            }
        };

Every thing is good as of now , But the Problem arises when i'm tying that with type Script code ,

 printData=(): any =>{
        {
          
                let rows:any = [];
                for (let i:any = 0 ; i<this.Data.length; i++) 
                {
                	
                    rows.push([
                        
                        this.Data[i],
                        this.StepData[i],
                        this.CateData[i],
                        this.CritiData[i],
                        this.FrequData[i]
                        
                    ]);
                };
                
                
                let pdfsize:any='b2';
                let doc :any= new jspdf('p', 'pt',pdfsize);  //this line is having that error
                 
          
                doc.autoTable(columns, rows, {
                	theme: 'grid',
                	headerStyles: {
                        fillColor: [12, 234, 227],
                        textColor: [12, 1, 1]
                   },
                	styles: {
                	      overflow: 'linebreak',
                	      columnWidth: 400
                	    },
                	    beforePageContent: function(data) {
							
                	        doc.text("Process Name :"+procName+"  ||   "+"Description :"+procDescription, 40, 30);
                	        
                	    },
                    columnStyles: {
                      1: {columnWidth: 60}
                    }
                  });

                  doc.save(this.mainData.name+".pdf");
         }   
        };

new jsPdf () was accepted by javaScript , But TypeScript say's Can't find name jsPdf .

like image 663
Beckham_Vinoth Avatar asked Jul 29 '16 14:07

Beckham_Vinoth


1 Answers

Suggestion from comment: Try inserting declare var jsPDF; at the top of your typescript file (above the printdata function). Read more: http://blogs.microsoft.co.il/gilf/2013/07/22/quick-tip-typescript-declare-keyword/

like image 161
Simon Bengtsson Avatar answered Oct 21 '22 01:10

Simon Bengtsson