无法使用AddHTML在jspdf中呈现CDN链接图像

时间:2018-06-22 05:24:18

标签: jspdf

我正在使用addHtml将带有本地图像的div内容导出为pdf。它的功能很棒,但是具有cdn链接的图像(服务器图像)无法渲染。

我尝试过的代码:

<div id="testdiv"> <asp:Image ImageUrl="https://test.com/DOCS/b11.jpg"Width="200px" runat="server" />

    

function exportChartToPDF() {
        var doc = new jsPDF('p', 'mm', 'A3', true);        
        doc.internal.scaleFactor = 3.75;
        var styles1 = {
            pagesplit: true,
            'background': '#fff'         
        };
        doc.addHTML($('#divpdf'), 0, 10, styles1, function () {
            doc.save('test.pdf');
        });
    }

1 个答案:

答案 0 :(得分:0)

     var pdf = new jsPDF('p', 'pt',  [PDF_Width, PDF_Height]);

    html2canvas($(".html_pdf_filemain")[0],
    margins.left, // x coord
    margins.top,

    { // y coord
        'width': margins.width, // max width of content on PDF
        //'elementHandlers': specialElementHandlers,


    },
     {allowTaint:true}).then(function(canvas) {
     canvas.getContext('2d');

      console.log(canvas.height+"  "+canvas.width);


      var imgData = canvas.toDataURL("image/jpeg", 1.0);



      pdf.addImage(imgData, 'JPG', top_left_margin, top_left_margin+100,canvas_image_width,canvas_image_height);


      for (var i = 1; i <= totalPDFPages; i++) {

      pdf.addPage(PDF_Width, PDF_Height);
      pdf.addImage(imgData, 'JPG', top_left_margin, (-(PDF_Height*i)+ 
     (top_left_margin*4))+100,canvas_image_width,canvas_image_height);
    }

          var iframe = document.createElement('iframe');
          iframe.setAttribute('style','position:absolute;right:0; top:0; bottom:0; height:100%; width:650px; padding:20px;');
          document.body.appendChild(iframe);
          iframe.src = pdf.output('datauristring');
          // pdf.save("HTML-Document.pdf");
         },margins);
       };

这是我生成的pdf generated pdf