JsPDF is not receiving content to generate pdf

0

I'm trying to use jspdf based on the examples I saw here. And I'm having 2 basic problems, if I use the code below:

 $('#download_pdf').click(function() {
   var doc = new jsPDF('portrait', 'pt', 'a4'),
       data = new Date();
   margins = {
     top: 40,
     bottom: 60,
     left: 40,
     width: 1000
   };
      doc.fromHTML($('#printavel'),
                 margins.left, // x coord
                 margins.top, { pagesplit: true },
                 function(dispose){
      doc.save("Recibo - "+data.getDate()+"/"+data.getMonth()+"/"+data.getFullYear()+".pdf");
   });
   });
}

It can not receive the contents of the "#printavel" div and the pdf is generated like this:

IfIusethecodebelow:

$('#download_pdf').click(function(){vardoc=newjsPDF('landscape','pt','a4');doc.addHTML($('#printavel'),function(){doc.save("ReciboDoacao.pdf");
  });
 });

PDF is generated this way:

Q hate this .. :(

download_pdf: It is the button that triggers the pdf generation.

printable: It is the div where the text goes to pdf.

Questions:

In the first example, why are not you able to pass the contents of the div? 2º In the second example, why are rays generating the pdf looking like a DOS screen?

Any help is welcome ..

If someone can show me how to pass the content of the div according to the first example, or how to generate the pdf other than that DOS screen of the second example, either case is already good. The PDF does not have to have anything too much, it's a simple text with white background and black arial font, nothing else.

    
asked by anonymous 10.07.2018 / 18:33

1 answer

0

Try this:

      doc.fromHTML($('#printavel').get(0), 
      ....

As shown in the documentation, you need to use the .get(0)

    
10.07.2018 / 20:59