将Div转换为包含图像的PDF [英] Converting Div into PDF INCLUDING images

查看:155
本文介绍了将Div转换为包含图像的PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

am 使用HTML下载HTML页面中的div为pdf javascript

基本上使用jspdf将div转换为pdf.我可以使用它,但是唯一的问题是我无法添加它以及要包含在div中的图像.换句话说,我可以将div中的文本作为pdf而不是其中的图像.

which basically uses jspdf to make a div into a pdf. I got it to work, but the only problem is I can't get it to add an image as well that would be contained in the div. In other words, I can get the text that's in the div to be a pdf but not the image inside.

推荐答案

一种解决方案是使用html2canvasrasterizeHTML库.他们创建HTML页面的画布,然后您可以使用addHTML

One solution is to use the html2canvas or rasterizeHTML library. They create a canvas of the HTML page which you can then add to the PDF using addHTML

$('#cmd').click(function() {
  var options = {};
  var pdf = new jsPDF('p', 'pt', 'a4');
  pdf.addHTML($("#content"), 15, 15, options, function() {
    pdf.save('pageContent.pdf');
  });
});

演示

这篇关于将Div转换为包含图像的PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆