Skip to content

pratikmachchar/pdfmakecustomfont

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pdfmakecustomfont

How to add server side custom font inside a pdf page with pdfmake

To run type following commands

npm install

node index.js

Reference: Pdf make issue

How to add client side custom font inside a pdf page with pdfmake

  1. Add new fonts

Copy this shell script

Create a folder and copy new fonts you wish to add,

Add the default fonts supported by pdfmake from here

run the shell script to generate vfs_fonts.js

How to use script:

sh script.sh font1.ttf font2.ttf font3.ttf

for example

sh script.sh Roboto-Italic.ttf Roboto-Medium.ttf Roboto-MediumItalic.ttf Roboto-Regular.ttf Consolas.ttf sampleImage.jpg CONSOLAB.TTF
  1. Replace old vfs_fonts.js with the file created

  2. Define the fonts

pdfMake.fonts = {
        Roboto: {
                normal: 'Roboto-Regular.ttf',
                bold: 'Roboto-Medium.ttf',
                italics: 'Roboto-Italic.ttf',
                bolditalics: 'Roboto-MediumItalic.ttf'
        },
                Consolas: {
                 normal: 'Consolas.ttf',
                 bold: 'CONSOLSB.TTF',
                 italics: 'Consolas.ttf',
                 bolditalics: 'Consolas.ttf'
   },
};
  1. Use the font

docDefinition.push({
                columns:[
                  {
                    text: [
                      { text:candidate_name+"\n", fontSize: 10, bold:false},
                      { text:"DifferentFont : ",fontSize: 9,bold:false},
                      { text: differentData.data[k].passcode+"\n" ,fontSize: 11,font:'Consolas',bold:true},

                    ],
                    width: 150,
                    margin:[7,15,7,0]
                  },
                  {
                    image:candidate_img,
                    fit:[70,70],
                    width: 80,
                    margin:[15,5,0,0]
                  }
                ]
              });
pdfMake.createPdf(docDefinition)

Reference: PDFmake document clientside add font

About

How to add custom font server side inside pdf with pdfmake

Resources

License

Stars

1 star

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors