我想将Meteor模板转换为PDF文件。我发现this package使用this library将HTML转换为PDF。 问题是......我不明白如何获取模板的HTML。我有一个测试模板(在Jade中):
template(name="test")
h1 Title 1
p Hello, world!
这些功能(根据教程):
var specialElementHandlers = {
'#bypassme': function(element, renderer)
{
return true;
}
};
Template.autotest_verdict_content.events({
"click #generate-pdf": function ()
{
var doc = new jsPDF('p', 'in', 'letter');
var source = $("#verdict-content").get(0); // I tried this (from a rendered template)
var source = Template.test; // And this (the template I want to transform)
doc.fromHTML(source, 0.5, 0.5,
{
'width': 7.5,
'elementHandlers': specialElementHandlers
});
doc.output('dataurl');
}
});
我只创建一个带有“未定义”字符串的PDF文件。我想我误解了模板是如何工作的......有人能解释一下吗?
答案 0 :(得分:2)
为什么你不能这样做(如包文档中所述):
Template.autotest_verdict_content.events({
"click #generate-pdf": function (){
Blaze.saveAsPDF(Template.test, {
filename: "test.pdf", // optional, default is "document.pdf"
x: 0, // optional, left starting position on resulting PDF, default is 4 units
y: 0, // optional, top starting position on resulting PDF, default is 4 units
unit: "in", // optional, unit for coordinates, one of "pt", "mm" (default), "cm", or "in"
format: "letter" // optional, see Page Formats, default is "a4",
elementHandlers: specialElementHandlers
});
}});