-
-
Save raven-kus/5c966f751b515c24f8188c21ff2aef58 to your computer and use it in GitHub Desktop.
How to download view only protected PDF from Google Drive (JS code)?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://codingcat.codes/2019/01/09/download-view-protected-pdf-google-drive-js-code/ | |
// https://www.linkedin.com/in/ronnie-joshua/ | |
// 1. Open the presentation | |
// 2. Click three times on zoom to enlarge the presentation | |
// 3. Scroll down slowly to the last page [Let the entire document load that's the idea] | |
// 4. Then go to the developer console and run this script | |
// 5. Check the results. if not okay then adjust width and length line of the code | |
// Landscape PDF | |
// With 3 clicks on Zoom | |
let jspdf = document.createElement("script"); | |
jspdf.onload = function () { | |
// [297 * 3.75, 210 * 3] [Width * Length] | |
let pdf = new jsPDF('l', 'mm', [297 * 3.75, 210 * 3]); | |
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("exported_file.pdf"); | |
}; | |
jspdf.src = 'https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.debug.js'; | |
document.body.appendChild(jspdf); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment