我正在使用iTextSharp库将网页转换为PDF文档 虽然文档已成功生成,但网页上应用的CSS未应用于PDF。
示例代码:
using (MemoryStream stream = new MemoryStream())
{
Gridhtml = Gridhtml.Replace("\n", "").Replace("\r", "");
System.IO.File.WriteAllText(System.Web.HttpContext.Current.Server.MapPath("~/Content/HtmlTable/HtmlTableMarkup.txt"),Gridhtml);
StreamReader sr = new StreamReader(System.Web.HttpContext.Current.Server.MapPath("~/Content/HtmlTable/HtmlTableMarkup.txt"));
Document pdfdoc = new Document(PageSize.A4,10f,10f,100f,0f);
PdfWriter pdfw = PdfWriter.GetInstance(pdfdoc,stream);
pdfdoc.Open();
XMLWorkerHelper.GetInstance().ParseXHtml(pdfw,pdfdoc,sr);
pdfdoc.Close();
return File(stream.ToArray(), "applicationpdf", "Grid.pdf");
}
如何获得与网页具有相同样式的PDF?