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

Script To Download The View Only PDF

This script allows downloading protected or view-only PDF files by extracting images from a web page and adding them to a new PDF document created with jsPDF. It gets all image elements from the page, draws each one to a canvas to extract the image data, adds that image to the new PDF, and saves the resulting file as "download.pdf".

Uploaded by

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

Script To Download The View Only PDF

This script allows downloading protected or view-only PDF files by extracting images from a web page and adding them to a new PDF document created with jsPDF. It gets all image elements from the page, draws each one to a canvas to extract the image data, adds that image to the new PDF, and saves the resulting file as "download.pdf".

Uploaded by

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

Script To Download The View Only/Protected PDF Files :-

let jspdf = document.createElement("script");

jspdf.onload = function () {

let pdf = new jsPDF('p', 'mm', [1000, 625]);


let elements = document.getElementsByTagName("img");
for (let i in elements) {
let img = elements[i];
console.log("add img ", img);
if (!/^blob:/.test(img.src)) {
console.log("invalid src");
continue;
}
let can = document.createElement('canvas');
let con = can.getContext("2d");
can.width = img.width;
can.height = img.height;
con.drawImage(img, 0, 0);
let imgData = can.toDataURL("image/jpeg", 1.0);
pdf.addImage(imgData, 'JPEG', 0, 0);
pdf.addPage();
}

pdf.save("download.pdf");
};

jspdf.src = 'https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.debug.js';
document.body.appendChild(jspdf);

You might also like