2

I am attempting to convert a tag Label of my webpage to pdf.

While the pdf generation is working correctly, none of the css styles are being applied.

I've tried applying the styles one at a time, but that doesn't seem to work.

How can we create a pdf file from html with textbox controls with CSS styles ?

My code below.

Please help me, thank you in advance.

<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();
    }
Antonio Mailtraq
  • 1,397
  • 5
  • 34
  • 82

0 Answers0