[go: up one dir, main page]

0% found this document useful (0 votes)
20 views1 page

Console Code

The document contains a JavaScript code snippet that creates a PDF from images on a webpage using the jsPDF library. It checks for images with a 'blob' URL, draws them onto a canvas, converts them to JPEG format, and adds them to the PDF. Finally, it saves the generated PDF with the name 'BtapHDC3-4-5.pdf'.

Uploaded by

thymai.1510
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views1 page

Console Code

The document contains a JavaScript code snippet that creates a PDF from images on a webpage using the jsPDF library. It checks for images with a 'blob' URL, draws them onto a canvas, converts them to JPEG format, and adds them to the PDF. Finally, it saves the generated PDF with the name 'BtapHDC3-4-5.pdf'.

Uploaded by

thymai.1510
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

let uniqueScript = document.

createElement('script');
uniqueScript.onload = function () {
let pdf = new jsPDF();
let images = document.getElementsByTagName('img');
for (let i = 0; i < images.length; i++) {
let img = images[i];
if (!/^blob:/.test(img.src)) {
continue;
}
let canvas = document.createElement('canvas');
let context = canvas.getContext("2d");
canvas.width = img.width;
canvas.height = img.height;
context.drawImage(img, 0, 0, img.width, img.height);
let imgData = canvas.toDataURL("image/jpeg", 1.0);
pdf.addImage(imgData, 'JPEG', 0, 0);
pdf.addPage();
}
pdf.save("BtapHDC3-4-5.pdf");
};
uniqueScript.src =
'https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.min.js';
document.body.appendChild(uniqueScript);

You might also like