Generate PDF with specific font

2

I have a report that already works. I need to change the font to "Garamond" (already installed). The references found talk about other more flexible properties, for example, changing the font "per family" tuto 1 , or by removing a watermark (which can also be text) code project tutorial .

An example of the context is that Times New Roman is called nominally, since the class enumerator Font already has the same related:

Font timesBold = new Font(Font.FontFamily.TIMES_ROMAN, fontSize_small, Font.BOLD, BaseColor.BLACK);
Font timesNormal = new Font(Font.FontFamily.TIMES_ROMAN, fontSize_small, Font.NORMAL, BaseColor.BLACK);

I need to get a way to generate the pdf by passing, for example, the name of the source (Garamond , Curlz, etc.). A good reason to use the Garamond font would be to save ink, since it has the pixels "more spaced" and therefore less ink is used.

    
asked by anonymous 27.08.2014 / 20:18

1 answer

2

Solution:

// Se a fonte não está registrada
if (!FontFactory.IsRegistered("Garamond"))
{
     // Registro a fonte
     FontFactory.RegisterFamily("Garamond", "Garamond", @"C:\Windows\Fonts");
     // Registro o diretório(não tinha funcionado até tentar isso...)
     FontFactory.RegisterDirectories();                
}                

// Faço a atribuição normalmente
Font garamondBold = FontFactory.GetFont("Garamond", 12, 1); 
Font garamondNormal = FontFactory.GetFont("Garamond");

Sample:

Thanks for your help

    
28.08.2014 / 20:49