0

我使用 iTextSharp 使用内联 Css 从 HTML 转换 pdf,但 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();
4

0 回答 0