1

I need to make a PDF file put of rendered with data html Blaze Template.

I need it to support utf-8, because im using some hebrew charcters, so most of the packages I tried doesn't fit the job.

I tried using jsPDF and addHTML libraries with jspdf:core package, and I added html2canvas.js file to my compatibility folder on the client folder (at the demo I paste the file to common.js).

Meteor Pad as demo : http://meteorpad.com/pad/g5GBn8TRrNHxYJ9ip/Leaderboard%20to%20html

My problem is that the callback function of addHTML is never executed (line 20 on client/app.js at the demo):

var html = Blaze.toHTMLWithData(Template.filledform, {'text' : 'יום אחד, בא אלי בחור ואמר לי:'}),
    pdf = new jsPDF('p','pt','a4'),
    options = {
      proxy: Meteor.absoluteUrl()
    },
    pdf = new jsPDF('p', 'pt', 'a4');
pdf.addHTML(html, options, function() {
  console.log("callBack");
  return pdf.output('datauri');
});

I also tried:

var href = '',
html = Blaze.toHTMLWithData(Template.filledform, {'text' : 'יום אחד, בא אלי בחור ואמר לי:'}),
pdf = new jsPDF('p','pt','a4'),
options = {
    proxy: Meteor.absoluteUrl()
};
pdf.addHTML(html, options, function() {
  return href = pdf.output('datauristring');
}).then(function(a) {
  console.log(a);
  console.log(href);
  return location.href = href;
});

but the href value never changed.

mkj
  • 2,761
  • 5
  • 24
  • 28
Amit Rahav
  • 115
  • 1
  • 15
  • I haven't used this myself, but notice that `Blaze.toHTMLWithData` returns a `string`. The `addHTML` method requires an `object` as the first argument. - http://stackoverflow.com/questions/28193487/how-to-use-addhtml-function-in-jspdf - the reason your callback isn't running is probably because `addHTML` encounter an error and isn't firing the callback for whatever reason. – fuzzybabybunny Jun 30 '15 at 02:10
  • Is the user already on the page that you want to export as a PDF document? If they are, it seems to me that you don't have to do anything with `Blaze`. Just directly pass `addHTML` the DOM node of the section of the page that you want converted to PDF using jQuery or `document.someElement`. – fuzzybabybunny Jun 30 '15 at 02:16

0 Answers0