Search code examples
backgroundpdfmake

pdfmake.js Two different absolutePositions within the background function


I try to set two text elements in a header with the background function on two different positions. But it didn't work. (Only the last one wins) Is there a way to get it fixed?

background: function(currentPage, pageCount) {
                        return {
                            text: 'pagenumber ' + currentPage,
                            fontSize: 12,
                            absolutePosition: {
                                x: 50,
                                y: 60
                            },

                             text: 'printtime: ' + moment(this.result[0].time).format("DD.MM.YYYY HH:mm"),
                             fontSize: 12,
                             absolutePosition: {
                                x: 600,
                                y: 80
                             }
                        }
                    },

Any ideas? Thanks a lot!


Solution

  • To have two elements, you have to return Array. Try this:

    background: function(currentPage, pageCount) {
      return [{
          text: 'pagenumber ' + currentPage,
          fontSize: 12,
          absolutePosition: {
            x: 50,
            y: 60
          }
        },
        {
          text: 'printtime: ' + moment(this.result[0].time).format("DD.MM.YYYY HH:mm"),
          fontSize: 12,
          absolutePosition: {
            x: 600,
            y: 80
          }
        }
      }]
    },