在pdfmake中嵌入背景图片 [英] Embedding a background image in pdfmake

查看:165
本文介绍了在pdfmake中嵌入背景图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用pdfmake http://bpampuch.github.io/pdfmake/index.html#/gettingstarted 来实现html到pdf的转换.为了创建PDF,我使用了一些硬编码的文本,以及一些使用AngularJS从.json文件中提取的文本.除背景图片外,其他所有选项均正常运行.

I'm using pdfmake http://bpampuch.github.io/pdfmake/index.html#/gettingstarted to implement html to pdf conversion. To create a PDF, I'm using some hard-coded text and some text pulled in with AngularJS from a .json file. All works well for the exception of the background image.

有人做过吗?在pdfmake中使用了背景图片?我想就如何强制将其抓取并实际放置在后台中获得一些建议.谢谢.

Has anyone done this before? Used a background image with pdfmake? I would like to get some advice on how to force it to grab it and actually put it in the background. Thanks.

推荐答案

结果表明,为了将图像设置为背景,需要确定.pdf输出大小,适当调整bkg图像的大小,然后指示所有函数中的尺寸如下(我正在与此一起使用AngularJS):

Turns out that in order to set an image as the background, one needs to decide on the .pdf output size, size the bkg image appropriately and then indicate all dimensions in the function as follows (I'm using AngularJS with this):

$scope.pdfMaker = function() {
var docDefinition = {
  pageSize: 'LETTER',
  background: [
   {
       image: 'data:image/jpeg;base64,/9j/4QAY...',
       width: 792
   }
 ],
 //other parameters go here
}

指示图像的pageSize和宽度对于使图像出现在背景中至关重要.

Indicating pageSize and width of the image was crucial to having the image appear in the background.

请让我知道此方法是否有错误,或者是否有人以简单的方式成功完成此操作.

Let me know if there are errors in this method or if anyone had success doing it in a simpler way.

这篇关于在pdfmake中嵌入背景图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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