pdfptable format problem?

Posted by raj on Stack Overflow See other posts from Stack Overflow or by raj
Published on 2010-06-17T04:57:14Z Indexed on 2010/06/17 5:03 UTC
Read the original article Hit count: 672

Filed under:

Hi, I am using the code below to convert Html string to PDF.I notice that at times, it does print the tables in PDF but no styles(no border, color etc..).Below is the html string: Can anyone suggest me where am I missing something?

  • Hi user
    The Message ID 56456 has been assigned to you for Edition. AUTO VERIFY FOR CONGROUP cccccccc FAILED
    SSID ssss message, RPTD BY rrrr
    SSID ssss RLD ll message, RPTD BY rrrr
    SSID ssss DEV ddd message, RPTD BY rrrr
     Table 12 EMC9998W message format
<table style="border: medium solid #00FF00; width:100%; table-layout: auto; visibility: visible;" 
    title="EMC9998W message format">
    <tr>
        <td>
            <b>Exception code</b></td>
        <td>
            <b>Meaning</b></td>
        <td>
            <b>Message format</b></td>
    </tr>
    <tr>
        <td >
            1460
        </td>
        <td>
            DYNAMIC SPARING INVOKED</td>
        <td>
            1</td>
    </tr>
    <tr>
        <td >
            147D REMOTE
        </td>
        <td >
            LINK DIRECTOR PROBLEM/FAILURE</td>
        <td>
            2</td>
    </tr>
</table>

Where

  • MSG FORMAT 1

  • EMC9998W SSID ssss message, RPTD BY rrrr
  • MSG FORMAT 2

  • EMC9998W SSID ssss message, RPTD BY rrrr
  • MSG FORMAT 3
    EMC9998W SSID ssss message, RPTD BY rrrr

private void HtmltoPdf(string s, Paragraph p,Document doc) {

        string strLine = s;
        byte[] byteArray = Encoding.ASCII.GetBytes(strLine);
        MemoryStream stream = new MemoryStream(byteArray);
        StreamReader reader2 = new StreamReader(stream);            
        StringReader sr2 = new StringReader(reader2.ReadToEnd());

        iTextSharp.text.html.simpleparser.HTMLWorker worker = new HTMLWorker(doc);
        ArrayList elementlist = HTMLWorker.ParseToList(sr2, null);            
        Phrase ph = new Phrase();
        for (int k = 0; k < elementlist.Count; ++k)
        {
            IElement ielement = (IElement)elementlist[k];
            ArrayList chunks = ielement.Chunks;

            if (ielement.Type == Element.PTABLE)
            {
                PdfPTable pt = (PdfPTable)ielement;
                pt.DefaultCell.Border = 2;

                PdfPTable t = new PdfPTable(1);//(new float[] {1f,1f,1f});

                ph.Add(t);
                PdfPCell pcell = new PdfPCell(new Paragraph(ph));                    
                t.AddCell(pcell);                                        

                p.Add(t);

                foreach (PdfPRow row in t.Rows)
                {

                }
            }
            else if (ielement.Type == Element.LIST)
            {

            }
            else
            {
                ph.Clear();
                ph.Add((IElement)elementlist[k]);
                p.Add(new Paragraph(ph));
            }
        }

        sr2.Close();
        reader2.Close();
        stream.Close();                        
    }

© Stack Overflow or respective owner

Related posts about itextsharp