Click here to Skip to main content
15,909,030 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
this is code

 <div style="font-family: Arial; background-color:black;">This is a test page</div>
    <div>
        <table border="1" width="100">
            <tr>
                <td>Name</td>
                <td>Age</td>
            </tr>
            <tr>
                <td>John</td>
                <td>11</td>
            </tr>
            <tr>
                <td>Sam</td>
                <td>13</td>
            </tr>
            <tr>
                <td>Tony</td>
                <td>12</td>
            </tr>
        </table>
    </div>
    <div>
        <asp:Button ID="btnExport" runat="server" Text="Export" OnClick="btnExport_Click" />
    </div>



and code behind is this

  protected void btnExport_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();
        }

file is getting downloaded but background color which i have given in div style="font-family: Arial; background-color:black;">This is a test page</div>
is not coming what is the issue !!??
Posted

1 solution

Hi

Try the below code . Mark it as answer if it resolves.

http://forums.asp.net/t/1670886.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900