Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react js pdf generate from html

// Rendering react as pdf is generally a pain,
// but there is a way around it using canvas.

// The idea is to convert : HTML -> Canvas -> PNG (or JPEG) -> PDF
// To achieve the above, you'll need :

// npm install --save html2canvas
// npm install jspdf --save
...
printDocument() {
    const input = document.getElementById('divToPrint');
    html2canvas(input)
      .then((canvas) => {
        const imgData = canvas.toDataURL('image/png');
        const pdf = new jsPDF();
        pdf.addImage(imgData, 'JPEG', 0, 0);
        // pdf.output('dataurlnewwindow');
        pdf.save("download.pdf");
      })
    ;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery id value input 
Javascript :: react conditional class 
Javascript :: Contact form tutorial next.js 
Javascript :: js jquery include external script 
Javascript :: select li element with arrow keys (up and down) using javascript 
Javascript :: array.from javascript 
Javascript :: create react expo 
Javascript :: nodemailer send email 
Javascript :: react build command 
Javascript :: react router base url 
Javascript :: check array values equal js 
Javascript :: react native build android 
Javascript :: remove duplicates from array in javascript 
Javascript :: react native vector icon 
Javascript :: angularjs dropdown 
Javascript :: js count char frequency in string 
Javascript :: use svg image in next js 
Javascript :: jquery select dropdown 
Javascript :: javascript array split empty string 
Javascript :: js array.prototype.join 
Javascript :: use effect react 
Javascript :: reverse a string in javascript 
Javascript :: Divide the number in js 
Javascript :: get list of all attributes jqery 
Javascript :: how to print console in javascript 
Javascript :: async await promise all javascript 
Javascript :: sort array of objects javascript by key value 
Javascript :: react select and react hook form 
Javascript :: going through every attributes of an object javascript 
Javascript :: mongodb mongoose match by ids 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =