locked
Richtextbox text to pdf(itextsharp) RRS feed

  • Question

  • i am using liquidRichText:RichTextBox control in silverlight  and writing text,tables,images.

    now i am saving it    richTextBox.HTML  in the database the text is as follows and getting the same data from database 

    creating the pdf .

    <style type="text/css">
    p {margin:0px 0px 0px 2px;}
    ul {margin-top:2px;margin-bottom:2px;}
    ol {margin-top:2px;margin-bottom:2px;}
    .Normal {font-family:Segoe UI Light;font-size:11px;color:#000000;vertical-align:middle;}
    .TableDefault {border-collapse:collapse;border:1px solid #000000;}
    .TableDefault th {padding:2px;vertical-align:top;text-align:left;border:1px solid #000000;}
    .TableDefault td {padding:2px;vertical-align:top;text-align:left;border:1px solid #000000;}
    .TableRed {border-collapse:collapse;border:1px solid #FF8888;}
    .TableRed th {padding:2px;vertical-align:top;text-align:left;background:#FFDDDD;border:1px solid #FF8888;}
    .TableRed td {padding:2px;vertical-align:top;text-align:left;background:#FFF0F0;border:1px solid #FF8888;}
    .TableGreen {background:#FFFFFF;border-collapse:collapse;border:2px solid #B0EEB0;}
    .TableGreen th {padding:2px;vertical-align:top;text-align:left;background:#B0EEB0;border:1px solid #B0EEB0;}
    .TableGreen td {padding:2px;vertical-align:top;text-align:left;border:1px solid #B0EEB0;}
    </style>
    <p><span class="Normal">raj</span></p>
    <br /><p><span class="Normal">john</span></p>
    <br /><p><table class="TableGreen" width="342">
    <tr>
    <th style="width:99px; vertical-align:top;"><p style="margin:0px;"><span class="Normal">hai</span></p></th>
    <th style="width:120px; vertical-align:top;"><p style="margin:0px;"><span class="Normal">hai</span></p></th>
    <th style="width:123px; vertical-align:top;"><p style="margin:0px;"><span class="Normal">hai</span></p></th>
    </tr>
    <tr>
    <td style="width:99px; vertical-align:top;"><p style="margin:0px;"><span class="Normal">hai</span></p></td>
    <td style="width:120px; vertical-align:top;"><p style="margin:0px;"><span class="Normal">hai</span></p></td>
    <td style="width:123px; vertical-align:top;"><p style="margin:0px;"><span class="Normal">hai</span></p></td>
    </tr>
    <tr>
    <td style="width:99px; vertical-align:top;"><p style="margin:0px;"><span class="Normal">hai</span></p></td>
    <td style="width:120px; vertical-align:top;"><p style="margin:0px;"><span class="Normal">hai</span></p></td>
    <td style="width:123px; vertical-align:top;"><p style="margin:0px;"><span class="Normal">hai</span></p></td>
    </tr>
    </table>
    </p>
    <br />

    i am adding above data to itextsharp.

    but i am not getting the result

                           

     HtmlEditorValue = ds.Tables[9].Rows[k][j].ToString();


                            System.Collections.ArrayList htmlElements = HTMLWorker.ParseToList(new StringReader(HtmlEditorValue), null);
                            PdfPTable pdfPtable2 = new PdfPTable(1);

                            pdfPtable2.TotalWidth = document.PageSize.Width - 70;
                            pdfPtable2.WidthPercentage = 100;
                            pdfPtable2.HorizontalAlignment = 1;

                            for (int ii = 0; ii < htmlElements.Count; ii++)
                            {
                                IElement htmlElement = ((IElement)htmlElements[ii]);
                                PdfPCell pdfCell = new PdfPCell();
                                pdfCell.Border = 0;
                                pdfCell.Top = 0;
                                pdfCell.AddElement(htmlElement);
                                pdfPtable2.AddCell(pdfCell);
                            }
                            PdfPTable ContentTable = new PdfPTable(1);
                            ContentTable.TotalWidth = document.PageSize.Width - 70;
                            ContentTable.WidthPercentage = 100;
                            ContentTable.HorizontalAlignment = 1;

                            float[] editorWidth = { 511 };
                            pdfPtable2.SetTotalWidth(editorWidth);
                            pdfPtable2.SplitLate = false;
                            pdfPtable2.SplitRows = true;

                            PdfPTable ContentCell = new PdfPTable(pdfPtable2);
                            ContentCell.HorizontalAlignment = 1;
                            ContentTable.AddCell(ContentCell);
                            document.Add(ContentTable);

    i am getting the result as follows.

    p {margin:0px 0px 0px 2px;} ul {margin-top:2px;margin-bottom:2px;} ol {margin-top:2px;marginbottom:
    2px;} .Normal {font-family:Segoe UI Light;font-size:11px;color:#000000;vertical-align:middle;}
    .Custom2 {font-family:Segoe UI Light;font-size:11px;color:#000000;vertical-align:Top;} .TableDefault
    {border-collapse:collapse;border:1px solid #000000;} .TableDefault th {padding:2px;vertical-align:top;textalign:
    left;border:1px solid #000000;} .TableDefault td {padding:2px;vertical-align:top;textalign:
    left;border:1px solid #000000;} .TableGreen {background:#FFFFFF;bordercollapse:
    collapse;border:2px solid #B0EEB0;} .TableGreen th {padding:2px;vertical-align:top;textalign:
    left;background:#B0EEB0;border:1px solid #B0EEB0;} .TableGreen td {padding:2px;verticalalign:
    top;text-align:left;border:1px solid #B0EEB0;}
    raj

    john

    about u

    Hai Hai Hai
    Hai Hai Hai

    please help me to convert rich text into pdf


    P.visweswararao.

    Saturday, February 8, 2014 11:34 AM

Answers