can someone fix the code below html CSS. (it convert the html textbox to PDF fil
ID: 3694825 • Letter: C
Question
can someone fix the code below html CSS. (it convert the html textbox to PDF file) <asp:Label ID="UserID" runat="server" BorderStyle="Double"></asp:Label> private void PdfFiles() { Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=" + Decrypt(Request.QueryString["id"].ToString()) + ".pdf"); Response.Cache.SetCacheability(HttpCacheability.NoCache); StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); panelView.RenderControl(hw); StringReader sr = new StringReader(sw.ToString()); Document pdfDoc = new Document(PageSize.A4, 40f, 10f, 10f, 10f); HTMLWorker htmlparser = new HTMLWorker(pdfDoc); PdfWriter.GetInstance(pdfDoc, Response.OutputStream); pdfDoc.Open(); htmlparser.Parse(sr); pdfDoc.Close(); Response.End(); }
Explanation / Answer
Answer:
This code wont work in ASP
you need itextsharp for CSS contents to work.
Export the html div contents to pdf using itextsharp.
Or you can use wkhtml to pdf tool which is a better html rendering engine.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.