问题
I am Adding html to the pdf file. My html is in div form and that containing the style attribute which having the style like border:2px solid red; but this style is not applying to the html that i am writing to the pdf file.
i am using the following code :
Document document = new Document(PageSize.A4_LANDSCAPE, 0, 0, 30, 65);
PdfWriter.GetInstance(document, new FileStream(Server.MapPath("/") + "Temp/" + "parsetest1.pdf", FileMode.Create));
document.Open();
String htmlText = "<div style='border:4px solid red'>Welcome</div>";
StringReader abc = new StringReader(htmlText);
List<iTextSharp.text.IElement> elements = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(abc, null);
foreach (object item in elements)
{
document.Add((IElement)item);
}
document.Close();
回答1:
iText doesn't fully support CSS. It's getting better, particularly in the last couple releases, but is far from complete.
If you need Really Accurate HTML-PDF conversion, I suggest WKHTML2PDF. It's a command line app that is WebKit based. It's quite impressive... it'll run script event, so well that it can properly render a page containing a google map.
来源:https://stackoverflow.com/questions/6329942/how-to-apply-style-while-writing-html-to-pdf