简体   繁体   English

Colspan 和 Rowspan 使用 JSPDF AutoTable 示例

[英]Colspan and Rowspan using JSPDF AutoTable Example

I'm new to jsPDF and I'm using jsPDF AutoTable ( https://github.com/simonbengtsson/jsPDF-AutoTable ).我是 jsPDF 的新手,我正在使用 jsPDF AutoTable ( https://github.com/simonbengtsson/jsPDF-AutoTable )。 I have multiple table Headers with Rowspan and Colspan in my table with sub-rows.我的表格中有多个带有 Rowspan 和 Colspan 的表格标题,其中包含子行。 When I run JSPDF with AUTOTABLE as ' False ' it prints the complete table on A4 but its compact and half the page which is not as expected.当我使用 AUTOTABLE 作为 ' False ' 运行 JSPDF 时,它会在 A4 上打印完整的表格,但它的紧凑性和一半的页面并不如预期。 It should print completely on A4 Page with width as table and on multiple pages with header as Date and Footer as Page No's.它应该完全打印在 A4 页面上,宽度为表格,并在多页上打印,日期为 header,页脚为页码。

Here is the JSFiddle for the issue.这是该问题的JSFiddle

Here is what I tried:这是我尝试过的:

//script to download as PDF 
 $('#reportpdf').click(function(){
    var children = $('#report tr.child').length;
    var visibleChildren = $('#report tr.child:visible').length;
       $('#report tr.child').show();
    var divToPrint=document.getElementById("report");   
            $('#report').tableExport({type:'pdf',
                                        fileName: 'Org_Status_Report',
                      jspdf: {orientation: 'p',
                       format: 'a4',
                               margins: {left:20, top:10},
                               autotable: false}
                      });
                  $('#report tr.child').hide();
                            });

Here is what the output I am getting:这是我得到的 output :

Output A4 Page-One First-half Output A4 Page-One 上半年

Output A4 Page-One Second-half Output A4第1页下半场

When I used AutoTable, the table is printed without the table header ie, the 1st two headers are missing.当我使用 AutoTable 时,打印的表格没有 header 表格,即缺少第一个两个标题。 I dont know where is the issue in my code.我不知道我的代码中的问题在哪里。 Tried every example mentioned in Demo and Code尝试了演示代码中提到的每个示例

Here is the code with AutoTable:下面是 AutoTable 的代码:

$('#reportpdf').click(function(){
    var children = $('#report tr.child').length;
    var visibleChildren = $('#report tr.child:visible').length;
        $('#report tr.child').show();
    var divToPrint=document.getElementById("report");
        $('#report').tableExport({type:'pdf',
                         fileName: 'Org_Status_Report',
                         //ignoreColumn: [4],
                       jspdf: {orientation: 'p',
                               format: 'a4',
                               margins: {left:20, top:20, botton:20, right:20},
                                autotable: {
                                      styles: {cellPadding: 2,
                                      fillColor: 'inherit',
                                      textColor: 'inherit',
                                      fontStyle: 'normal',
                                      overflow: 'ellipsize',
                                      halign: 'inherit',
                                      valign: 'middle'},
                              headerStyles: {
                                            halign: 'inherit',
                                            valign: 'middle'},
                              alternateRowStyles: {fillColor: 245}
                                }
                      }
        });
                              $('#report tr.child').hide();
                });

Here is what the output I am getting when I used Autotable:这是我使用 Autotable 时得到的 output:

Output as complete A4 Page using AutoTable Output 作为完整的 A4 页面使用 AutoTable

Can any experts help?有专家可以帮忙吗?

I've used JSPDF to fill a PDF form.我使用 JSPDF 填写了 PDF 表格。 I have an idea, might work, might not.我有一个想法,可能会奏效,也可能不会。

Print your form to PDF/then convert that to a base 64 image and paste the code manually into your JS.将您的表单打印为 PDF/然后将其转换为 base 64 图像并将代码手动粘贴到您的 JS 中。 Then use X,Y axes to place the data where you want it on the base 64 image.然后使用 X、Y 轴将数据放置在 base 64 图像上您想要的位置。 it might be a pain but it will work after some adjustments.这可能会很痛苦,但经过一些调整后它会起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM