我正在使用jsPdf将我的网页保存为pdf
我正在使用meteor框架,这是我的代码
'click .button':function(e)
{
var doc = new jsPDF();
var source = $('#stackoverflow').first();
var specialElementHandlers = {
};
doc.fromHTML(
source, // HTML string or DOM elem ref.
0.5, // x coord
0.5, // y coord
{
'width': 7.5, // max width of content on PDF
'elementHandlers': specialElementHandlers
});
doc.output('dataurlnewwindow');
doc.save('test.pdf');
},
我的stackoverflow div
<div class="tab-pane" id="stackoverflow">
<a href="" class="button">Run Code</a>
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="text" id="stackurl" class="form-control" autocomplete="off" placeholder="Enter Your Stackoverflow ID">
</div>
<button type="submit" class="btn btn-default" id="getData">Get Data</button>
</form>
<br><br>
<hr>
{{> BasicDetails}}
<hr>
{{> UserQuestions}}
<hr>
{{> UserAnswers}}
</div>
对于doc.save('test.pdf'),错误是
saveas is not defined
我已将filesaver.js
添加到我的项目中,该项目加载了dom加载,仍然出现错误,我是否需要添加任何其他包blob.js
或downloadify.js
对于doc.output('dataurl')
在输出窗口中,我只得到“undefined
我从github下载了zip文件,并将以下文件添加到我的项目中
jspdf.js,
jspdf.plugin.from_html.js,
jspdf.plugin.split_text_to_size.js,
jspdf.plugin.standard_font_metrics.js
我的代码有什么问题?
更新:使用slavo解决方案我没有收到saveAs
错误,但我的数据仍未以pdf显示,它在pdf文件中显示undefined
。我的div包含图表,这是问题吗?
看起来jsPDF的插座有问题
答案 0 :(得分:1)
我也很困惑,试图将其连接起来,所以这是我在尝试让jsPDF在Meteor上工作时发现的。而不是使用这些文件:
jspdf.js,
jspdf.plugin.from_html.js,
jspdf.plugin.split_text_to_size.js,
jspdf.plugin.standard_font_metrics.js
找到以下两个并将它们放入“客户端/兼容性”文件夹中,如imslako建议的那样:
jspdf.min.js
jspdf.source.js
不知道这是否有助于您的图表错误,但它为我解决了saveAs
问题。