I am trying to generate PDF from below HTML i.e. a text with dotted underline. (Below is sample actual HTML is much bigger)
<u style="border-bottom: 1px dotted #000;text-decoration: none;"> Hello </u>
as explained in How to convert HTML to PDF using iTextSharp . The output is supposed to have a dotted line which I can see in the HTML file, however the PDF generated by iTextSharp shows a normal underline and not a dotted underline. Here is my complete method
public void UsingXMLWorker()
{
Byte[] bytes;
//Create a stream that we can write to, in this case a MemoryStream
using (var ms = new MemoryStream())
{
using (var doc = new Document())
{
//Create a writer that's bound to our PDF abstraction and our stream
using (var writer = PdfWriter.GetInstance(doc, ms))
{
//Open the document for writing
doc.Open();
//sample HTML and CSS
var example_html = @"<u style=""border-bottom: 1px dotted #000;text-decoration: none;"" > Hello </u>";
using (var srHtml = new StringReader(example_html))
{
//Parse the HTML
iTextSharp.tool.xml.XMLWorkerHelper.GetInstance().ParseXHtml(writer, doc, srHtml);
}
//var example_html = @"<u class=""dottedBorder""> Hello </u>";
//var example_css = @".dottedBorder{border-bottom: 1px dotted #000;text-decoration: none;font-size:38px;}";
//using (var msCss = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(example_css)))
//{
// using (var msHtml = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(example_html)))
// {
// //Parse the HTML
// iTextSharp.tool.xml.XMLWorkerHelper.GetInstance().ParseXHtml(writer, doc, msHtml, msCss);
// }
//}
doc.Close();
}
}
bytes = ms.ToArray();
}
var testFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test.pdf");
System.IO.File.WriteAllBytes(testFile, bytes);
}
I even tried other methods like below code still I see a PDF generated with a normal underline as opposed to a dotted underline. What I am missing here ?
var example_html = @"<u class=""dottedBorder""> Hello </u>";
var example_css = @".dottedBorder{border-bottom: 1px dotted #000;text-decoration: none;font-size:38px;}";
using (var msCss = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(example_css)))
{
using (var msHtml = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(example_html)))
{
//Parse the HTML
iTextSharp.tool.xml.XMLWorkerHelper.GetInstance().ParseXHtml(writer, doc, msHtml, msCss);
}
}