Pdfmake: How to place icons in pdfmake? Is there any Solution

Created on 12 Apr 2017  Â·  1Comment  Â·  Source: bpampuch/pdfmake

How to place icons in pdfmake? Is there any Solution

Most helpful comment

I use an icon font. Complicated but possible.

In short:

  • Make a font at http://fontello.com/ or something and download it
  • convert to dataURL (e.g. via http://dataurl.net/#dataurlmaker )
  • add to the fs_js example like the robot font already in there (you can replace or remove the roboto) (strip the "data:application/octet-stream;base64," part from the beginning)
  • define font in js (just defining normal might be enough):
        pdfMake.fonts = {
            Fontello: {
                normal: 'fontello.ttf',
                bold: 'fontello.ttf',
                italics: 'fontello.ttf',
                bolditalics: 'fontello.ttf'
            }
        }
  • add a style for icons:
    icon: { font: 'Fontello' }
  • make a text paragraph:
    { text: '', style: 'icon' }, //icon wifi
  • as the text you copy from the fontello-codes.css from the comments (not the escaped value)

  • if you need an icon within text, you need to nest text objects:
                            text: [
                                    { text: 'î ƒ', style: 'icon' }, //icon gift
                                    " my present"
                                ]

this puts out: "[gift icon] my present"

>All comments

I use an icon font. Complicated but possible.

In short:

  • Make a font at http://fontello.com/ or something and download it
  • convert to dataURL (e.g. via http://dataurl.net/#dataurlmaker )
  • add to the fs_js example like the robot font already in there (you can replace or remove the roboto) (strip the "data:application/octet-stream;base64," part from the beginning)
  • define font in js (just defining normal might be enough):
        pdfMake.fonts = {
            Fontello: {
                normal: 'fontello.ttf',
                bold: 'fontello.ttf',
                italics: 'fontello.ttf',
                bolditalics: 'fontello.ttf'
            }
        }
  • add a style for icons:
    icon: { font: 'Fontello' }
  • make a text paragraph:
    { text: '', style: 'icon' }, //icon wifi
  • as the text you copy from the fontello-codes.css from the comments (not the escaped value)

  • if you need an icon within text, you need to nest text objects:
                            text: [
                                    { text: 'î ƒ', style: 'icon' }, //icon gift
                                    " my present"
                                ]

this puts out: "[gift icon] my present"

Was this page helpful?
0 / 5 - 0 ratings

Related issues

CharlyPoppins picture CharlyPoppins  Â·  3Comments

MathLavallee picture MathLavallee  Â·  3Comments

qgliu picture qgliu  Â·  3Comments

Christian24 picture Christian24  Â·  3Comments

davidyeiser picture davidyeiser  Â·  3Comments