Привет! Я пытаюсь экспортировать страницу JSP с классами начальной загрузки CSS в PDF. Я получаю сообщение об ошибке: объект не поддерживает свойство или метод 'table', в строке
renderer.pdf.table(renderer.x, renderer.y, table2json.rows, table2json.headers, {
в jspdf.plugin.from_html.js. Я пытаюсь в IE 10 и 11.
Я включил в свой JSP jspdf.plugin.from_html.js, jspdf.js, split_text_to_size.js, standard_fonts_metrics.js, html2canvas.js, bluebird.min.js, кроме классов jquery, начальной загрузки и т. Д.
<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 документ, чтобы исправить проблему.
Любая помощь будет оценена.