Skip to content Skip to sidebar Skip to footer

Apply Custom Font To Html In Itextsharp

I have code FontFactory.Register(Server.MapPath('includes/fonts/Rockwell-Light.ttf')); StyleSheet style = new StyleSheet(); style.LoadTagStyle('div', 'face', 'customfont')

Solution 1:

I have been able to implement custom fonts via HTML in iTextSharp using the following code:

Step 1: Copy your font files to a subdirectory of your website, for my purposes I used "/media/fonts"

Step 2: Register the directory using the code below:

FontFactory.RegisterDirectory(C.Server.MapPath("/Media/Fonts"));

Step 3: Loop through all of the fonts in the FontFactory object to get the font's name:

StringBuilder sb = new StringBuilder();
        foreach (string fontname in FontFactory.RegisteredFonts)
        {

            sb.Append(fontname + "\n");

        }

Step 4: Add the font name via a font-family style attribute:

YOURDIVNAME.Attributes.Add("style", "font-family: brush script mt italic;");

Solution 2:

BaseFontrockwellBold= BaseFont.CreateFont(Server.MapPath("includes/fonts/") + "ROCKB.TTF", BaseFont.CP1250, BaseFont.EMBEDDED);
Fontrock_11_bold_header=newFont(rockwellBold, 11, Font.NORMAL, newBaseColor(190, 36, 34));
PdfPCelldescHeadrCell=newPdfPCell();
descHeadrCell.AddElement(newPhrase("Demo"), rock_11_bold_header));

Post a Comment for "Apply Custom Font To Html In Itextsharp"