0
HTML代碼:jsPDF fromHTML()不顯示圖像
<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。請幫我解決這個問題
我得到了一個解決方案。但我不知道它的正確方法。我將圖像轉換爲base64編碼,然後運行 –
你能告訴我嗎?,我將不勝感激。 –