我正在尝试将表格图表保存为pdf并且它正在抛出错误。以下是我的代码:
<script type="text/javascript">
function getImgData(chartContainer) {
var chartArea = chartContainer.getElementsByTagName('svg')[0].parentNode;
var svg = chartArea.innerHTML;
var chartDoc = chartContainer.ownerDocument;
var canvas = chartDoc.createElement('canvas');
canvas.setAttribute('width', (chartArea.offsetWidth * 5));
canvas.setAttribute('height', (chartArea.offsetHeight * 5));
canvas.setAttribute(
'style',
'position: absolute; ' +
'top: ' + (-chartArea.offsetHeight * 2) + 'px;' +
'left: ' + (-chartArea.offsetWidth * 2) + 'px;');
chartDoc.body.appendChild(canvas);
canvg(canvas, svg);
var imgData = canvas.toDataURL('image/JPEG');
doc.addImage(imgData, "JPEG", 10,10, 210,100);
canvas.parentNode.removeChild(canvas);
return imgData;
}
$(document).ready(function() {
$('#pdfBtn').click(function () {
var chartContainer = document.getElementById('table_div');
var chartDoc = chartContainer.ownerDocument;
var img = chartDoc.createElement('img');
img.src = getImgData(chartContainer);
doc.save('NotionViz.pdf');
});
});
</script>
错误是:
未捕获的TypeError:无法读取未定义的属性“parentNode” getImgData (匿名功能) jQuery.event.dispatch elemData.handle
如何将数据表导出为pdf。非常感谢解决方案。