在TypeScript中找不到名称jsPdf [英] Can't find name jsPdf in TypeScript

查看:143
本文介绍了在TypeScript中找不到名称jsPdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的任务是使用JavaScript将数据打印到pdf文件中.因此,我为任务选择了jsPdf并在其中也成功.我的任务是将打印任务转换为TypeScript.这里面临着一个新问题Can't find name jsPdf in TypeScript,我不知道这里的原因,因为在使用TypeScript运行时,在我的JavaScript中成功运行的代码无法做到这一点.我花了两天的时间来解决这个问题,但是失败了.推荐许多站点的站点,但未找到任何解决方案.有人可以帮我吗?

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>

我的Js文件

 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");
            }
        };

到目前为止,一切都很好,但是当我用 type脚本代码

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");
         }   
        };

新的jsPdf()被javaScript接受,但是TypeScript说了找不到名称jsPdf .

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

推荐答案

注释建议:尝试在打字稿文件顶部(在printdata函数上方)插入declare var jsPDF;.了解更多: http://blogs .microsoft.co.il/gilf/2013/07/22/quick-tip-typescript-declare-keyword/

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/

这篇关于在TypeScript中找不到名称jsPdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆