2

Here iam trying to convert the content inside html div tag to pdf i found the following error:

Input string was not in a correct format is occur

Here is the code i tried using c#:

    divexcel.Visible = true;
    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);
    divexcel.RenderControl(hw);
    StringReader sr = new StringReader(sw.ToString());
    Document pdfDoc = new Document(PageSize.A4, 80f, 80f, -2f, 35f);
    HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
    PdfWriter writer = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
    pdfDoc.Open();
    //head.WriteSelectedRows(0, -1, page.Width / 8, page.Height - pdfDoc.TopMargin + head.TotalHeight, writer.DirectContent);
    //pdfDoc.Add(headerTbl);   
    htmlparser.Parse(sr);
    pdfDoc.Close();
    Response.Write(pdfDoc);
    Response.End();
------------------------------------------

Here is my html code

<div id="divexcel" runat="server">
    <table id="tbDetails" width="800px">
    <thead >
    <tr>
    <td></td>
    <td></td>
    <td></td>
    </tr>
    </thead>
    <tbody>
    </tbody>
    </table>
    </div>
2
  • Which line gives you this error? Commented Oct 24, 2013 at 12:26
  • htmlparser.Parse(sr); Commented Oct 24, 2013 at 17:17

1 Answer 1

1

Try to replace width="800px" on width="800". Should work

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.