How to apply style while writing html to PDF

自作多情 提交于 2019-12-31 03:46:17

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!