javascript - 如何使用 fillColor 填充 pdfmake 的列背景颜色?

标签 javascript pdf pdf-generation pdfmake

是否有任何选项可以用 fillColor: '#dedede' 填充列背景色? fillColor 在 tablecell 中工作得很好,同时它不适用于列 :(

<script src="https://rawgit.com/bpampuch/pdfmake/master/build/vfs_fonts.js"></script>
<script src="https://rawgit.com/yelouafi/pdfmake/master/build/pdfmake.js"></script>
<script>
  function print(argument) {
    // open the PDF in a new window
    pdfMake.createPdf(docDefinition).open();
  }
</script>
<button onclick="print()" style="display:block; margin: 10px auto;padding: 20px 50px;">Print</button>
<hr>
<script>
  var docDefinition = {
    content: [
      'This paragraph fills full width, as there are no columns. Next paragraph however consists of three columns', {
        columns: [{
          // auto-sized columns have their widths based on their content
          width: 'auto',
          text: 'First column',
          fontSize: 30,
          fillColor: '#dedede'
        }, {
          // star-sized columns fill the remaining space
          // if there's more than one star-column, available width is divided equally
          width: '*',
          text: 'Second column'
        }, {
          // fixed width
          width: 100,
          text: 'Third column'
        }, {
          // percentage width
          width: '10%',
          text: 'Last column'
        }],
        // optional space between columns
        columnGap: 10
      },
      'This paragraph goes below all columns and has full width'
    ]
  };
</script>

最佳答案

我还没有为列应用背景颜色。我认为您唯一的选择是使用表格。

在此行下方,我附上了一个简单的代码,您可以将其直接粘贴到 pdfmake playground 以进行尝试。

祝你好运!

    var dd = {
    content: [
        'This paragraph fills full width, as there are no columns. Next paragraph however consists of three columns', 
        {
            style: 'section',
            table: {
                widths: [ '15%',  '*',  '35%'],
                body: [
                    [ 
                        {
                          text: 'first column',
                          fillColor: '#555555',
                          color: '#00FFFF',
                        },
                        {
                          text: 'second column',
                          color: '#555555',
                          fillColor: '#dedede'
                        },
                        {
                          text: 'third column',
                          fillColor: '#555555'
                        }
                    ]
                ]
            },
            layout: 'noBorders'
        }
    ],
    styles: {
        section: {
            fontSize: 9,
            color: '#FFFFFF',
            fillColor: '#2361AE',
            margin: [0, 15, 0, 5]
        }
    },
    defaultStyle: {
        alignment: 'center'
    }
}

关于javascript - 如何使用 fillColor 填充 pdfmake 的列背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28764174/

相关文章:

javascript - 如何在 Visual Studio 2013 中 'do'(并使用)HTML 包(来自 Web Essentials)

javascript - 如何通过人力车和AngularJS制作图表?

pdf - 14种标准PDF字体和字符编码

iphone - 在 IOS 中将从 Web 服务接收到的字节数组转换为 PDF

c++ - PDFCreator 将打印 TIFF 而不是 PDF

javascript - JS 检查页面/内容是否不包含

java - 使用 Java 的 Pdf 页数

java - 如何使用 itext 5.3.0 在 PDF 文档中显示 Java List<>?

java - iText Java 到 PDF : how to output a JPanel without having to add it to the Container

javascript - JS跨域子到父窗口通信