0
我有我的頭版這樣頂部的標題:如何使用iTextSharp保存CSS?
我使用iTextSharp的代碼來生成PDF它......但生成的PDF不包含這個頭搭配黑色:代替一些CSS是寫在地方頭部像這樣:
我怎麼可能解決這個問題?
代碼:
protected void BtnPDF_Click(object sender, EventArgs e)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=TestPage.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
this.Page.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
}
CSS不'HTMLWorker'支持。您需要XML Worker:http://itextpdf.com/sandbox/xmlworker –