我在变量中有html内容。
我想在按钮点击时使用 iTextSharp dll 创建 PDF文档。我在Google上搜索了我的PDF文档如何理解我的HTML内容,所以我得到了HTMLWorker,它可以工作,但我不知道它是如何工作的。
此代码如何用于创建PDF文档(可以理解我的HTML内容)。
在此代码中使用HTMLWorker类是什么。
如果还有其他更好的方法,那么请建议。
你能让我理解这段代码的过程吗?这对我来说非常重要。
Document PdfDoc = new Document(PageSize.A4);
PdfWriter write = PdfWriter.GetInstance(PdfDoc, Response.OutputStream);
TextReader reader = new StringReader(paragraphBlogContent.InnerText);
HTMLWorker worker = new HTMLWorker(PdfDoc);
PdfDoc.Open();
worker.StartDocument();
worker.Parse(reader);
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;" + "filename=sample.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Write(PdfDoc);
worker.EndDocument();
worker.Close();
PdfDoc.Close();