将html表格导出为pdf
Exporting html table to pdf
我的代码出了什么问题?我想把我的html表导出为pdf并保存。然后碰巧它只会打开空屏幕的新浏览器。这是我的示例代码。请帮忙。非常感谢。
<!DOCTYPE html>
<html>
</head>
<body>
<div id="pdf">
<table id="StudentInfoListTable">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Track</th>
<th>S.S.C Roll</th>
<th>S.S.C Division</th>
<th>H.S.C Roll</th>
<th>H.S.C Division</th>
<th>District</th>
</tr>
</thead>
<tbody>
<tr>
<td>alimon </td>
<td>Email</td>
<td>1</td>
<td>2222</td>
<td>as</td>
<td>3333</td>
<td>dd</td>
<td>33</td>
</tr>
</tbody>
</table>
</div>
<!--<button >Submit</button> -->
<li> <a href="javascript:PrintDiv()">Export to pdf</a> </li>
<script type="text/javascript">
function PrintDiv(htmlexportPDF) {
var divToPrint = document.getElementById(htmlexportPDF);
alert('Printing: Success');
var popupWin = window.open('', '_blank', 'width=650,height=600');
popupWin.document.open();
popupWin.document.write('<style type="text/css">body{ margin:0.5px;');
popupWin.document.write('font-family:verdana,Arial;color:#000;');
popupWin.document.write('font-family:Verdana, Geneva, sans-serif; font-size:8px;}');
popupWin.document.write('a{color:#000;text-decoration:none;}</style>');
popupWin.document.write('<html><body onload="window.print()">' + divToPrint.innerHTML + '</html>');
popupWin.document.close();
}
</script>
您的JavaScript函数printDiv接受参数htmlexportPDF。
函数PrintDiv(htmlexportPDF){
问题是,当您从<a>
链接调用PrintDiv时,您没有给出任何参数。
要解决此问题,请更改
<a href="javascript:PrintDiv()">Export to pdf</a>
至
<a href="javascript:PrintDiv('StudentInfoListTable')">Export to pdf</a>
此外,在您的HTML代码中,您从来没有放置一个开始的<head>
标记、一个结束的</body>
标记或一个关闭的</html>
标记。
相关文章:
- 如何使用javascript或html下载PDF格式的填写表单
- 在提交时打开thankyou.html+下载PDF
- 生成pdf或其他非html文件时的错误处理
- how to convert html <div> to pdf
- 如何在使用jsPDF将html转换为pdf的同时,在pdf中的某个点进行分页
- 如何将带有大量svg图表的html转换为pdf
- 将php页面的一个部分渲染为HTML和CSS后生成PDF,并考虑PDF分页符
- 如何使用javascript或jquery将整个html页面转换为pdf
- 如果iframe在src(pdf或text)中有非html文档,则iframe中的onload不起作用
- HTML表格导出为具有适当列宽和字体的pdf
- 具有可拖动元素的HTML到PDF
- c# mvc nreco HtmlToPdfConverter 问题将 html 文档转换为 pdf
- 来自HTML图像的jsPDF 会导致 pdf 为空
- 使用 php 将 pdf 文件转换为 html 文件
- HTML到PDF的转换仅在客户端使用JavaScript
- 从横向格式的HTML页面制作PDF
- 使用TableExport.js将HTML表格导出为PDF、WORD、PNG
- HTML和CSS转换为JavaScript中的PDF
- JQuery-HTML到PDF没有'无法在IE中工作(来自C#asmx Web服务)
- 保存样式'导出到pdf'html表