i am trying to convert a html file into pdf. in the CSS it contain some custom font.
i tried with the following code but result in Font ‘Lato’ not found exception
FontRepository.Sources.Add(new FolderFontSource(FontFolder));
FontRepository.FindFont(@"Lato", true);
HtmlLoadOptions loadOptions = new HtmlLoadOptions();
loadOptions.PageInfo.Margin.Top = 32;
loadOptions.PageInfo.Margin.Bottom = 32;
loadOptions.PageInfo.Margin.Left = 32;
loadOptions.PageInfo.Margin.Right = 32;
loadOptions.PageInfo.Height = PageSize.A4.Height;
loadOptions.PageInfo.Width = PageSize.A4.Width;
I have attached my font files inside the attached zip
Relavant Files
SampleFile.zip (70.4 KB)
@bczm8703
Have you tried installing the required font in the system? Please try installing it properly and make sure that its present in the default Fonts folder. Let us know in case issue still persists.
i have limited access to the server. is it possible to load the font file instead of installing the font?
@bczm8703
You can use FontRepository.OpenFont() method in order to load font from file.
HI. i tried using OpenFont but I am receiving an exception Unable to determined font type. I tried setting FontTypes but it seems like only TTF and OTF is available. is there any way to use woff2?
hi… i tried installing the font on a dev server to test. after installing the font, i am still getting the font not found exception
LatoFont.png (22.5 KB)
@bczm8703
Can you please share your font file with us in .zip format as well? We will test the scenario in our environment and address it accordingly.
Attached is the font file used
fonts.zip (100.1 KB)
hi, i am able to use find font when I load the font folder using the following
FontRepository.Sources.Add(new FolderFontSource(FontFolder));
Font boldFont = FontRepository.FindFont("latobold", true);
Font regFont = FontRepository.FindFont("latoregular", true);
But it seems that the alignment will be off. I have include an attached with the code use when installing font and without installing the font
Sample files.zip (2.4 KB)
@bczm8703
Please check the attached PDF generated in our environment using Aspose.PDF for .NET 22.11. We could not notice any alignment issue in it. Can you please share a screenshot to show where the alignment is off? HtmlFragmentwithCustomFont.pdf (192.2 KB)
Please see attached for the 2 scenarios
AsposeAlignment.jpg (42.4 KB)
@bczm8703
An issue as PDFNET-53164 has been logged in our issue tracking system for the sake of further investigation. We will look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.
We are sorry for the inconvenience.