codeigniter 使用JSPDF(JavaScript)PHP将PDF保存到特定文件夹

hfsqlsce  于 2022-12-07  发布在  Java
关注(0)|答案(1)|浏览(198)

我正在使用JSPDF将HTML转换为PDF,我想通过电子邮件发送它。为此,我需要将文件存储在文件夹中。但我无法将其存储在文件夹中,因为“pdf.save('filename.pdf')”没有给予路径选项。

function pdf_dowland (order_id)
{
    var contentWidth = $("#invoice_wrapper").width();
    var contentHeight = $("#invoice_wrapper").height();
    var topLeftMargin = 20;
    var pdfWidth = contentWidth + (topLeftMargin * 2);
    var pdfHeight = (pdfWidth * 1.5) + (topLeftMargin * 2);
    var canvasImageWidth = contentWidth;
    var canvasImageHeight = contentHeight;
    var totalPDFPages = Math.ceil(contentHeight / pdfHeight) - 1;

    var pdf_name = 'teklif_formu_'+order_id;

    html2canvas($("#invoice_wrapper")[0], {allowTaint: true}).then(function (canvas) {
        canvas.getContext('2d');
        var imgData = canvas.toDataURL("image/jpeg", 1.0);
        var pdf = new jsPDF('p', 'pt', [pdfWidth, pdfHeight]);
        pdf.addImage(imgData, 'JPG', topLeftMargin, topLeftMargin, canvasImageWidth, canvasImageHeight);

        for (var i = 1; i <= totalPDFPages; i++) {
            pdf.addPage(pdfWidth, pdfHeight);
            pdf.addImage(imgData, 'JPG', topLeftMargin, -(pdfHeight * i) + (topLeftMargin * 4), canvasImageWidth, canvasImageHeight);
        }
    
        pdf.save(pdf_name+".pdf");
    });
}
eulz3vhy

eulz3vhy1#

jspdf似乎不可能实现这一点,因为它使用FileSaver.js保存文件:https://github.com/eligrey/FileSaver.js/issues/42

相关问题