Type Error Cannot set property '_minWidth' of undefined - pdfmake, Angular 2

Murlidhar Fichadia picture Murlidhar Fichadia · Jan 9, 2018 · Viewed 7.3k times · Source

I am trying to add widths to my table but for some reason I get below error:

Component.html:187 ERROR TypeError: Cannot set property '_minWidth' of undefined  at DocMeasure.measureTable (pdfmake.js:4487)
at pdfmake.js:4012
at StyleContextStack.auto (pdfmake.js:6069)
at DocMeasure.measureNode (pdfmake.js:3999)
at DocMeasure.measureVerticalContainer (pdfmake.js:4216)
at pdfmake.js:4006
at StyleContextStack.auto (pdfmake.js:6069)
at DocMeasure.measureNode (pdfmake.js:3999)
at DocMeasure.measureDocument (pdfmake.js:3992)
at LayoutBuilder.tryLayoutDocument (pdfmake.js:3120)
at LayoutBuilder.layoutDocument (pdfmake.js:3107)
at PdfPrinter.createPdfKitDocument (pdfmake.js:2383)
at Document._createDoc (pdfmake.js:105)
at Document.getBuffer (pdfmake.js:243)
at Document.getBlob (pdfmake.js:233)

Issue line

widths: ['auto', 'auto', 'auto', 'auto'],

My Doc Definition

var docDefinition = {
        content: [
            {text: 'Section A: Facilities and Ambience', style: 'sectionStyling'},
            {
                style: 'tableExample',
                table: {
                    widths: ['auto', 'auto', 'auto', 'auto'],
                    body: [
                        ['col1', 'col2', 'col3', 'col4', 'col5'],
                        ['some text', '1', '1', '100%', '-'],
                        ['some text', '1', '1', '100%', '-'],
                        ['some text', '1', '1', '100%', '-'],
                        ['some text', '1', '1', '100%', '-'],
                        ['some text', '1', '1', '100%', '-'],
                        ['some text', '1', '1', '100%', '-'],
                        ['some text', '1', '1', '100%', '-'],
                        ['some text', '1', '1', '100%', '-']
                    ]
                }
            }
        ],
        background: function () {
            return [
                {
                    image: 'watermark',
                    width: 200,
                    alignment : 'center',
                    margin: [0, 325, 0, 0]
                }
            ];
        },
        images: {
            watermark: 'data:image/base64....'
        },
        styles: {
            sectionStyling: {
                fontSize: 18,
                color: 'blue',
                bold: true,
                alignment: 'right',
                margin: [0, 190, 0, 80]
            },
            subheader: {
                fontSize: 14
            },
            superMargin: {
                margin: [20, 0, 40, 0],
                fontSize: 15
            }
        },
        defaultStyle: {
            alignment: 'justify'
        }
    };

I tried (none of the below work):

widths: ['auto', 'auto', 'auto', 'auto'],
widths: ['auto', 'auto', 'auto'],
widths: [100, '*', 200, '*'],


It works if I just remove the widths line.

Answer

cbr picture cbr · Jan 9, 2018

You have five columns but are setting only four widths. Try setting the width for all of them:

widths: ['auto', 'auto', 'auto', 'auto', 'auto'];