pdfmake icon indicating copy to clipboard operation
pdfmake copied to clipboard

Header/Footer error on multiple pages

Open nbridgemohan opened this issue 10 years ago • 5 comments

I have a app which produces a multi page pdf.

on the produced pdf, there is a header and footer. the header is placed in a 2 column table so that there is an image to the left and right, and the footer is in a 3 column table so that there are images in the middle, left and right. when we move to the second page, the tables change a bit and some columns disappear.

i was able to reproduce the problem on playground

please take a look into it.

// playground requires you to assign document definition to a variable called dd

var dd = {
                pageSize: 'letter',
            pageOrientation: 'portrait',
            pageMargins: [40, 55, 40, 60],
            header: {
                margin: [10, 10],
                columns: [
                    {

                        table: {
                            widths: ['50%', '50%'],

                            body: [
                                [
                                    {
                                        image: 'sampleImage.jpg',
                                        width: 140, height: 26,
                                        alignment: 'left'
                                    },


                                    {
                                        image: 'sampleImage.jpg',
                                        width: 140, height: 26,
                                        alignment: 'right'
                                    }
                                ]
                            ]
                        },
                        layout: 'noBorders'
                    }


                ]
            },


            footer: {
                margin: [10, 10],
                columns: [
                    {

                        table: {
                            widths: ['33%', '33%', '33%'],

                            body: [
                                [
                                    {
                                        image: 'sampleImage.jpg',
                                        width: 140, height: 26,

                                        alignment: 'left'

                                    },

                                    {
                                        image: 'sampleImage.jpg',
                                        width: 140, height: 26,
                                        alignment: 'center'
                                    },


                                    {
                                        image: 'sampleImage.jpg',
                                         width: 140, height: 26,

                                        alignment: 'right'
                                    }
                                ]
                            ]
                        },
                        layout: 'noBorders'
                    }


                ]
            },
    content: [
        'First page',
        '\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n',
        "second Page"


    ]
}

nbridgemohan avatar May 23 '16 20:05 nbridgemohan

Any feedback

nbridgemohan avatar May 31 '16 18:05 nbridgemohan

same problem here! one center image in header works fine on first page, but is shifted to the far right on the following pages!

Twisterking avatar Jun 07 '16 21:06 Twisterking

Same problem here. Seems to be an issue with margins. At least also the positioning of images having a margin is wrong. Left margins are sumed up on every page, pushing the image more and more to the right.

Mario-Eis avatar Jun 30 '16 17:06 Mario-Eis

I was able to get around this by passing a function to the header, as suggested in the doc's header and footer section.

  var docDefinition = {
    header: function() {
        var _left = 285;
        return {
          margin: [_left, 10],
          columns: [
            {
               // you'll most often use dataURI images on the browser side
              // if no width/height/fit is provided, the original size will be used
              image: 'data:image/jpeg;base64,...encodedContent...',
              width: 300,
              alignment: 'center',
            }
          ]
        }
      }, 
    footer: {...}
}

Hope this helps.

vdtejeda avatar Jul 08 '16 23:07 vdtejeda

Fixed in version 0.1.22.

liborm85 avatar Dec 23 '16 13:12 liborm85