Reputation: 780
I want to transform a Meteor template into a PDF file. I found this package using this library that transform HTML into PDF. The problem is... I don't understand how to get the HTML of my template. I have for the example a test template (in Jade) :
template(name="test")
h1 Title 1
p Hello, world!
And these functions (according to the tutorial) :
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');
}
});
I only create a PDF file with "undefined" string in it. I think I misunderstood how Template works... Can someone explain it to me ?
Upvotes: 2
Views: 1240
Reputation: 573
Why can't you do sth like this (as stated in package docs):
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
});
}});
Upvotes: 2