I’m using v17.9 running MVC .net application.
I’m having issues on loading the fonts while converting HTML to PDF. Here is the code I’m using-
var basePath = HttpContext.Current.Request.Url.Scheme + “://” + HttpContext.Current.Request.Url.Authority;
var htmlOptions = new HtmlLoadOptions(basePath);
htmlOptions.PageInfo.Height = 725;
htmlOptions.PageInfo.Width = 792;
htmlOptions.PageInfo.Margin.Left = 10;
htmlOptions.PageInfo.Margin.Right = 10;
htmlOptions.PageInfo.Margin.Top = 75;
htmlOptions.PageInfo.Margin.Bottom = 20;
var pdf = new Document(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(htmlString)), htmlOptions);
var headerHtml = new HtmlFragment(headerHTML);
HeaderFooter hf;
foreach (Aspose.Pdf.Page page in document.Pages)
{
hf = new Aspose.Pdf.HeaderFooter();
hf.Paragraphs.Add(headerHtml);
page.Header = hf;
if(page.Resources.Fonts != null)
{
foreach(Aspose.Pdf.Text.Font pageFont in page.Resources.Fonts)
{
if (!pageFont.IsEmbedded)
pageFont.IsEmbedded = true;
}
}
}
pdf.Save(dataDir + “Output.pdf”);
I’m referencing my style.css file from my razor(cshtml) file. I’m copy pasting a sample of how the font-family is defined in my style.css. I want to use 3 different fonts in the pdf file (I have all .otf font files placed in the same directory as the stylesheet)
@font-face {
font-family: ‘HelveticaNeueLTStd-BdCnO’;
src: url(‘HelveticaNeueLTStd-BdCnO.otf’) format(‘opentype’);
}
@font-face {
font-family: ‘HelveticaNeueLTStd-MdCn’;
src: url(‘HelveticaNeueLTStd-MdCn.otf’) format(‘opentype’);
}
@font-face {
font-family: ‘HelveticaNeueLTStd-Roman’;
src: url(‘HelveticaNeueLTStd-Roman.otf’) format(‘opentype’);
}
I can load all the styles except that it is not loading the proper font-families in the pdf file.
Thanks.