gpt4 book ai didi

jspdf - 如何使用 jsPDF 获取 PDF 中的表格行图像?

转载 作者:行者123 更新时间:2023-12-03 23:15:10 29 4
gpt4 key购买 nike

我有一个带图像的 html 表。当我尝试转换为 PDF 时,只有数据来了。图像未以 PDF 格式显示。

如何获取pdf格式的表格td图片?

enter image description here

契约(Contract)标题包含复选框图像。但不是以 pdf 格式提供吗?

我的pdf代码:

function fnExportDIVToPDF() {

var pdf = new jsPDF('l', 'pt', 'a2');
pdf.setFontSize(8);
source = $('#divReport')[0];
specialElementHandlers = {
'#bypassme': function (element, renderer) {
return true
}
};
margins = {
top: 30, bottom: 40, left: 10, width: 1300};

pdf.fromHTML(
source, margins.left, margins.top, {
'elementHandlers': specialElementHandlers},

function (dispose) {

pdf.save('Report.pdf');
}
, margins);
}

分区:

<div id="divReport">

<div width="100%">
<p><span id="oHeadingSummary" class="rptheader"></span></p>

</div>

<table class="table table-striped rpttable" border="1" cellspacing="0" id="oReportContractDetailsByCA" width="100%">
<colgroup>... <col width="10%">
</colgroup></table>

自动生成表格我添加了一张图片:

    function GenerateTable(data) {
document.getElementById('divExport').style.display = "";
if (i == 0) {
$('#oReportContractDetailsByCA').append("<tr style='background-color:" + bkColor + ";'><td><img src='../../../_layouts/15/1033/IMAGES/eContracts/checked-checkbox-512.jpg'></img></td></tr>")
}

最佳答案

您可以使用 didDrawCell Hook 将任何内容添加到单元格。

https://codepen.io/someatoms/pen/vLYXWB

function generate() {
var doc = new jsPDF();

doc.autoTable({
html: '#mytable',
bodyStyles: {minCellHeight: 15},
didDrawCell: function(data) {
if (data.column.index === 5 && data.cell.section === 'body') {
var td = data.cell.raw;
// Assuming the td cells have an img element with a data url set (<td><img src="data:image/jpeg;base64,/9j/4AAQ..."></td>)
var img = td.getElementsByTagName('img')[0];
var dim = data.cell.height - data.cell.padding('vertical');
var textPos = data.cell.textPos;
doc.addImage(img.src, textPos.x, textPos.y, dim, dim);
}
}
});

doc.save("table.pdf");
}

关于jspdf - 如何使用 jsPDF 获取 PDF 中的表格行图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40465155/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com