在IE上获取黑色图像

在IE上获取黑色图像

本文介绍了jsPDF-在IE上获取黑色图像,但在Chrome和FireFox上可以正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下问题上,我需要一些帮助,当我在Chrome和FireFox上获得包含图像的pdf时,我可以得到很好的结果,jsPDF对其进行了模糊处理,但我可以接受.

I need some help with the following problem, when I get a pdf with images on Chrome and FireFox I can get a good résult, jsPDF put on it some blur but I can live with it.

Chrome上的结果

另一方面,在IE 10,11和Edge上,结果如下:

In other hand, on IE 10,11 and Edge the result is the following:

IE上的结果

如果您注意到我们在图片上可以看到一些东西,但是几乎是黑色的.

If you notice we can see something on pictures but almost is black.

这些是图表的图表,我将svg转换为画布.

Those are charts from highcharts and I convert svg to canvas.

我添加了一些摘录,但是我可以将整个示例发送给电子邮件:

I put some snippets but I can send to email the whole example:

  var doc = new jsPDF('p', 'pt', 'a4', true);
  var centered_x = (doc.internal.pageSize.width / 2) - ((context.destWidth / 2) * 0.75);

imgData_1 = atob(imgData_1);
doc.addImage(imgData_1, 'png', centered_x, 50);

data.datauri = context.browserSupportDownload && doc.output('datauristring');
data.blob = context.browserSupportBlob && doc.output('blob');

我调用函数download将流发送到浏览器,其定义如下:

I call the function download to send the stream to the browser and its definition is like that:

  var download = function(highChartsObject, context, data) {
    if (!data || (!data.content && !(data.datauri || data.blob))) {
      throw new Error("Something went wrong while exporting the chart");
    }

    if (context.browserSupportDownload && (data.datauri || data.content)) {
      a = document.createElement('a');
      a.href = data.datauri || ('data:' + context.type + ';base64,' + window.btoa(unescape(encodeURIComponent(data.content))));
      a.download = 'result_good.pdf';
      document.body.appendChild(a);
      a.click();
      a.remove();
    }
    else if (context.browserSupportBlob && (data.blob || data.content)) {
      blobObject = data.blob || new Blob([data.content], { type: context.type });
      window.navigator.msSaveOrOpenBlob(blobObject, 'IE_CASE.pdf');
    }
    else {
      //window.open(data);
        window.navigator.msSaveOrOpenBlob(blobObject, 'IE_CASE.pdf');
    }
  };

谢谢.

推荐答案

尝试使用画布或svg更改图像的背景颜色. https://github.com/MrRio/jsPDF/issues/247

Try changing the background color of the image using canvas or svg.https://github.com/MrRio/jsPDF/issues/247

这篇关于jsPDF-在IE上获取黑色图像,但在Chrome和FireFox上可以正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 13:14
查看更多