2
誰能告訴我如何使用C#從HTML代碼轉換PDF文檔?我使用的是itextsharp 5.0.2 dll。我遇到過這個論壇。到目前爲止我沒有找到任何解決方案。其中一些人提到iTextSharp.HtmlParser,但我無法在我的dll版本中找到這樣的類。我需要使用哪個版本來完成我的任務。如何使用C#將HTML轉換爲HTML?
我試過這段代碼...我不知道我做了什麼錯誤?我沒有得到PDF文件。
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=TestResult.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringBuilder htmlText =
new StringBuilder("<table style='color:red;' border='1'>");
htmlText.Append("<tr><th>Karunagara Pandi</th><tr><td> Software Engineer</td></tr></table>");
StringReader stringReader = new StringReader(htmlText.ToString());
Document doc = new Document(PageSize.A4);
List<iTextSharp.text.IElement> elements =
iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(stringReader, null);
doc.Open();
foreach (object item in elements)
{
doc.Add((IElement)item);
}
// Response Output
PdfWriter.GetInstance(doc, Response.OutputStream);
doc.Open();
//doc.Close();
Response.Write("PDF is created");
此代碼也僅此網站採取....我需要你的妥善解決。我也試着去.....
謝謝。