admin管理员组

文章数量:1345722

I need to print my html contet and text together, I tried with the below code, but the text that am added is not printing in the PDF. Its only print the html contents. Please help me to solve this issue....

    pdf = new jsPDF('l', 'mm', 'ledger'),
    specialElementHandlers = {
      '#editor': function( element, renderer ) {
          return true;
      }
};
pdf.fromHTML(
      $('#customers').get(0) // HTML element
    , 15  // x coord
    , 0.5  // y coord
    , {
          'width': 3000 // was 7.5, max width of content on PDF
        , elementHandlers: specialElementHandlers
    }
);
pdf.text(35, 25, "test");
pdf.save( filename ); 
}); 

I need to print my html contet and text together, I tried with the below code, but the text that am added is not printing in the PDF. Its only print the html contents. Please help me to solve this issue....

    pdf = new jsPDF('l', 'mm', 'ledger'),
    specialElementHandlers = {
      '#editor': function( element, renderer ) {
          return true;
      }
};
pdf.fromHTML(
      $('#customers').get(0) // HTML element
    , 15  // x coord
    , 0.5  // y coord
    , {
          'width': 3000 // was 7.5, max width of content on PDF
        , elementHandlers: specialElementHandlers
    }
);
pdf.text(35, 25, "test");
pdf.save( filename ); 
}); 
Share Improve this question asked Feb 10, 2015 at 11:31 Syam kumar KKSyam kumar KK 5542 gold badges6 silver badges32 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

you must use the full sintax of function:

doc.fromHTML(HTML, x, y, settings, callback, margins);

Using callback you can add a function that executes on fromHtml plete.

In your code:

pdf = new jsPDF('l', 'mm', 'ledger'),
    specialElementHandlers = {
      '#editor': function( element, renderer ) {
          return true;
      }
};
pdf.fromHTML(
      $('#customers').get(0) // HTML element
    , 15  // x coord
    , 0.5  // y coord
    , {
          'width': 3000 // was 7.5, max width of content on PDF
        , elementHandlers: specialElementHandlers
    },
    myfunc,
    {
        top : 25,
        bottom : 25
    }
);

function myfunc(){
    pdf.text(35, 25, "test");
    pdf.save( filename ); 
}

I think your missing the syntax here What you have done here pdf.text(35, 25, "test"); Instead use this: pdf.text("test",35, 25); (Where the 35 stands X axis an 25 stands Y axis in pdf document).

本文标签: javascriptHow can i create pdf with jspdf from html and textStack Overflow