C# 如何将css应用于html到pdf转换过程?

C# 如何将css应用于html到pdf转换过程?,c#,asp.net,.net,pdf,itextsharp,C#,Asp.net,.net,Pdf,Itextsharp,我使用iTextSharp将pdf从HTML转换为内嵌Css,但Css不适用 divPDF.InnerHtml = "<ul style="float:none;width:100%;display:block;list-style:none;margin:0 0 20px 0;padding:0;clear:both"><li style="text-indent:0;"><label style="float:left;w

我使用iTextSharp将pdf从HTML转换为内嵌Css,但Css不适用

                    divPDF.InnerHtml = "<ul style="float:none;width:100%;display:block;list-style:none;margin:0 0 20px 0;padding:0;clear:both"><li style="text-indent:0;"><label style="float:left;width:50%;">Additional Medicare tax (1.45%  + .9%)</label>P1_F1</li><li style="text-indent:0;"><label style="float:left;width:50%;">Additional Obamacare Medicare tax (3.8%)</label>P1_F2</li></ul>";

                    Response.ContentType = "application/pdf";
                    Response.AddHeader("content-disposition", "attachment;filename=Panel.pdf");

                    Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    StringWriter sw = new StringWriter();
                    HtmlTextWriter hw = new HtmlTextWriter(sw);
                    divPDF.RenderControl(hw);
                    StringReader sr = new StringReader(sw.ToString());
                    Document pdfDoc = new Document(PageSize.A4);

                    HTMLWorker htmlparser = new HTMLWorker(pdfDoc);

                    PdfWriter.GetInstance(pdfDoc, Response.OutputStream);


                    pdfDoc.Open();
                    htmlparser.Parse(sr);
                    pdfDoc.Close();
                    Response.Write(pdfDoc);
                    Response.End();
divPDF.InnerHtml=“
  • 附加医疗保险税(1.45%+0.9%)P1_F1
  • 额外的奥巴马医改医疗保险税(3.8%)”; Response.ContentType=“application/pdf”; AddHeader(“内容处置”、“附件;文件名=Panel.pdf”); Response.Cache.SetCacheability(HttpCacheability.NoCache); StringWriter sw=新的StringWriter(); HtmlTextWriter hw=新的HtmlTextWriter(sw); divPDF.RenderControl(hw); StringReader sr=新的StringReader(sw.ToString()); 文档pdfDoc=新文档(页面大小为A4); HTMLWorker htmlparser=新的HTMLWorker(pdfDoc); GetInstance(pdfDoc,Response.OutputStream); pdfDoc.Open(); 解析(sr); pdfDoc.Close(); 响应写入(pdfDoc); Response.End();
在使用HTMLWorker时,请参见此图。此类已被弃用,取而代之的是XML Worker: