Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

angular jspdf

generatePdf() {
    const div = document.getElementById("html2Pdf");
    const options = {background: "white", height: div.clientHeight, width: div.clientWidth};

    html2canvas(div, options).then((canvas) => {
        //Initialize JSPDF
        let doc = new jsPDF("p", "mm", "a4");
        //Converting canvas to Image
        let imgData = canvas.toDataURL("image/PNG");
        //Add image Canvas to PDF
        doc.addImage(imgData, 'PNG', 20, 20);

        let pdfOutput = doc.output();
        // using ArrayBuffer will allow you to put image inside PDF
        let buffer = new ArrayBuffer(pdfOutput.length);
        let array = new Uint8Array(buffer);
        for (let i = 0; i < pdfOutput.length; i++) {
            array[i] = pdfOutput.charCodeAt(i);
        }

        //Name of pdf
        const fileName = "example.pdf";

        // Make file
        doc.save(fileName);

    });
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: if between two numbers javascript 
Javascript :: javascript regex reference 
Javascript :: javascript currency format 
Javascript :: sort strings javascript alphabetically 
Javascript :: yarn incompatible module node 
Javascript :: javascript remove array element 
Javascript :: run onclick function once 
Javascript :: install vue by CDN 
Javascript :: copy to clipboard reatjs 
Javascript :: ts node cannot use import statement outside a module 
Javascript :: vue 3 script setup dynamic component sample 
Javascript :: vue get if checkbox is checked 
Javascript :: js loop to array backwards 
Javascript :: how to assert element attributes in cypress 
Javascript :: javascript set input value by id 
Javascript :: js get selected option elemeng 
Javascript :: how make date object in jquery from custom date 
Javascript :: express req get json 
Javascript :: ejs display variable 
Javascript :: polling in js 
Javascript :: adding cypress to react project using npm 
Javascript :: react click outside 
Javascript :: jquery option not disabled 
Javascript :: js check if undefined 
Javascript :: puppeteer headless 
Javascript :: delete axios token 
Javascript :: how to get variable in local storage in javascript 
Javascript :: get odd elements of list javascript 
Javascript :: javascript vector 
Javascript :: mongoose findone exclude perticular field 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =