JS JQUERY JSPDF how to download images and input values from BLOB object as PDF

Im able to convert my HTML code to BLOB object as PDF. var that = … Read more JS JQUERY JSPDF how to download images and input values from BLOB object as PDF

Im able to convert my HTML code to BLOB object as PDF.

    var that = this;
            var doc = new jsPDF('p', 'pt', 'a4');
            var htmlString = 
                '<div class="container"> <img src="base64image" alt="Image"> <input value="testing"><p> Paragraph</p> <label class="bold" for="fname">Vehicle</label></div>';

            doc.fromHTML(htmlString, 20, 20, {},
                function (bla) {
                    doc.save('saveDOC.pdf'); // After downloading PDF i can see image and Label. But i cant see my input values.
                },0);

        // Below code is to convert HTML into Blob as PDF

         var blob = new Blob([doc.output("blob")], {
                type: "application/pdf"
            });

In the above code variable htmlString contains <img/> , <input/>, <label/>. When i try to download the BLOB object as PDF, Im getting blank PDF. But when i remove <img/> , <input/> then im able to view the content in BLOB object PDF.

Below is the code for converting BLOB as PDF..

const downloadFile = (blob, fileName) => {
            const link = document.createElement('a');
            link.href = URL.createObjectURL(blob);
            link.download = fileName;
            document.body.append(link);
            link.click();
            link.remove();
            setTimeout(() => URL.revokeObjectURL(link.href), 7000);
        };
        downloadFile(new Blob([doc.output("blob")]), "document.pdf");

How to get images and input values in downloaded PDF from BLOB object . Can someone please help me?

Thank you in advance.

Source: JavaSript – Stack Overflow


Categories: NewsTags: , ,

Leave a Reply

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