简体   繁体   English

如何从HTML表创建PDF文档?

[英]How to create PDF document from HTML table?

I'm using AngularJS to get data from API and populate HTML table using ng-repeat . 我正在使用AngularJS从API获取数据并使用ng-repeat填充HTML表。

Table is populated from array containing JSON arrays with data (eg. vm.data = [{"x": 1, "y":2}, {"x": 1, "y":2}...]) 表是从包含带有数据的JSON数组的数组中填充的(例如vm.data = [{"x": 1, "y":2}, {"x": 1, "y":2}...])

HTML table is customized using external stylesheet file. HTML表是使用外部样式表文件定制的。

I want to create PDF file from that HTML table and possible div containing data about that table (like header). 我想从该HTML表和可能包含该表数据的div(例如标头)创建PDF文件。 Preferably I would like this done without jQuery, only using pure JS and AngularJS. 最好是我希望不使用jQuery而仅使用纯JS和AngularJS来完成此操作。 Also table in PDF should include stylesheet info (font, font-size, color, even child background...). PDF中的表格还应包含样式表信息(字体,字体大小,颜色,甚至是子背景...)。

One thing to notice that table have limited height, but it is scrollable on X axis (using overflow:auto). 需要注意的一点是,桌子的高度有限,但是可以在X轴上滚动(使用overflow:auto)。 I want table shown in PDF file to be full height. 我希望PDF文件中显示的表格全高。


Methods I tried: 我尝试过的方法:

jsPDF - not customizable for tables jsPDF-不可自定义表格
html-pfg ( https://www.npmjs.com/package/html-pdf ) - not customizable for tables/bad documentation html-pfg( https://www.npmjs.com/package/html-pdf )-不能为表格/错误的文档进行自定义
( Is there an Angular way of printing a div from a HTML page? ) - Hackish/Uses jQuery 是否存在从HTML页面打印div的Angular方法? )-Hackish / Use jQuery
( Print a div using javascript in angularJS single page application ) - Not applying CSS files 在angularJS单页应用程序中使用javascript打印div )-不应用CSS文件
( https://github.com/sayanee/angularjs-pdf ) - This is not plugin for creating pdf documents... https://github.com/sayanee/angularjs-pdf)-这不是用于创建pdf文档的插件...
pdfMake pdf制作
( Generate PDF from HTML using pdfMake in Angularjs ) - This is not working because only part of table is shown on page and it is scrollable. 在Angularjs中使用pdfMake从HTML生成PDF )-这不起作用,因为页面上仅显示表的一部分并且可以滚动。 I want full table in my PDF. 我想在PDF中显示完整表格。

I managed to create PDF reports that I needed. 我设法创建了所需的PDF报告。

Plugin I used is PDFmake and is definitely best I found, works so flawless. 我使用的插件是PDFmake,并且绝对是我发现的最好的插件,它的工作如此完美。

Only problem I had is that I wrongly included it and that's why it didn't worked first time. 我唯一的问题是我错误地包含了它,这就是为什么它第一次不起作用的原因。

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

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