Giter Club home page Giter Club logo

pdfmakecustomfont's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.