No Change In Font Face In Html To Pdf Generation Using Itextsharp
Solution 1:
The simplest, brute-force way is to call FontFactory.RegisterDirectories()before calling HTMLWorker.ParseToList()
. Be warned, however - the method attempts to register/map all fonts on the running system.
So if you're running this in ASP.NET, for example, you probably want to put the call in global.asax.
EDIT: Working example using FontFactory.RegisterDirectories()
and the HTML you provided above:
FontFactory.RegisterDirectories();
using (Documentdocument = newDocument()) {
PdfWriter.GetInstance(document, Response.OutputStream);
document.Open();
List<IElement> objects = HTMLWorker.ParseToList(
newStringReader(html), null);
foreach (IElement element in objects) {
document.Add(element);
}
}
Just substitute Response.OutputStream
with the Stream
of your choice. Result PDF file from above.
Solution 2:
HTMLWorker is obsolete. You need to switch to the new XMLWorker class. But if you want to use the HTMLWorker, you can define a global style for it as well:
StyleSheetstyles=newStyleSheet();
styles.LoadTagStyle(HtmlTags.BODY, HtmlTags.FONTFAMILY, "tahoma");
//...//and thenvarparsedHtmlElements= HTMLWorker.ParseToList(data, styles);
Solution 3:
there you can get the last version of iTextSharp(5.4.1) Library
and here is the XML worker... it only works with the same version of iTextSharp (5.4.1)
Post a Comment for "No Change In Font Face In Html To Pdf Generation Using Itextsharp"