locked
itextsharp with CSS RRS feed

  • Question

  • User-1698479530 posted

    hi 

    i try to make itextsharp with loadstyle but it wont work.

      Dim document = New Document(PageSize.A4, 50, 50, 25, 25)
    
            ' Create a new PdfWrite object, writing the output to a MemoryStream
            Dim output = New MemoryStream()
            Dim writer = PdfWriter.GetInstance(document, output)
    
     'to save the file
            Dim path As String = Server.MapPath("PDFs")
            PdfWriter.GetInstance(document, New FileStream(path + "/Doc2.pdf", FileMode.Create))
    
    ' Open the Document for writing
            document.Open()
    
            ' Read in the contents of the Receipt.htm HTML template file
            Dim contents As String = File.ReadAllText(Server.MapPath("/content/template/index.html"))
    
    ' Replace the placeholders with the user-specified text
            contents = contents.Replace("[ORDERID]", txtOrderID.Text)
            contents = contents.Replace("[TOTALPRICE]", Convert.ToDecimal(txtTotalPrice.Text).ToString("c"))
            contents = contents.Replace("[ORDERDATE]", DateTime.Now.ToShortDateString())
           
      Dim styles As New StyleSheet()
            styles.LoadStyle("noborder", "border", "none")
    
    
            Dim parsedHtmlElements = HTMLWorker.ParseToList(New StringReader(contents), styles)
            For Each htmlElement In parsedHtmlElements
                document.Add(TryCast(htmlElement, IElement))
            Next
    

    i get the below error

    Server Error in '/' Application.
    
    Input string was not in a correct format.
    
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
    Exception Details: System.FormatException: Input string was not in a correct format.
    
    Source Error: 
    
    
    Line 59: 
    Line 60: 
    Line 61:         Dim parsedHtmlElements = HTMLWorker.ParseToList(New StringReader(contents), styles)
    Line 62:         For Each htmlElement In parsedHtmlElements
    Line 63:             document.Add(TryCast(htmlElement, IElement))
    
    Source File: H:\itextproject\default.aspx.vb    Line: 61 
    
    Stack Trace: 
    
    
    [FormatException: Input string was not in a correct format.]
       System.Number.ParseSingle(String value, NumberStyles options, NumberFormatInfo numfmt) +398
       iTextSharp.text.html.simpleparser.IncCell..ctor(String tag, ChainedProperties props) +520
       iTextSharp.text.html.simpleparser.HTMLWorker.StartElement(String tag, Hashtable h) +4055
       iTextSharp.text.xml.simpleparser.SimpleXMLParser.Go(TextReader reader) +971
       iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(TextReader reader, StyleSheet style, Hashtable interfaceProps) +131
       iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(TextReader reader, StyleSheet style) +7
       Ahmed_design_customer_invoices._default.btnCreatePDF_Click(Object sender, EventArgs e) in H:\itextproject\default.aspx.vb:61 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9628722 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103 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) +35 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724 Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34248

    Sunday, August 9, 2015 5:44 PM

All replies