我已经使用 itextsharp.dll 将 html 转换为 Pdf。它工作正常,唯一的问题是它不会在 pdf 中呈现 css。我的代码如下:
string[] attachment;
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Certificate.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
System.Text.StringBuilder ss = new System.Text.StringBuilder(CertificateHtml);
StringWriter sw = new StringWriter(ss);
HtmlTextWriter hw = new HtmlTextWriter(sw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
string PdfName = "Certificate" + name;
PdfWriter.GetInstance(pdfDoc, new FileStream(Server.MapPath("~/DesktopModules/SterlingPlanet-SP_CheckOut/PDfCertificate/" + PdfName + ".pdf"), FileMode.Create));
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
我的 CSS 很傻
body {
font-family: Conv_Californian FB,Arial;
margin: 0;
padding: 0;
}
#wrapper {
background: url("../images/bg.jpg") no-repeat scroll 0 0 transparent;
height: 719px;
margin: 25px auto 0;
position: relative;
width: 959px;
}
.wrapper_inner {
color: White;
text-align: center;
width: 100%;
}
.wrapper_inner h1 {
color: #FFFFFF;
font-size: 65px;
letter-spacing: 16px;
padding-top: 38px;
text-align: center;
}
.wrapper_inner h6 {
color: #FFFFFF;
font-size: 17px;
letter-spacing: 10px;
margin: -53px;
text-align: center;
}
是否有任何替代 itextsharp.dll 的方法可以使用 css 将 html 转换为 pdf,或者如果我缺少任何可以将 css 呈现为 html.Kindly 帮助的代码。