HTML CODE:
<div id="customers" >
<div class="">
<div class="heading">
<img class="form_head" src="http://dev.syntrio.in/kchr-project/images/kchr-kchr.png" alt="">
</div>
<button onclick="javascript:demoFromHTML();">PDF</button>
JS CODE:
function demoFromHTML() {
var pdf = new jsPDF('p', 'pt', 'letter');
// source can be HTML-formatted string, or a reference
// to an actual DOM element from which the text will be scraped.
source = $('#customers')[0];
// we support special element handlers. Register them with jQuery-style
// ID selector for either ID or node name. ("#iAmID", "div", "span" etc.)
// There is no support for any other type of selectors
// (class, of compound) at this time.
specialElementHandlers = {
// element with id of "bypass" - jQuery style selector
'#bypassme': function (element, renderer) {
// true = "handled elsewhere, bypass text extraction"
return true
}
};
margins = {
top: 80,
bottom: 60,
left: 40,
width: 10000
};
// all coords and widths are in jsPDF instance's declared units
// 'inches' in this case
pdf.fromHTML(
source, // HTML string or DOM elem ref.
margins.left, // x coord
margins.top, { // y coord
'width': margins.width, // max width of content on PDF
'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.debug.js中。单击pdf按钮时,生成了pdf,但未显示html代码中的图像。我得到了一个空白的pdf。请帮我解决这个问题
答案 0 :(得分:0)
我遇到了同样的问题,但是我的图像没有被看到,因为我在chrome中试过它,firefox尝试了它,如果它工作,表明代码很好。我澄清说我不太了解这个主题,但如果你想在任何浏览器中操作,你可以使用网络服务器。
答案 1 :(得分:-1)
试试这个,
我将上面的html代码更改为:
<div id="customers" >
<div class="">
<div class="heading">
<img class="form_head" src="base64encoded data of the image" alt="">
</div>
<button onclick="javascript:demoFromHTML();">PDF</button>
然后它为我工作