简体   繁体   English

PDFMake如何在图像上放置文本

[英]PDFMake how to put text over an image

I'm struggling trying to put text over an image with PDFmake, I'm using PDFMAKE playground image demo我正在努力尝试使用 PDFmake 将文本放在图像上,我正在使用 PDFMAKE 游乐场图像演示

var dd = {
    content: [
                {
                 stack:[    
                         {
                             text:'pdfmake (since it\'s based on pdfkit)     supports JPEG and PNG format',
                             color:'#333',
                             fontSize: 17
                        },    
                        {
                            image: 'sampleImage.jpg',
                        }
                    ]

                }
    ]
} 

Any dea how this could be ahieved?有什么办法可以实现吗?

Duplicate question: Embedding a background image in pdfmake重复问题: 在 pdfmake 中嵌入背景图像

Put the image in a background将图像置于背景中

var dd = {

  pageSize: 'LETTER',
  background: [
   {
       image: 'sample.jpg',
       width: 792
   }
  ],
  content: [
     'text'
  ]

You could use a background as explained in the documentation:您可以使用文档中解释的背景:

https://pdfmake.github.io/docs/0.1/document-definition-object/background-layer/ https://pdfmake.github.io/docs/0.1/document-definition-object/background-layer/

var docDefinition = {
  background: 'simple text',

  content: (...)
};

Note that if you don't want it to be repeated in every page, you can use a function to return a different background according to the page:请注意,如果您不希望它在每个页面中重复,您可以使用 function 根据页面返回不同的背景:

var docDefinition = {
  background: function(currentPage, pageSize) {
    return `page ${currentPage} with size ${pageSize.width} x ${pageSize.height}`
  },

  content: (...)
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM