locked
Right border only to html <td> element RRS feed

  • Question

  • User1623409651 posted

    Hi all

    I have to give right side border to <td> element  when export to pdf using below code . 

    StringBuilder sb = new StringBuilder();
                sb.Append("<table width='370' style='border-collapse: collapse;'>");
                sb.Append("<tr>");
                sb.Append("<td style='border-right: 1px solid #000000;'>Matriculation</td>");
                sb.Append("<td style='border-right: 1px solid #000000;'>BISE</td>");
                sb.Append("<td>A</td>");
                sb.Append("</tr>");            
                sb.Append("</table>");
                Response.ContentType = "application/pdf";
                Response.AddHeader("content-disposition", "attachment;filename= Env_Report.pdf");
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                StringReader sr = new StringReader(sb.ToString());
                Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 50f, 0f);
                HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
                PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
                pdfDoc.Open();
                htmlparser.Parse(sr);
                pdfDoc.Close();
                Response.Write(pdfDoc);
                Response.End();

    Any Suggestion?

    Tuesday, January 22, 2019 10:47 AM

All replies

  • User839733648 posted

    Hi Rameezwaheed,

    According to your description, I suggest that you could  modify the style of border like below.

    border="1"

    Since solid and px is not working in html to pdf.

    My testing code.

        <form id="form1" runat="server">
            <asp:Button runat="server" Text="ClickToPDF" OnClick="ClickToPDF" />
        </form>
    protected void ClickToPDF(object sender, EventArgs e)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("<table width='370' style='border-collapse: collapse;'>");
                sb.Append("<tr>");
                sb.Append("<td border='1'>Matriculation</td>");
                sb.Append("<td border='1'>BISE</td>");
                sb.Append("<td>A</td>");
                sb.Append("</tr>");
                sb.Append("</table>");
                Response.ContentType = "application/pdf";
                Response.AddHeader("content-disposition", "attachment;filename= Env_Report.pdf");
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                StringReader sr = new StringReader(sb.ToString());
                Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 50f, 0f);
                HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
                PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
                pdfDoc.Open();
                htmlparser.Parse(sr);
                pdfDoc.Close();
                Response.Write(pdfDoc);
                Response.End();
            }

    result:

    Best Regards,

    Jenifer

    Wednesday, January 23, 2019 8:31 AM
  • User1623409651 posted

    Thank you for your reply.

    But I only want to give right border to td  not the all borders . border = 1 give the all side border.

    Is it possible to give the right border only?

    Regards

    Wednesday, January 23, 2019 8:47 AM
  • User1623409651 posted

    Any suggestion or Idea how will be possible to give the right border only to html td in string builder when export to pdf using itextsharp

    Thanking you

    Friday, January 25, 2019 9:47 AM