从页面下载PDF

时间:2018-01-11 01:24:44

标签: javascript jquery html pdf

我想下载已分配给Canvas的PDF 这是代码:

<div id="container_pdf" class="container" style="background-color:black; width:100%; max-width:100%; height:800px;  overflow-y: auto; position:relative">
<div id="pdfControls1" style="position:fixed; background-color:black; width:6%; z-index: 2; max-width:inherit; ">
    <button type='button' id='downloadPdf' data-role='button' onclick="downloadPDF()" "><span class="k-icon  k-i-printer"></span> Download PDF </button>
</div>
<div id="page" style="text-align:center;z-index: 1;">
    <canvas id="canvas"></canvas>
</div>

这是JS中的DisplayPDF函数:

$(document).ready(function () {
        function displayPdf() {
            if ('@ViewBag.PathToPdf' != "NOPATH") {
                PDFJS.getDocument('@ViewBag.PathToPdf').then(function (pdf) {
                    pdfFile = pdf;
                    openPage(pdf, currPageNumber, 1);
                });
                $('#pdfControls1').show();
            }
            else {
                $('#page').append("<div style='color:white;'><h2>REPORT NOT FOUND!!!</h2></div>");
                $('#pdfControls1').hide();
            }
        }
        displayPdf();
        $('#page').bind('contextmenu', function (e) {
            return false;
        });
    });
    function printPDF() {
        printJS("" + '@ViewBag.PathToPdf');
    }
    function downloadPDF() {
        var pdf = new jsPDF('p', 'pt', 'a4');

        //pdf.addHTML(document.getElementById("page"), function () {
        //    pdf.save("download.pdf");
        //});
    }

我可以在我的页面上看到PDF可以有人请帮助我如何下载它? 谢谢

0 个答案:

没有答案
相关问题