【发布时间】:2018-05-08 09:28:30
【问题描述】:
我尝试在https://github.com/joshua-gould/canvas2pdf 阅读更多内容。在这里,有一个创建新 PDF 画布的指南,但我想使用一个 div 包含两个画布
$('#PDF').click(function(e) {
e.preventDefault();
// In here, I need get data a div with two canvas ,
// and then add this to below
//Create a new PDF canvas context.
var ctx = new canvas2pdf.Context(blobStream());
//draw your canvas like you would normally
ctx.fillStyle = 'yellow';
ctx.fillRect(100, 100, 100, 100);
// more canvas drawing, etc...
//convert your PDF to a Blob and save to file
ctx.stream.on('finish', function() {
var blob = ctx.stream.toBlob('application/pdf');
saveAs(blob, 'example.pdf', true);
});
ctx.end();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="pdf-viewer" style="height: 300px; width: 100%; background: #d4d4d4; overflow: scroll">
<canvas height="792" width="612" style="margin: 2px auto; display: block; border: 2px solid rgb(255, 0, 0);"></canvas>
<canvas height="792" width="612" style="margin: 2px auto; display: block; border: 2px solid rgb(255, 0, 0);"></canvas>
</div>
我需要一种在 div 中获取数据并使用此转换为 PDF 的方法。
【问题讨论】:
标签: javascript jquery html pdf html5-canvas