2015-11-27 40 views
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。请帮我解决这个问题

回答

0

我有同样的问题,但没有看到我的图像,因为我在铬试用它,Firefox试图它,如果它的工作,表明代码是好的。我澄清说我不太了解这个主题,但是如果你想在任何浏览器中运行,你可以使用一个web服务器。

+0

我得到了一个解决方案。但我不知道它的正确方法。我将图像转换为base64编码,然后运行 –

+0

你能告诉我吗?,我将不胜感激。 –

-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> 

那么它的作品对我来说

jsFiddle Example