数据表PDF导出不完整

时间:2017-08-21 12:56:07

标签: javascript jquery datatables

我有一个简单的html表。分页已关闭,因此页面上显示的所有50行左右。 excel出口效果很好。 PDF导出仅显示1页,约占内容的三分之一。是否有一种导出所有行的简单方法?即使分页设置为true,导出仍然不完整。做了一些研究之后,我应该做些什么。我只是无法弄清楚为什么它失败并只导出一页。

[("GCC extra via C opts", "@GccExtraViaCOpts@"),
 ("C compiler command", "@SettingsCCompilerCommand@"),
 ("C compiler flags", "@SettingsCCompilerFlags@"),
 ("C compiler link flags", "@SettingsCCompilerLinkFlags@"),
 ("C compiler supports -no-pie", "@SettingsCCompilerSupportsNoPie@"),
 ("Haskell CPP command","@SettingsHaskellCPPCommand@"),
 ("Haskell CPP flags","@SettingsHaskellCPPFlags@"),
 ("ld command", "@SettingsLdCommand@"),
 ("ld flags", "@SettingsLdFlags@"),
 ("ld supports compact unwind", "@LdHasNoCompactUnwind@"),
 ("ld supports build-id", "@LdHasBuildId@"),
 ("ld supports filelist", "@LdHasFilelist@"),
 ("ld is GNU ld", "@LdIsGNULd@"),
 ("ar command", "@SettingsArCommand@"),
 ("ar flags", "@ArArgs@"),
 ("ar supports at file", "@ArSupportsAtFile@"),
 ("touch command", "@SettingsTouchCommand@"),
 ("dllwrap command", "@SettingsDllWrapCommand@"),
 ("windres command", "@SettingsWindresCommand@"),
 ("libtool command", "@SettingsLibtoolCommand@"),
 ("perl command", "@SettingsPerlCommand@"),
 ("cross compiling", "@CrossCompiling@"),
 ("target os", "@HaskellTargetOs@"),
 ("target arch", "@HaskellTargetArch@"),
 ("target word size", "@WordSize@"),
 ("target has GNU nonexec stack", "@HaskellHaveGnuNonexecStack@"),
 ("target has .ident directive", "@HaskellHaveIdentDirective@"),
 ("target has subsections via symbols", "@HaskellHaveSubsectionsViaSymbols@"),
 ("Unregisterised", "@Unregisterised@"),
 ("LLVM llc command", "@SettingsLlcCommand@"),
 ("LLVM opt command", "@SettingsOptCommand@")
 ]

html具有这种结构

<script>

$(document).ready(function() {
$('#summary_table').DataTable( {
    dom: 'Bfrtip',
    buttons: [
        'excelHtml5',
                    {
            extend: 'pdfHtml5',
            orientation: 'landscape',
            pageSize:'LEGAL'
        }
    ],
paging:false

} );
  } );

</script>

3 个答案:

答案 0 :(得分:0)

我不知道你所包含的js和css。你可以试试这个。这是working demo

<table id="example" class="display nowrap" cellspacing="0" width="100%">
      <thead>
        <tr>
          <th>Name</th>
          <th>Position</th>
          <th>Office</th>
          <th>Age</th>
          <th>Start date</th>
          <th>Salary</th>
        </tr>
      </thead>

      <tbody>
        <tr>
          <td>Tiger Nixon</td>
          <td>System Architect</td>
          <td>Edinburgh</td>
          <td>61</td>
          <td>2011/04/25</td>
          <td>$320,800</td>
        </tr>

      </tbody>
</table>
$(document).ready(function() {
    $('#example').DataTable( {
        dom: 'Bfrtip',
        buttons: [
            'copyHtml5',
            'excelHtml5',
            'csvHtml5',
            'pdfHtml5'
        ],
        paging: false
    } );
} );

并且不要忘记包含这些文件

  

https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js   https://cdn.datatables.net/buttons/1.4.0/js/dataTables.buttons.min.js   //cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js   //cdn.rawgit.com/bpampuch/pdfmake/0.1.27/build/pdfmake.min.js   //cdn.rawgit.com/bpampuch/pdfmake/0.1.27/build/vfs_fonts.js   //cdn.datatables.net/buttons/1.4.0/js/buttons.html5.min.js   https://cdn.datatables.net/1.10.15/css/jquery.dataTables.min.css   https://cdn.datatables.net/buttons/1.4.0/css/buttons.dataTables.min.css

答案 1 :(得分:0)

datatables网站的示例包含以下pdfmake CDN

<script src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.27/build/pdfmake.min.js"></script>
<script src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.27/build/vfs_fonts.js"></script>

我从我的代码中删除了上述内容,而是通过cdnjs替换为0.1.32版本。 PDF按钮现在可以完全导出所有页面!

<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/pdfmake.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/vfs_fonts.js"></script>

答案 2 :(得分:-1)

导出前设置页面设​​置。

protected void btnSubmit_Click(object sender, EventArgs e)
        {       
            WebClient wc = new WebClient();
            string url = Request.Url.AbsoluteUri;
            string fileContent = wc.DownloadString(url); 
            List<string> tableContents = GetContents(fileContent, table_pattern);
            string HTMLString = String.Join(" ", tableContents.ToArray());   
            Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
            PdfWriter.GetInstance(pdfDoc, Response.OutputStream);             
            pdfDoc.Open();
            pdfDoc.Add(new Paragraph("Welcome to dotnetfox"));
            List<IElement> htmlarraylist = HTMLWorker.ParseToList(new StringReader(HTMLString), null);
            for (int k = 0; k < htmlarraylist.Count; k++)
            {
                pdfDoc.Add((IElement)htmlarraylist[k]);
            } 
            pdfDoc.Close();
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;" +
                                           "filename=sample.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Write(pdfDoc);
            Response.End();       
        }   
    }