So i have a html file which contains custom fonts declared inside a <style></style>
tag
<!DOCTYPE html>
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<title>Something</title>
<style >
@font-face {
font-family: 'myfont';
src: url('myfont.eot') format('embedded-opentype'), url('myfont.woff') format('woff'), url('myfont.ttf') format('truetype');
}
.. other styles
</style>
</head>
<body style="font-family: myfont,Calibri, 'Trebuchet MS', sans-serif;">
Content ...
</body>
</html>
The fonts myfont
(.ttf and so on) are located in an another directory. When i try to read the html and convert it to a pdf the fonts are not loaded and embedded in the pdf.
string fontPath = "C:\\path\\to\\fonts\\"; // In the fonts folder the file are located ( myfont.eot ..)
var document = new DocumentModel();
var paragraph = new Paragraph(document);
var section = new Section(document);
var htmlLoadOptions = new HtmlLoadOptions
{
HtmlType = HtmlType.Html,
Encoding = Encoding.UTF8,
InheritCharacterFormat = true,
BaseAddress = fontPath
};
section.Content.LoadText(_htmlString, htmlLoadOptions);
document.Sections.Add(section);
String outputPath = "Output.pdf";
document.Save(outputPath);
What am I doing wrong? Do I need to still use FontSettings.FontsBaseDirectory
, which I tried but it didn’t work.