2

I'm struggling trying to put text over an image with PDFmake, I'm using PDFMAKE playground image demo

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 ?

user701934
  • 33
  • 1
  • 6

2 Answers2

1

Duplicate question: Embedding a background image in pdfmake

Put the image in a background

var dd = {

  pageSize: 'LETTER',
  background: [
   {
       image: 'sample.jpg',
       width: 792
   }
  ],
  content: [
     'text'
  ]
mjlitz
  • 148
  • 10
0

You could use a background as explained in the documentation:

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:

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

  content: (...)
};

maganap
  • 2,414
  • 21
  • 24