使用javascript将HTML表转换为pdf
HTML table to pdf using javascript
我创建了一个应用程序,用于使用我使用的jsPDF插件将html表下载到pdf。应用程序运行良好,但问题是表不正确。表格的宽度和标题没有正确对齐。我正在使用angularjs创建表格。
有人能为这个问题给我一些建议吗?
JSFiddle
function demoFromHTML() {
var pdf = new jsPDF('p', 'pt', 'letter');
source = $('#customers')[0];
specialElementHandlers = {
'#bypassme': function (element, renderer) {
return true
}
};
margins = {
top: 4,
bottom: 4,
left: 4,
width: 522
};
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) {
pdf.save('Test.pdf');
}, margins);
}
我想你现在必须手动(fiddle):
function demoFromHTML() {
var pdf = new jsPDF('p', 'pt', 'letter');
pdf.cellInitialize();
pdf.setFontSize(10);
$.each( $('#customers tr'), function (i, row){
$.each( $(row).find("td, th"), function(j, cell){
var txt = $(cell).text().trim() || " ";
var width = (j==4) ? 40 : 70; //make 4th column smaller
pdf.cell(10, 50, width, 30, txt, i);
});
});
pdf.save('sample-file.pdf');
}
尝试"jspdf"而不是"jspdf"
相关文章:
- 将画布转换为pdf:黑色背景
- 如何在不在本地下载的情况下将url中提供的文件(pdf/doc)转换为json/string/base64格式
- 将网页转换为具有样式的pdf
- 如何在使用jsPDF将html转换为pdf的同时,在pdf中的某个点进行分页
- 如何将带有大量svg图表的html转换为pdf
- PDF到JPG的转换器
- 如何使用javascript或jquery将整个html页面转换为pdf
- c# mvc nreco HtmlToPdfConverter 问题将 html 文档转换为 pdf
- 使用 php 将 pdf 文件转换为 html 文件
- HTML到PDF的转换仅在客户端使用JavaScript
- 我们如何将URL的PDF转换为convert.javascript中的ToBase64String
- 将数据库中的数据转换为可下载的PDF文件
- HTML和CSS转换为JavaScript中的PDF
- 将Markdown文件转换为PDF,同时剥离Jekyll Front Matter
- 谷歌应用程序脚本:将文本文档转换为PDF的代码
- 谷歌应用程序将电子邮件表单脚本转换为PDF格式,但希望清除一些单元格
- Java使用css+js将html转换为pdf
- 如何使用javascript将Html页面转换为PDF
- 如何使用pdfmake将html表格转换为pdf
- JSPDF添加黑色背景转换PDF