使用jsPDF将我网站中的一个Div导出为PDF格式的报告,但无法得到正确的格式

Using jsPDF to export a Div in my website into a PDF format report but can't get the right format

正如标题所说,我正在使用 jsPDF 导出我网站中的 div 部分以导出为 PDF 文档。

这些是我的代码

<script>
function exportToPDF() {
    var pdf = new jsPDF('l', 'pt', 'a4');
    // source can be HTML-formatted string, or a reference
    // to an actual DOM element from which the text will be scraped.
    source = $('#tab_cm')[0];

    // we support special element handlers. Register them with jQuery-style 
    // ID selector for either ID or node name. ("#iAmID", "div", "span" 
    etc.)
    // There is no support for any other type of selectors 
    // (class, of compound) at this time.
    specialElementHandlers = {
        // element with id of "bypass" - jQuery style selector
        '#bypassme': function (element, renderer) {
            // true = "handled elsewhere, bypass text extraction"
            return true
        }
    };
    margins = {
        top: 30,
        bottom: 60,
        left: 30,
        width: 500
    };
    // all coords and widths are in jsPDF instance's declared units
    // 'inches' in this case
    pdf.fromHTML(
        source, // HTML string or DOM elem ref.
        margins.left, // x coord
        margins.top, { // y coord
            'width': margins.width, // max width of content on PDF
            'elementHandlers': specialElementHandlers
        },

        function (dispose) {
            // dispose: object with X, Y of the last line add to the PDF 
            //          this allow the insertion of new lines after html
            pdf.save(pdfName);
        }, margins
    );
}
</script>

我的 Div 部分如下所示: https://drive.google.com/file/d/0B2mHDe7wmRSfU2Q0UjM4QV9Sc2c/view?usp=sharing

但是导出后是这样的 https://drive.google.com/file/d/0B2mHDe7wmRSfMndIVGZUQ2FHLW8/view?usp=sharing

如您所见,我不知道如何在导出的 PDF table 中正确对齐这些文本。

在此先感谢您的帮助!

jspdf 不支持 css,因此很难获得正确的格式。您可以制作 html 的图像,然后将其添加到 pdf 中。看到这个答案: