jsPDF 正在下载 EMPTY PDF
jsPDF is downloading EMPTY PDF
我有一个 ID 为 "divDownload" 的内容 div。
在内容 div 中,我有一个面板,其中有一些中继器、一些表格和标签等等。
当用户单击下载按钮时,我想将 div 下载为 pdf 格式。为此,我正在使用 jsPDF 库。但它正在下载空的 PDF。
HTML 页数:
<asp:Button ID="btnDownload" runat="server" Text="Download" />
<div id="divDownload">
<asp:Panel ID="pnldownload" runat="server">
// repeaters
//tables
//labels
</Panel>
</div>
<div id="noprint"></div>
JavaScript函数:
$(document).ready(function () {
$("#<%= btnDownload.ClientID %>").click(function (e) {
var pdf = new jsPDF('p', 'pt', 'a4');
var source = $("#divDownload");
alert(source);
specialElementHandlers = {
// element with id of "bypass" - jQuery style selector
'#noprint': function (element, renderer) {
// true = "handled elsewhere, bypass text extraction"
return false;
}
};
pdf.fromHTML(
source,
15,
15, {
'width': 150,
'elementHandlers': specialElementHandlers
});
pdf.save('test.pdf');
});
});
有人能帮我解决这个问题吗?在 Whosebug 中搜索了很多并尝试了不同的方法,但没有成功。
我用过:
var source = $("#divDownload").html;
我还用 true
代替了 #noprint
。
希望对您有所帮助!
我再次尝试,完整代码如下:
var pdf = new jsPDF('p', 'pt', 'a4');
var source = $("#divDownload").html();
specialElementHandlers = {
// element with id of "bypass" - jQuery style selector
'#noprint': function (element, renderer) {
// true = "handled elsewhere, bypass text extraction"
return true;
}
};
pdf.fromHTML(
source, 20, 20, { 'width': 150,
'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);
请告诉我它是否有效。很高兴解决这个问题!谢谢!
@阿比,
jsPdf 适用于 html tables。
因此,您必须提供 html table 而不是 div 的 ID。尝试使用 html table.
希望对您有所帮助。
我有一个 ID 为 "divDownload" 的内容 div。 在内容 div 中,我有一个面板,其中有一些中继器、一些表格和标签等等。 当用户单击下载按钮时,我想将 div 下载为 pdf 格式。为此,我正在使用 jsPDF 库。但它正在下载空的 PDF。
HTML 页数:
<asp:Button ID="btnDownload" runat="server" Text="Download" />
<div id="divDownload">
<asp:Panel ID="pnldownload" runat="server">
// repeaters
//tables
//labels
</Panel>
</div>
<div id="noprint"></div>
JavaScript函数:
$(document).ready(function () {
$("#<%= btnDownload.ClientID %>").click(function (e) {
var pdf = new jsPDF('p', 'pt', 'a4');
var source = $("#divDownload");
alert(source);
specialElementHandlers = {
// element with id of "bypass" - jQuery style selector
'#noprint': function (element, renderer) {
// true = "handled elsewhere, bypass text extraction"
return false;
}
};
pdf.fromHTML(
source,
15,
15, {
'width': 150,
'elementHandlers': specialElementHandlers
});
pdf.save('test.pdf');
});
});
有人能帮我解决这个问题吗?在 Whosebug 中搜索了很多并尝试了不同的方法,但没有成功。
我用过:
var source = $("#divDownload").html;
我还用 true
代替了 #noprint
。
希望对您有所帮助!
我再次尝试,完整代码如下:
var pdf = new jsPDF('p', 'pt', 'a4');
var source = $("#divDownload").html();
specialElementHandlers = {
// element with id of "bypass" - jQuery style selector
'#noprint': function (element, renderer) {
// true = "handled elsewhere, bypass text extraction"
return true;
}
};
pdf.fromHTML(
source, 20, 20, { 'width': 150,
'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);
请告诉我它是否有效。很高兴解决这个问题!谢谢!
@阿比,
jsPdf 适用于 html tables。
因此,您必须提供 html table 而不是 div 的 ID。尝试使用 html table.
希望对您有所帮助。