简体   繁体   English

无法使用jspdf和html2canvas从图像创建pdf

[英]Unable to create pdf from image using jspdf and html2canvas

I am trying to create the pdf file from an image file, but getting the blank pdf file. 我正在尝试从图像文件创建pdf文件,但获取的是空白pdf文件。 I draw an image file into the canvas and then trying to create the pdf file. 我将图像文件绘制到画布中,然后尝试创建pdf文件。

I am using html2canvas and jspdf 我正在使用html2canvasjspdf

here is my jsfiddle 这是我的jsfiddle

Yesterday i got the same task, this is my code https://jsfiddle.net/qe884617/ 昨天我完成了同样的任务,这是我的代码https://jsfiddle.net/qe884617/

but when exporting pdf you will get a security error about Tainted canvases may not be exported. 但是在导出pdf时,您会收到有关Tainted canvases may not be exported.的安全错误Tainted canvases may not be exported. you have to make the image was on the same server as page address. 您必须使图像与页面地址位于同一服务器上。 You may read further information here 您可以在此处阅读更多信息

This is another approach using fabric.js, see here to run you have to Allow-Control-Allow-Origin:* on document header. 这是使用fabric.js的另一种方法, 请参见此处运行,必须在文档标题上执行Allow-Control-Allow-Origin:*。 Or just install google chrome CORS addon 或仅安装Google Chrome Chrome CORS插件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM