如何将jspdf中创建的pdf导出为图像?

问题描述 投票:0回答:2

我已经使用jspdf在我的程序中创建了一个pdf,我提供了一个下载为图像或pdf的选项,所以我可以以某种方式使用jspdf或者以某种方式使用jspdf创建的pdf将其存储为图像吗?

javascript jspdf
2个回答
-1
投票

这个插件做不到 只有pdfjs插件可以


-2
投票

先将 HTML 转换为图像,然后再转换为 PDF。要将 HTML 转换为图像,请使用 html2canvas 并通过

addImage
方法创建 PDF。

示例:

const html_source = document.getElementById('contentID');   // Get html

 html2canvas(html_source).then(function(canvas) { // Convert to canvas

   let imgData = canvas.toDataURL('image/png'); // Generates image that you can store

   let pdf = new jsPDF('p', 'mm', 'a4'); //Create PDF, Note that you use the same image to create the PDF
   pdf.addImage(imgData, 'PNG', 10, 10);
   pdf.save('test.pdf');
 })
© www.soinside.com 2019 - 2024. All rights reserved.