本文介绍了使用pdfmake在段落中添加边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过生成pdf。

假设我有这样的pdf内容

Let's say i have content of the pdf like this

var docDefinition = {
    content: [
        'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam a pharetra odio.',
        'Vestibulum erat mauris, sodales et consequat sit amet, ultricies vitae erat. Etiam feugiat orci justo, ultrices malesuada dui ornare ac.',
    ]
};

是否可以在其中一个段落中添加边框或者是否必须使用表格?

Is it possible to add border arround one of the paragraphs or do I have to use tables for this?

推荐答案

我还没有对一个段落应用边框。我认为你唯一的选择就是使用表格。

I have not gotten apply borders to a paragraph. I think the only option you have is to use tables.

在这行之后我附上了一个简单的代码,你可以直接粘贴在以试用它。

Below this lines I have attached a simple code that you can paste directly at pdfmake playground in order to try it.

var dd = {
    content: [
        {
            style: 'tableExample',
            color: '#555',
            table: {
                body: [
                    [
                        {
                             text : 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam a pharetra odio.\n\nVestibulum erat mauris, sodales et consequat sit amet, ultricies vitae erat. Etiam feugiat orci justo, ultrices malesuada dui ornare ac.'
                        }
                    ],
                    [
                        {
                             text : 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam a pharetra odio.\n\nVestibulum erat mauris, sodales et consequat sit amet, ultricies vitae erat. Etiam feugiat orci justo, ultrices malesuada dui ornare ac.'
                        }
                    ],
                    [
                        {
                             text : 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam a pharetra odio.\n\nVestibulum erat mauris, sodales et consequat sit amet, ultricies vitae erat. Etiam feugiat orci justo, ultrices malesuada dui ornare ac.'
                        }
                    ],
                ]
            },
            layout: {
                //hLineWidth: function(i, node) {
                //  return (i === 0 || i === node.table.body.length) ? 2 : 1;
                //},
                //vLineWidth: function(i, node) {
                //  return (i === 0 || i === node.table.widths.length) ? 2 : 1;
                //},
                hLineColor: function(i, node) {
                    return (i === 0 || i === node.table.body.length) ? 'red' : 'blue';
                },
                vLineColor: function(i, node) {
                    return (i === 0 || i === node.table.widths.length) ? 'red' : 'blue';
                },
                paddingLeft: function(i, node) { return 40; },
                paddingRight: function(i, node) { return 40; },
                paddingTop: function(i, node) { return 20; },
                paddingBottom: function(i, node) { return 20; }
            }
        }
    ],

    defaultStyle: {
        alignment: 'justify'
    }

}

这篇关于使用pdfmake在段落中添加边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 21:52