类型错误无法设置属性' _minWidth' of undefined - pdfmake,Angular 2

时间:2018-01-09 13:53:58

标签: javascript json angular pdfmake

我正在尝试为表格添加宽度,但由于某种原因,我得到以下错误:

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)

发布行

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

我的文档定义

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'
        }
    };

我尝试过(以下都没有工作):

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


It works if I just remove the widths line.

1 个答案:

答案 0 :(得分:7)

您有五列,但只设置四个宽度。尝试设置所有这些的宽度:

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