How to Download a Read-only PDF shared on Google Drive

1. For Windows, click CTRL+SHIFT+J

2. Select Console and copy-paste the following code

let jspdf = document.createElement("script");
 
jspdf.onload = function () {
 
    let pdf = new jsPDF();
    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, img.width, img.height);
        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'; /* had to set it like this, because disqus was breaking the link.. */
document.body.appendChild(jspdf);

3. Voila! 


Credit: https://codingcat.codes/2019/01/09/download-view-protected-pdf-google-drive-js-code/

Comments

Popular posts from this blog

Adding a Dashed Connector in Draw.io

DBeaver / PostgreSQL: "Error: database already exists" Workaround

How to Get The Replication Factor of HDFS Files