PDF.js插入图像 [英] PDF.js Inserting Images
问题描述
顺便说一下,我已开始使用 PDF.js ,这是一项杰出的工作。
I've started using PDF.js, an excelent work, by the way.
但现在我想在pdf页面上插入一个图像(从canvas元素)。这是我的代码:
But now I want to insert an image (from a canvas element) on the pdf page. Here's my code:
var image = myCanvas.getContext('2d').getImageData(0,0,400,300),
doc = new pdf();
doc.setProperties({
title: fileName,
author: 'VirtuaLab®',
creator: 'pdf.js'
});
doc.addPage();
data = doc.output();
但我还没有找到任何关于在PDF.js页面上插入图片的信息。
But I haven't found anything about inserting images on PDF.js pages.
可能 doc.image()
或 doc.addImage
?
推荐答案
免责声明:我为 Bytescout 工作
不幸的是,PDF.js不支持图片,因此我们开发了 PDF JavaScript的Generator SDK (免费用于非商业用途),您可以在此处添加图片(来自网址或画布),如下所示:
Unfortunately PDF.js not working with images and that is why we developed PDF Generator SDK for Javascript (free for non-commercial use) where you can add image (from url or canvas) like this:
// load image from local file
pdf.imageLoadFromUrl('image1.jpg');
// place this mage at given X, Y coordinates on the page
pdf.imagePlace(20, 40);
重要的是,你可以面对图像大小的限制,因为BytescoutPDF.js可能消耗内存处理大image(这个问题是由javascript的内存限制造成的)。
Important to say that you can face limitation on image size as BytescoutPDF.js may consumes memory to process large image (this issue is caused by the memory limitations for javascript).
但是,如果您只需要在生成的pdf中插入标志图片或小图片,脚本应该会正常工作。
However the script should work fine in case you just need to insert logo image or small picture into generated pdf.
UPDATE : jsPDF 的最新版本(不要与PDF.js混淆)似乎适用于图片,请参阅示例页面上的示例。
UPDATE: the latest version of jsPDF (not to be confused with PDF.js) seems to work with images, see the sample on examples page.
这篇关于PDF.js插入图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!