1

I'm using jsPDF to convert html to pdf. When a page has a lot of text I just got a blank pdf or a gray page with no contentsanf data: in url

I have no errors in console.

How can I make it print pdf correctly?

To convert to pdf I use this code:

     $(document).ready(function(){
     var specialElementHandlers = {
         '#editor': function (element,renderer) {
             return true;
         }
     };
     $('#topdf').click(function () {

      var doc = new jsPDF();

      var specialElementHandlers = {
        '#editor': function(element, renderer){
            return true;
        }
      };

      doc.fromHTML($('.post-content p').get(0), 15, 15, {
        'width': 170, 
        'elementHandlers': specialElementHandlers
      });

       doc.output("dataurlnewwindow");
     });
 });
kirqe
  • 2,431
  • 4
  • 37
  • 63

1 Answers1

1

The problem is in length of URL limit 2000 chars (more here: What is the maximum length of a URL in different browsers?), so I suggest you to use doc.output('save', 'filename.pdf') but this have limitation (more: How to open generated pdf using jspdf in new window)

Community
  • 1
  • 1
Piotr Stapp
  • 19,392
  • 11
  • 68
  • 116
  • But it this case text becomes a little ugly. If I use regular print as pdf from a browser text looks better. – kirqe May 13 '15 at 16:05