I'm using a HTML Rich-Text Editor to help me create a template for dynamic PDF reports, and it's working fine except that it doesn't change the font-face.
This editor is using the font tag instead of CSS styles, and I would welcome any way to programmatically change the font tags to equivalent tags using styles instead.
HTML (yes its messy, its from a WYSIWYG editor):
<div>
<br>
<div align="center">
<font size="5">
<b>
<br>
<div align="center">
<font font-face="Times New Roman" size="5">
<b>Example
<font size="6">Chamber
<font size="5">
<font size="4">Website</font>
</font></font>Quotes</b>
</font>
<font face="Times New Roman">
<br>
<font face="Times New Roman">
<br>~
<font face="Times New Roman" color="#0000FF">
<b>
<u> [!PlanName] </u></b>
</font>
<font face="Times New Roman">
<br>~
<font face="Times New Roman" color="#0000FF">
<b> </b>
</font>
<font face="Times New Roman" color="#0000FF">
<b>
<font color="#000000">Deductible
$[!PlanDeductible]: </font></b>
</font>
<font face="Times New Roman" color="#B0B0FF">
[!PlanRate]
<br>
<font face="Times New Roman">/~/~</font>
<br>
<br>
<br>
<font face="Courier New" size="1">
Copyright Example.com</font>
<br>
<br>
<font face="Arial">test</font>
<br></br>
</br>
</br>
</br>
</br>
</br>
</br></font></br>
</font></br>
</font>
</br>
</font>
</div>
</br>
</b>
</font>
</div>
</br></div>
C#:
public static byte[] ConvertHtmlToPdf(string html)
{
html = HtmlPostProcessor.Process(html);
byte[] fileData = null;
string tempPath = ConfigurationManager.AppSettings["TempDirectory"];
string tempPDFFile = Path.Combine(tempPath, Guid.NewGuid() + ".pdf");
Document document = new Document(PageSize.LETTER, 50, 50, 50, 50);
using (FileStream fs = new FileStream(tempPDFFile, FileMode.Create))
{
PdfWriter.GetInstance(document, fs);
using (StringReader stringReader = new StringReader(html))
{
List<IElement> parsedList = HTMLWorker.ParseToList(stringReader, null );
document.Open();
foreach (IElement item in parsedList)
{
document.Add(item);
}
document.Close();
}
}
FileStream generatedPDF = File.Open(tempPDFFile, FileMode.Open);
fileData = new byte[(int)generatedPDF.Length];
int result = generatedPDF.Read(fileData, 0, (int)generatedPDF.Length);
generatedPDF.Close();
File.Delete(tempPDFFile);
return fileData;
}
EDIT
I've been using iTextSharp version 5.1.1.0.