jsPDF 完成 Google 云端硬盘只读 PDF 文件下载导出

背景

https://www.savemyexams.co.uk

蜜汁刷题网站,会员几乎就是在抢钱
十分困难搞了个西席折扣,试卷资本还不能下载…
本要领适用于 Google Drive 被设置为 Read Only 的 PDF 文件的下载导出

代码

/* 
    Via https://codingcat.codes/2019/01/09/download-view-protected-pdf-google-drive-js-code/
    If the images are not complete, try zooming the page to get the full image.
    1. Open Developer Tools on separate window and choose the Console tab
    2. Paste the code below (and hit enter)
*/

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];
        if (!/^blob:/.test(img.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(document.title.split('.pdf - ')[0]+".pdf");
};
 
jspdf.src = 'https://cdn.bootcss.com/jspdf/1.5.3/jspdf.debug.js';
document.body.appendChild(jspdf);

↑ JavaScript 代码

注重

原代码来自 https://codingcat.codes/2019/…
翻开浏览器开发者东西(单窗口翻开)挑选 Console / 控制台
复制代码,回车实行
假如图片绘制不完整,尝试缩放浏览器页面

    原文作者:TonyHe
    原文地址: https://segmentfault.com/a/1190000019053619
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞