javascript - 如何在其他 jsPdf 元素之间添加画布图像
问题描述
我已将特定<div>
标签转换为<canvas>
使用html2canvas
,我需要将此转换后的画布图像与其他JsPdf
元素(如Autotables
文本)添加。
谢谢。
解决方案
这是我在 jsfiddle http://jsfiddle.net/huynhsamha/q5w8pvdn/上的解决方案
您可以在 jsfiddle 上运行,它正在工作。这是代码片段。
const html2canvas = window.html2canvas;
$(document).ready(function() {
$('#download').click(function() {
html2canvas(document.body).then(function(canvas) {
var imgData = canvas.toDataURL('image/png');
var doc = new jsPDF();
doc.addImage(imgData, 'PNG', 10, 10);
doc.save('file.pdf');
});
});
});
button {
margin: 50px;
}
<p>The library has two sets of tests. The first set is a number of qunit tests that check that different values parsed by browsers are correctly converted in html2canvas. To run these tests with grunt you'll need phantomjs.</p>
<p>The other set of tests run Firefox, Chrome and Internet Explorer with webdriver. The selenium standalone server (runs on Java) is required for these tests and can be downloaded from here. They capture an actual screenshot from the test pages and compare the image to the screenshot created by html2canvas and calculate the percentage differences. These tests generally aren't expected to provide 100% matches, but while committing changes, these should generally not go decrease from the baseline values.</p>
<button id="download">Download PDF</button>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://unpkg.com/html2canvas@1.0.0-alpha.12/dist/html2canvas.min.js"></script>
<script src="https://unpkg.com/jspdf@1.4.1/dist/jspdf.min.js"></script>
推荐阅读
- replace - 文本框表达式中的 SSRS 替换函数
- angular - onBlur 和 onSubmit 上的 NgModel 更新
- vb.net - 如何在 vb.net 中链接 2 个数据网格视图
- python - 姜戈。如何将来自mixin的父模型字段存储在子模型中?
- dart - 如何在 Flutter 中的 navigator.pop(context) 之后显示小吃栏?
- mysql - 通过 1 SELECT 从 SQL 中提取所有内容
- geospatial - 有人有兴趣为 GeoDMS 建立社区吗?
- javascript - 是否可以在 Leaflet.js 上使用这些图标(http://map-icons.com/)?
- sql - 合并 1 行中的数据
- python - KeyError:使用箱线图时出现“final_result”