Creating fonts from *.ttf files using iText

前端 未结 1 1610
Happy的楠姐
Happy的楠姐 2021-01-29 01:03

This is a method inside my Resources.class:

public static Font loadFont(String fontFileName)
    {
        BaseFont base = null;

        try
        {
                  


        
1条回答
  •  时光取名叫无心
    2021-01-29 01:48

    Try to create an embedded font object and use this font to render your text:

    //this code should run once at initialization/application startup
    FontFactory.register("resources/wingding_font.ttf");
    Font textFont = FontFactory.getFont("wingding", BaseFont.IDENTITY_H, 
        BaseFont.EMBEDDED, 10); //10 is the size
    ...
    //reuse the reference to the font object when rendering your text
    Paragraph p = new Paragraph("someText", textFont);
    

    By the way, iText has the FontFactory class to help load your fonts, you don't need anymore the loadFont method in your Resources.

    Hope it helps.

    0 讨论(0)
提交回复
热议问题