输入字符串格式不正确时出错

Ish*_*han 4 c# asp.net itextsharp

单击按钮时出现以下错误 输入字符串的格式不正确,

点击按钮我调用以下方法:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using System.IO;
using iTextSharp.text.html.simpleparser;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
/// <summary>
/// Summary description for pdfgeneration
/// </summary>
public class pdfgeneration
{
    public pdfgeneration()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    public void pdfgenerator(String name1, AjaxControlToolkit.HTMLEditor.Editor Editor1)
    {

        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.ContentType = "application/pdf";
        // Create PDF document
        Document pdfDocument = new Document(PageSize.A4, 70, 55, 40, 25);

        PdfWriter wri = PdfWriter.GetInstance(pdfDocument, new FileStream("e://" +name1 + ".pdf", FileMode.Create));

        PdfWriter.GetInstance(pdfDocument, HttpContext.Current.Response.OutputStream);

        pdfDocument.Open();
        string htmlText = Editor1.Content;
        System.Collections.Generic.List<IElement> htmlarraylist = HTMLWorker.ParseToList(new StringReader(htmlText), null);

        for (int k = 0; k < htmlarraylist.Count; k++)
        {
            pdfDocument.Add((IElement)htmlarraylist[k]);
        }

        pdfDocument.Close();
        HttpContext.Current.Response.End();
    }

}
Run Code Online (Sandbox Code Playgroud)

堆栈跟踪是:

[FormatException: Input string was not in a correct format.]
   System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +7471335
   System.Number.ParseSingle(String value, NumberStyles options, NumberFormatInfo numfmt) +115
   System.Single.Parse(String s, NumberStyles style, NumberFormatInfo info) +192
   iTextSharp.text.html.simpleparser.CellWrapper..ctor(String tag, ChainedProperties chain) +148
   iTextSharp.text.html.simpleparser.HTMLTagProcessor_TD.StartElement(HTMLWorker worker, String tag, IDictionary`2 attrs) +84
   iTextSharp.text.html.simpleparser.HTMLWorker.StartElement(String tag, Dictionary`2 attrs) +79
   iTextSharp.text.xml.simpleparser.SimpleXMLParser.ProcessTag(Boolean start) +30
   iTextSharp.text.xml.simpleparser.SimpleXMLParser.Go(TextReader reader) +1008
   iTextSharp.text.xml.simpleparser.SimpleXMLParser.Parse(ISimpleXMLDocHandler doc, ISimpleXMLDocHandlerComment comment, TextReader r, Boolean html) +48
   iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(TextReader reader, StyleSheet style, IDictionary`2 tags, Dictionary`2 providers) +94
   iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(TextReader reader, StyleSheet style) +9
   pdfgeneration.pdfgenerator(String name1, Editor Editor1) in C:\inetpub\wwwroot\dcis\App_Code\pdfgeneration.cs:37
   EntryForm.Button4_Click(Object sender, EventArgs e) in C:\inetpub\wwwroot\dcis\EntryForm.aspx.cs:224
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个错误?

@ geek在他发布的代码中出错

在此输入图像描述

ash*_*ish 9

我面临同样的错误,"输入字符串的格式不正确." ,我检查我的html字符串,发现,如果我写样式标签之外的表宽度,我得到这个错误,例如,: - 在htmlWorker.Parse()方法给出错误.

当我在样式标签中放置宽度标签时,我解决了这个错误,例如,

我希望,这对你有所帮助.

For eg, <table width="610px"> </table> :- Give error at htmlWorker.Parse() method.
Run Code Online (Sandbox Code Playgroud)

当我在样式标签中放置宽度标签时,我解决了这个错误,

For eg, <table style="width:610px"> </table>
Run Code Online (Sandbox Code Playgroud)

我希望,这对你有所帮助.