pdfmake icon indicating copy to clipboard operation
pdfmake copied to clipboard

pdfmake - how do you make labels?

Open jayiconcmo opened this issue 10 years ago • 8 comments

We have an online webapp, which we use pdfmake for reports. However we also want to do labels. We do have the label data going to a report size pdf right now. How can that be reduced to make a label? Or what is the best way to do this? I am very new to pdfmake, so please take that into consideration when answering. :)

jayiconcmo avatar Jun 30 '16 19:06 jayiconcmo

+1

umaganesan avatar Jun 30 '16 21:06 umaganesan

If I correctly understand, you want to adjust the page size of your PDF? see http://pdfmake.org/#/gettingstarted at the bottom of the page If your need is to make a page with many labels on it, you should consider the columns property : for example, something like {columns : [{text : 'mylabel1'},{text : 'mylabel2'},{text : 'mylabel2'}]} would put 3 labels on a line. Hope it helps...

bhericher avatar Jul 01 '16 13:07 bhericher

@bhericher So for labels (single) the recommended way of doing that is something like pageSize: { width: 2.4 * 72, height: 1.8 * 72 }

And if you want to run multiple labels would the page size just be a full sheet? If so what else is needed to get {text : 'mylabel1'} put into the label one position and {text : 'mylabel2'} in the second position. The reason I ask this is because label vary in width (and height).

Also What is the measurement in when you are doing the 2.4 or 1.8 like above? I'm not sure what pdfmake uses as their measurement

jayiconcmo avatar Jul 01 '16 13:07 jayiconcmo

For multiple labels can be used table.

liborm85 avatar Apr 15 '17 11:04 liborm85

After this being closed, I would assume that pdfmake can't make a full sheet of labels because you can't set a column property for the various sizes?

jayiconcmo avatar Apr 17 '17 12:04 jayiconcmo

Example with table:

var dd = {
	content: [
		{
			table: {
			    widths: [150, 100, 120],
				body: [
					[{text : 'mylabel1'}, {text : 'mylabel2'}, {text : 'mylabel3'}],
					[{text : 'mylabel4'}, {text : 'mylabel5'}, {text : 'mylabel6'}],
				]
			}
		},
	]
}

Width of columns can be set by using widths property; and height is by content.

liborm85 avatar Apr 17 '17 13:04 liborm85

Thank you so much, just what we needed 👍 here at nickysoft

nickysoft avatar Nov 18 '17 19:11 nickysoft

Hello liborm85, i Know that is an old question. But i need help to make labels dynamically, the labels suppose to be horizontal 5 by row My Code: `static label(tob: any[]) {

return {

  content: [
    {

      table: {
        headerRows: 0,
        heights: [50],
        widths: [100, 100, 100, 100, 100, 100],
        body: [
          

          ...tob.map(
            (sp) => {
              return [
                {
                  height: 150,
                  width: 50,
                  fillColor: '#bada55',
                  // pageBreak: 'after',
                  text: [
                    {
                      text: sp.name + '\n'
                    },
                    {
                      text: sp.product + '\n'
                    },
                    {
                      text: sp.pp + '\n'
                    },
                    {
                      // text: sp.saleDate + '\n'
                      text: 'sp.saleDate' + '\n'
                    },
              ]
            }
        ];

          }),
        ]


      }
    },

  ]
};

}` and what I'm experting in red

Capture d’écran 2020-01-28 à 17 42 47

stingers avatar Jan 28 '20 17:01 stingers