admin管理员组文章数量:1420119
I am trying to make an app in which the user can download a certain table as PDF. I am trying to use jsPDF for the purpose but due to some reasons or other , it is not working. The latest error which I am getting in the console is TypeError: element is undefined
in the file jspdf.plugin.from_html.js
.
Here is my approach:
I have the following headers:
<script type="text/javascript" src="jspdf.js"></script>
<script type="text/javascript" src="jspdf.plugin.from_html.js"></script>
<script type="text/javascript" src="jspdf.plugin.split_text_to_size.js"></script>
<script type="text/javascript" src="jspdf.plugin.standard_fonts_metrics.js"></script>
One thing that may be noted here is the fact that My table is populated dynamically from values provided by my backend during the page load itself
The table looks like:
<div id="huh">
<table class="table table-hover table-bordered" id="recent">
<thead>
<tr>
<th>
Spent On
</th>
<th>
Amount
</th>
</tr>
</thead>
</table>
</div>
The table contains actual data when I invoke the following script:
<script type="text/javascript">
function demoFromHTML() {
var doc = new jsPDF('p', 'in', 'letter');
var source = document.getElementById('huh');
var specialElementHandlers = {
'#bypassme': function(element, renderer) {
return true;
}
};
doc.fromHTML(
$('#testcase').get(0), // [Refer Exact code tutorial][2]HTML string or DOM elem ref.
0.5, // x coord
0.5, // y coord
{
'width': 7.5, // max width of content on PDF
'elementHandlers': specialElementHandlers
});
doc.output('dataurl');
}
</script>
<button onclick="javascript:demoFromHTML();">PDF</button>
I took some code from samples and examples. Any ideas where I am going wrong? Thank You.
I am trying to make an app in which the user can download a certain table as PDF. I am trying to use jsPDF for the purpose but due to some reasons or other , it is not working. The latest error which I am getting in the console is TypeError: element is undefined
in the file jspdf.plugin.from_html.js
.
Here is my approach:
I have the following headers:
<script type="text/javascript" src="jspdf.js"></script>
<script type="text/javascript" src="jspdf.plugin.from_html.js"></script>
<script type="text/javascript" src="jspdf.plugin.split_text_to_size.js"></script>
<script type="text/javascript" src="jspdf.plugin.standard_fonts_metrics.js"></script>
One thing that may be noted here is the fact that My table is populated dynamically from values provided by my backend during the page load itself
The table looks like:
<div id="huh">
<table class="table table-hover table-bordered" id="recent">
<thead>
<tr>
<th>
Spent On
</th>
<th>
Amount
</th>
</tr>
</thead>
</table>
</div>
The table contains actual data when I invoke the following script:
<script type="text/javascript">
function demoFromHTML() {
var doc = new jsPDF('p', 'in', 'letter');
var source = document.getElementById('huh');
var specialElementHandlers = {
'#bypassme': function(element, renderer) {
return true;
}
};
doc.fromHTML(
$('#testcase').get(0), // [Refer Exact code tutorial][2]HTML string or DOM elem ref.
0.5, // x coord
0.5, // y coord
{
'width': 7.5, // max width of content on PDF
'elementHandlers': specialElementHandlers
});
doc.output('dataurl');
}
</script>
<button onclick="javascript:demoFromHTML();">PDF</button>
I took some code from samples and examples. Any ideas where I am going wrong? Thank You.
Share Improve this question asked Oct 24, 2014 at 12:45 Akshay AroraAkshay Arora 1,9451 gold badge16 silver badges31 bronze badges1 Answer
Reset to default 2Your #testcase
is not defined
try:
<script type="text/javascript">
function demoFromHTML() {
var doc = new jsPDF('p', 'in', 'letter');
//var source = document.getElementById('huh');
var specialElementHandlers = {
'#bypassme': function(element, renderer) {
return true;
}
};
doc.fromHTML(
$('#huh').get(0), // [Refer Exact code tutorial][2]HTML string or DOM elem ref.
0.5, // x coord
0.5, // y coord
{
'width': 7.5, // max width of content on PDF
'elementHandlers': specialElementHandlers
});
doc.output('dataurl');
}
</script>
Here is the working example http://jsfiddle/xzZ7n/898/
本文标签: javascriptElement is undefined error in jsPDFStack Overflow
版权声明:本文标题:javascript - Element is undefined error in jsPDF - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745326994a2653637.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论