Skip to main content

Converts any webpage or element into a printable PDF entirely client-side, using html2canvas and jsPDF.

// If you're on a webpage that you can't modify directly and wish to use
// html2pdf.js to capture a screenshot, you can follow these steps:
//
// 1. Open your browser's console (instructions for different browsers here https://webmasters.stackexchange.com/a/77337/94367).
//
// 2. Paste in this code:
function loadScript(url, callback) {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.charset = "utf-8";

    script.onload = script.onreadystatechange = function() {
        var state = this.readyState;
        if (!state || /loaded|complete/.test(state)) {
            script.onload = script.onreadystatechange = null;
            callback();
        }
    };

    script.src = url;
    document.body.appendChild(script);

    return script;
}

loadScript("https://raw.githack.com/eKoopmans/html2pdf/master/dist/html2pdf.bundle.js",
    function() {
        html2pdf(document.body);
    }
);
// NOTE: "raw.githack.com" serves raw files directly from GitHub, Bitbucket or
// GitLab with proper Content-Type headers. More at https://raw.githack.com.