Save Multiple Div’s into pdf using jsPDF

I am trying to save 2 div’s into one single pdf file, using, jsPDF. In … Read more Save Multiple Div’s into pdf using jsPDF

I am trying to save 2 div’s into one single pdf file, using, jsPDF. In this case, I’m using a react app.

<div>
  <div id="id1" style={{height: "100px", width:"2000px", backgroundColor: "red"}}>

  </div>

  <div id="id2" style={{height: "3000px", width:"2000px", backgroundColor: "aqua"}}>

  </div>
  <button onClick={(e) => saveDiv(e)}>Save Div</button>
</div>

Then I call my function:

const saveDiv = () => {

var doc = new jsPDF('l', 'pt', 'a4')

if (document.getElementById("id1")) {  
      doc.html(document.getElementById("id1"), {
          callback: (pdf) => {
              console.log(pdf);
              pdf.save("myPdf.pdf");
          },
      });        

}
}

With this I can save one div, but I don’t know how add a condition to save the second and export them together. If anyone could help I would really appreciate it

Source: React – Stack Overflow


Categories: NewsTags: , ,

Leave a Reply

Your email address will not be published. Required fields are marked *