Jspdf not receiving content to generate pdf

Asked

Viewed 443 times

0

I am trying to use jspdf based on the examples I have seen here. And I am 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 cannot receive the contents of the div "#printavel" and the pdf is generated like this:

inserir a descrição da imagem aqui

If I use the code below:

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

The pdf is generated this way:

inserir a descrição da imagem aqui

I hate that.. :(

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

printavel: It is the div where ta text that goes pro pdf.

Questions:

First up, why can’t I get the contents of the div through? 2º In the second example, why are the 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 without being that DOS screen of the second example, any of the case already serves. The pdf doesn’t have to have anything else, it’s a simple text with white background and black Arial font, nothing more.

  • I put a video showing the error: http://softarena.ml/erro.mp4. No problem to display the card number pq is just a test card

1 answer

0

Try it like this:

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

As shown in the documentation, it is necessary to use the method .get(0)

  • Not going, using the console I get the following message using this way: SCRIPT438: Object doesn’t support Property or method 'getelementsbytagname' html2canvas.min.js (6,30265)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.