如何在pdfmake中设置文本的背景颜色和填充

You*_*Bee 3 pdfmake

我有一个字符串想要用作 PDF 文档的标题。我尝试使用以下代码来实现此目的,但遇到了背景颜色的问题。它不会将背景颜色应用于整行,而是仅出现在文本正下方。对于解决此问题的任何帮助,我将不胜感激。

var dd = {
   
    content: [
            {
        text: 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.',
        style: 'header'
      },
],
    styles: {
        header: {
            fontSize: 18,
            bold: true,
            margin: [0, 0, 0, 10],
            background:'blue',
            color: 'white',
            alignment:'center'
        }
    },
    defaultStyle: {
        // alignment: 'justify'
    }
    
}
Run Code Online (Sandbox Code Playgroud)

You*_*Bee 6

我找不到一种简单的方法来自定义背景颜色和文本填充。为了解决这个问题,我探索了一种替代方法,设计了一个表格,其中只有标题使用无边框的单列。事实证明,该解决方案对于我的特定用例是有效的。

    var dd = {
            content: [
            
             
            {
                style: 'header',
                table: {
                    widths:'*',
                    body: [
                        [{
                                border: [false, false, false, false],
                                fillColor: '#5bc0de',
                                text: 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.'
                            }]
                    ]
                }
            },
            
        
        ]
}
Run Code Online (Sandbox Code Playgroud)