嗨,我正在尝试将具有引导CSS类的JSP页面导出到PDF。我收到错误消息:对象不支持行中的属性或方法'table'
renderer.pdf.table(renderer.x, renderer.y, table2json.rows, table2json.headers, {
在jspdf.plugin.from_html.js中。我正在IE 10和11中进行尝试。
除了jquery,bootstrap类等之外,我的JSP中还包含jspdf.plugin.from_html.js,jspdf.js,split_text_to_size.js,standard_fonts_metrics.js,html2canvas.js,bluebird.min.js。
<link href="../bootstrap-3.3.7-dist/css/bootstrap-theme.min.css" rel='stylesheet' type='text/css' />
<script src="../jscripts/jsPDF-master/jsPDF-master/src/jspdf.js"> </script>
<script src="../jscripts/jsPDF-master/jsPDF-master/jspdf.plugin.from_html.js"> </script>
<script src="../jscripts/jsPDF-master/jsPDF-master/src/modules/split_text_to_size.js"> </script>
<script src="../jscripts/jsPDF-master/jsPDF-master/src/modules/standard_fonts_metrics.js"> </script>
<script src="../jscripts/html2canvas.js"> </script>
<script src="../jscripts/bluebird.min.js"> </script>
<script>
function demoFromHTML() {
/*var pdf = new jsPDF('p', 'pt', 'letter');
//pdf.canvas.height = 72 * 11;
//pdf.canvas.width = 72 * 8.5;
pdf.fromHTML(document.body);
pdf.save('test.pdf');*/
var pdf = new jsPDF('p', 'pt', 'letter');
// source can be HTML-formatted string, or a reference
// to an actual DOM element from which the text will be scraped.
source = $('body')[0];
// we support special element handlers. Register them with jQuery-style
// ID selector for either ID or node name. ("#iAmID", "div", "span" etc.)
// There is no support for any other type of selectors
// (class, of compound) at this time.
specialElementHandlers = {
// element with id of "bypass" - jQuery style selector
'#bypassme': function (element, renderer) {
// true = "handled elsewhere, bypass text extraction"
return true
}
};
margins = {
top: 80,
bottom: 60,
left: 40,
width: 522
};
// all coords and widths are in jsPDF instance's declared units
// 'inches' in this case
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) {
// dispose: object with X, Y of the last line add to the PDF
// this allow the insertion of new lines after html
pdf.save('Test.pdf');
}, margins
);
}
</script>
编辑:我按@ Deepak-MSFT的建议尝试了,还好它现在正在生成PDF(在IE 11中,它可以正常工作,不能在Chrome中工作,但是无论如何,我需要它仅在IE中工作)。但是现在表格渲染出现了问题。我的页面上有很多文本和一些表格,表格看起来很大并且表格文本重叠。我尝试使用jsPDF + html2canvas保留CSS样式,但无法正常工作(尽管控制台显示“完成的渲染”,但没有PDF)。解决方法是,将表格替换为html列表,现在我的PDF文本大小等可以,但是显示错误:
此页面上存在错误。 Acrobat可能无法正确显示页面。 >请与创建PDF文档的人联系以解决问题。
任何帮助将不胜感激。