pdfmake icon indicating copy to clipboard operation
pdfmake copied to clipboard

Add Padding and rounded Border to the text

Open suhasbhattu opened this issue 7 years ago • 3 comments

I want to add the text that looks like this: Untitled

I have tried this thing:

content: [
    {text: "Lorem ipsum dolor sit amet", background: "#e5f6ff"}
]

But I want to add padding and add the rounded border to the text. How can I achieve this?

suhasbhattu avatar Mar 28 '19 11:03 suhasbhattu

The only thing I found that works for creating padding on the outside is mainly the \t\t\t:

content: [
  {
    text: '\t\t\t\t\t\t\t\t\t\t\t\tText\t\t\t\t\t\t\t\t\t\t\t\t',
    style: ['header', 'background1'],
  },
],
styles: {
  background1: {
    background: '#5190a5'
  },
  header: {
    fontSize: 22,
    alignment: 'center',
    color: 'white',
  },
}

Dal-Tron avatar May 11 '19 22:05 Dal-Tron

+1

nastyamyalik avatar Jun 18 '20 12:06 nastyamyalik

Quick and dirty ... can also use a width test to measure content instead of passing width parameter

function makeTag(text = '', width = 30) { 
    let canvas = { 
        type: 'rect',
        x: 0, 
        y: 0, 
        w:width, 
        h: 14, 
        r: 7,
        color: '#990876',
        lineColor: '#B08BCD',
    }
    let column = {
        text, 
        width,
        color: '#FFFFFF',
        alignment:'center',
        noWrap: true, 
        maxHeight: 16,
        bold:true
    }
    return {
        stack: [
            { canvas:[canvas] },
            { columns:[column], 
              relativePosition: { y: -11 }, 
              style:{ fontSize:7, bold:true } 
            }
        ]
    } 
}

var dd = {
    content: [
        makeTag('Some tag', 40),
        makeTag('Some other', 50),
    ]
}