[英]jsPDF is downloading EMPTY PDF
I have a content div with the id as "divDownload". 我有一个内容div,其ID为“ divDownload”。 In the content div I have a panel which has some repeaters and some tables and labels and so on. 在内容div中,我有一个面板,其中包含一些中继器,一些表和标签,等等。 I want to download that div as a pdf when user click on download button. 当用户单击下载按钮时,我想将该div下载为pdf。 For this purpose i'm using jsPDF Library. 为此,我正在使用jsPDF库。 But it is downloading empty PDF. 但是它正在下载空的PDF。
HTML page: 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 function: 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');
});
});
Can some one please help me how to solve this one? 有人可以帮我解决这个问题吗? Searched a lot and tried different ways in StackOverFlow, but no luck. 在StackOverFlow中进行了大量搜索并尝试了不同的方法,但是没有运气。
I have used: 我用过:
var source = $("#divDownload").html;
Also I have used true
for #noprint
. 我也对#noprint
使用true
。
Hope it helps you! 希望对您有帮助!
I tried again and the following is complete code: 我再次尝试,以下是完整的代码:
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);
Please let me know if it works or doesn't work. 请让我知道它是否有效。 Enjoyed solving this issue! 喜欢解决这个问题! Thanks! 谢谢!
@Abhi, @阿比
jsPdf works with html tables. jsPdf可用于html表。
Therefore you have to provide an id of a html table and not a div as you are trying. 因此,您必须提供html表的ID,而不要提供div的ID。 Try with a html table. 尝试使用html表。
Hope it helps. 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.