使用 Javascript 创建带表格的 PDF

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21305661/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 20:37:14  来源:igfitidea点击:

Create PDF with Table using Javascript

javascriptpdfcordovadocumentation-generationjspdf

提问by user2706035

I'm currently creating a phonegap app that lets you input Data and then creates a PDF with that data. The Input is done, but I can't find anything to make a PDF with Javascript. So far I only found jsPDF, but that doesn't support tables. The App must work offline. Does someone have an Idea?

我目前正在创建一个 phonegap 应用程序,让您输入数据,然后使用该数据创建 PDF。输入已完成,但我找不到任何可以使用 Javascript 制作 PDF 的内容。到目前为止,我只找到了 jsPDF,但它不支持表格。该应用程序必须离线工作。有人有想法吗?

采纳答案by roland

Bytescout PDF Generator SDK for Javascriptmight come in handy: http://bytescout.com/products/developer/pdfgeneratorsdkjs/index.html

用于 Javascript 的 Bytescout PDF Generator SDK可能会派上用场:http: //bytescout.com/products/developer/pdfgeneratorsdkjs/index.html

Ensure that browser inconsistencies for your targeted devices are taken into account.

确保将目标设备的浏览器不一致考虑在内。

回答by Simon Bengtsson

I wanted to use jsPDF to generate tables so I made a table plugin for it. Check it out! jspdf-autotableIt has all the features I was looking for in a table plugin.

我想使用 jsPDF 来生成表格,所以我为它制作了一个表格插件。看看这个!jspdf-autotable它具有我在表格插件中寻找的所有功能。

  • Auto width (100% of page width or only as much as required)
  • Multiple pages
  • Custom headers and footers
  • Multiple tables on the same page
  • Custom styling
  • Examples
  • 自动宽度(页面宽度的 100% 或仅根据需要)
  • 多页
  • 自定义页眉和页脚
  • 同一页面上的多个表
  • 自定义样式
  • 例子

enter image description here

在此处输入图片说明

回答by Ashish Lahoti

jsPDF provide good support for tables using jsPDF-AutoTableplugin.

jsPDF 为使用jsPDF-AutoTable插件的表格提供了良好的支持。

jsPDF and pdfmake are two javascript libraries widely used to generate pdf. I have used both and would like to share few points i observed:

jsPDF 和 pdfmake 是两个广泛用于生成 pdf 的 javascript 库。我已经使用了两者,并想分享我观察到的几点:

jsPDF

jsPDF

  1. Performance is really good. I would able to generate PDF of 2000 pages in 5-6 seconds.
  2. It doesn't support utf-8 format i.e. you won't be able to render pdf in chinese, turkish and other languages.
  3. It doesn't support row break and table inside table.
  1. 性能真的很好。我将能够在 5-6 秒内生成 2000 页的 PDF。
  2. 它不支持 utf-8 格式,即您将无法以中文、土耳其语和其他语言呈现 pdf。
  3. 它不支持换行和表内表。

pdfmake

制作

  1. Performace is good if you are generating pdf of less than 40 pages. Performance degrade exponentially if you generate larged pdf. Almost kill the browser.
  2. Support utf-8 format.
  3. Support row break and table inside table.
  4. Easy to use.
  1. 如果您生成的 pdf 少于 40 页,则性能很好。如果生成大的 pdf,性能会呈指数级下降。差点杀了浏览器。
  2. 支持utf-8格式。
  3. 支持换行和表内表。
  4. 使用方便。

You can make wise decision based on your requirement.

您可以根据自己的要求做出明智的决定。

回答by bartekp

pdfmakelet's you easily create tables.

pdfmake让您轻松创建表格。

It can automatically repeat headers, supports column/row spans and comes with a lot of other options.

它可以自动重复标题,支持列/行跨度并带有许多其他选项。

There's an example for tables in the playground

操场上有一个桌子的例子