Default font on PDF

Default font on PDF

Forum member · Nov 3, 2021
Hi Team, I have requirement to change default font on PDF. As I am using some place HTML area and not providing any font style on that. So is it possible to provide default setting for font. Thanks , Chandan Singh

Re: Default font on PDF

Support · Nov 3, 2021
Hi, Currently, there is no way to set a default font for the document along with HtmlArea. HtmlArea will have its own default font. You will have to specify the font in the HTML/CSS. If no font is specified then Arial will be used by default in HtmlArea. We may have an option to set the default fonts in HtmlArea in a future build, however, we do not have any specific timeline on this. Thanks, ceTe Software Support Team.

Re: Default font on PDF

Support · Dec 10, 2021
Hello, We have an update from our development team, and they have implemented a feature to set a custom fonts in an HtmlArea object in latest release, DynamicPDF Core Suite for .NET version 11.22. You can download latest version from NuGet (Package ID: ceTe.DynamicPDF.CoreSuite.NET) or from our website here . Please note that, if you don't specify a font for the HtmlArea and if the the HTML source does not have any font specified, then it will add content with the LiberationSans-Regular font (default font for HtmlArea). You can set a custom font using the FontSelecting event of HtmlArea. Here is a code sample: Document doc = new Document(); PageDimensions dimensions = new PageDimensions(PageSize.Letter, PageOrientation.Portrait, 72f); ceTe.DynamicPDF.Page page = new ceTe.DynamicPDF.Page(dimensions); string filePath = @"C:\Temp\Test.html"; Uri url = new Uri(filePath); Document document = new Document(); HtmlArea htmlArea = new HtmlArea(url, 0, 0, 530, 580); htmlArea.FontSelecting+=new HtmlAreaFontSelecting(htmlArea_FontSelecting); do { Page page = new Page(); page.Elements.Add(htmlArea); document.Pages.Add(page); htmlArea = htmlArea.GetOverflowHtmlArea(); } while (htmlArea != null); string output = @"C:\Temp\CustomFontForHtmlArea.pdf"; document.Draw(output); System.Diagnostics.Process.Start(output); static void htmlArea_FontSelecting(object sender, FontSelectingEventArgs e) { if (e.FontFamily == "serif" || e.FontFamily.Contains("Times")) { if (e.FontStyle == CssFontStyle.Italic && e.FontWeight >= 700) { e.Font = Font.TimesBoldItalic; } else if (e.FontStyle == CssFontStyle.Italic) { e.Font = Font.TimesItalic; } else if (e.FontWeight >= 700) { e.Font = Font.TimesBold; } else { e.Font = Font.TimesRoman; } } else if (e.FontFamily.Contains("Courier")) { if (e.FontStyle == CssFontStyle.Oblique && e.FontWeight >= 700) { e.Font = Font.CourierBoldOblique; } else if (e.FontStyle == CssFontStyle.Oblique) { e.Font = Font.CourierOblique; } else if (e.FontWeight >= 700) { e.Font = Font.CourierBold; } else { e.Font = Font.Courier; } } } Thanks, ceTe Software Support Team

Re: Default font on PDF

Forum member · Dec 13, 2021
Hi Team, I tried your code with my sample application, but its not working. Expected Font : TimeNewRoman Actual Font: LiberationSans -------------Sample Code----------------------- using ceTe.DynamicPDF; using ceTe.DynamicPDF.PageElements.Html; using System; namespace ConsolePDF { class Program { static void Main(string[] args) { Document doc = new Document(); PageDimensions dimensions = new PageDimensions(PageSize.Letter, PageOrientation.Portrait, 72f); ceTe.DynamicPDF.Page page = new ceTe.DynamicPDF.Page(dimensions); var testString = "<HTML><BODY><P align = center>This is my test sample</BODY></HTML>"; Document document = new Document(); HtmlArea htmlArea = new HtmlArea(testString, 0, 0, 530, 580); htmlArea.FontSelecting += new HtmlAreaFontSelecting(htmlArea_FontSelecting); do { Page page1 = new Page(); page1.Elements.Add(htmlArea); document.Pages.Add(page1); htmlArea = htmlArea.GetOverflowHtmlArea(); } while (htmlArea != null); string output = @"C:\Temp\CustomFontForHtmlArea.pdf"; document.Draw(output); } static void htmlArea_FontSelecting(object sender, FontSelectingEventArgs e) { if (e.FontStyle == CssFontStyle.Normal && e.FontWeight < 700) { e.Font = Font.TimesRoman; } } } } Thanks, Chandan Singh

Re: Default font on PDF

Support · Dec 22, 2021
Hi, We have an update from our development team and this issue is fixed in DynamicPDF Core Suite for .NET (v11.23). You can download latest version from NuGet(Package Id: ceTe.DynamicPDF.CoreSuite.NET) or from our website here Thanks, ceTe Software Support Team