HTML代码:
<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代码:
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。请帮我解决这个问题
发布于 2015-12-09 10:31:52
我也遇到了同样的问题,但我的图片看不到,因为我在chrome上试过了,火狐也试过了,如果它能工作,说明代码没问题。我澄清说,我对这个主题了解不多,但是如果你想在任何浏览器中操作,你可以使用web服务器。
发布于 2015-12-18 13:48:31
尝尝这个,
我将上面的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>那么它对我来说是有效的
jsFiddle Example
https://stackoverflow.com/questions/33951936
复制相似问题