首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jsPDF fromHTML()不显示图像

jsPDF fromHTML()不显示图像
EN

Stack Overflow用户
提问于 2015-11-27 15:06:07
回答 2查看 6.1K关注 0票数 0

HTML代码:

代码语言:javascript
复制
<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代码:

代码语言:javascript
复制
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。请帮我解决这个问题

EN

回答 2

Stack Overflow用户

发布于 2015-12-09 10:31:52

我也遇到了同样的问题,但我的图片看不到,因为我在chrome上试过了,火狐也试过了,如果它能工作,说明代码没问题。我澄清说,我对这个主题了解不多,但是如果你想在任何浏览器中操作,你可以使用web服务器。

票数 0
EN

Stack Overflow用户

发布于 2015-12-18 13:48:31

尝尝这个,

我将上面的html代码更改为:

代码语言:javascript
复制
<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

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33951936

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档