locked
iTextSharp RRS feed

  • Question

  • User-547121016 posted

    hi

    i'm trying to generate a pdf using itextsharp.my aspx have div tags and styles.when i generate it, styles doesn,t apply.give me support.here my html code.

    <div style="width:539px;height:235px;float:left;border-bottom:2px #cbcccd dashed;">
          <div style="width:261px; height:auto; float:left;">
            <div style="width:261px; height:45px; float:left;"><img src="images/logo-new.jpg" width="260" height="45" /></div>
            <div style="width:261px; height:20px; float:left; font-family:Verdana, Geneva, sans-serif; font-size:8px; color:#000; margin-top:8px;">xxxxxx is a trading name of<br />
              xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</div>
            <div style="width:261px;height:15px;font-family:Verdana, Geneva, sans-serif;font-size:10px;color:#000;font-weight:bold;
     margin-top:10px;
     background-color:#f1f1f2;
     float:left;">Sender Details :</div>
            <div style="width:211px;height:89px;border:1px solid #cbcccd;font-family:Verdana, Geneva, sans-serif;font-size:12px;color:#000; background-color:#f1f1f2;padding:9px 9px 9px 39px;float:left;"> <b>Mr xxxxxxxxxxx</b><br />
              xxxxxxxxx<br />
              xxxxxxxx<br />
              xxxxxxxx<br />
              xxxxxxxxx<br />
            </div>
          </div>
          <div style="width:278px;height:235px;float:left;">
            <div style="width:264px;height:20px;font-family:Verdana, Geneva, sans-serif;font-size:15px;font-weight:bold;line-height:20px;text-align:right;color:#000;float:right;">Remittance acknowledgement</div>
            <div style="width:210px;height:auto;font-family:Verdana, Geneva, sans-serif;font-size:12px;color:#000;float:right;">
              <table style="width:100%; border:0; background-color:green">
                <tr>
                  <td style="width:55%; height:15px; text-align:left; padding:2px;">Confirmation No :</td>
                  <td style="width:45%; height:15px; text-align:right; padding:2px;">61619887</td>
                </tr>
                <tr>
                  <td style="height:15px; text-align:left;">Order Date:</td>
                  <td style="height:15px; text-align:right;">01/02/2010</td>
                </tr>
                <tr>
                  <td style="height:15px; text-align:left">Agent Code :</td>
                  <td style="height:15px; text-align:right">xxxxxxx</td>
                </tr>
                <tr>
                  <td style="height:15px; text-align:left">Customer No :</td>
                  <td style="height:15px; text-align:right">XXXXX</td>
                </tr>
              </table>
            </div>
          </div>
        </div>

    HtmlPdfPage first = builder.AddPage();

    first.appendHtml("mycode");

     

    Saturday, August 7, 2010 11:21 PM

All replies

  • User-861155893 posted

    The iTextSharp xhtml parser is not comprehensive - you may have to extend iTextSharp to achieve what you are after... I also had a quick scan and it may be that it will only pickup LINKed css stylesheets NOT inline styles

    Sunday, August 8, 2010 11:03 AM
  • User-547121016 posted

    i did this way.but doesnt work

    builder.AddStyle("Reg-info", "width:261px;height:20px;font-family:Verdana, Geneva, sans-serif;font-size:8px;color:#000;float:left;margin-top:8px;");
                first.AppendHtml("<div id=page><div id=page-inner>");
                first.AppendHtml("<div-area>");
                first.AppendHtml("<div="top-left"><div></div><div="info"> a trading name of<br />s Limited Registered in England : No. 00197</div><div class="sender-details-head">Sender Details :</div><div="details"> <b>Mr </b><br /> - 127 Braml Road<br />ENFIELD<br />London <br />United Kingdom<br /></div></div>");


    help me

    Monday, August 9, 2010 1:11 AM
  • User-861155893 posted

    firstly your html syntax in the AddHtml is bad... try this

    builder.AddStyle("testBorder", "border:1px red solid");

    first.AppendHtml("<p class="testBorder">hi this should have a 1px red border if it targets the DOM element correctly</p>");

    If it works then you need to look at your HTML knowledge - it seems you dont quite know how to write it i.e.

    what is <div="top-left">? this is invalid X/HTML... should it be <div class="top-left"> or <div id="top-left">?


    Hope this helps


    Monday, August 9, 2010 2:15 AM
  • User-547121016 posted

    hi

    it is a mistake.i have added like this <div id="top-left">.but doesnt work.

    Monday, August 9, 2010 2:42 AM
  • User-861155893 posted

    did you do the test as I said? i.e. testBorder

    Monday, August 9, 2010 3:59 AM
  • User-547121016 posted

    hi

    it's work for p and h tags.my question is how i work with div

    Monday, August 9, 2010 4:49 AM
  • User-861155893 posted

    You may find that the iTextSharp html parser is NOT complete and does not implement the code needed to convert html divs into pdf markup and if you need it to do so then you will have to extend iTextSharp to include the logic

    regards



    Monday, August 9, 2010 5:07 AM
  • User-547121016 posted

    hi

    i cant find htmlPaser in my itextsharp.itextsharp version is 5.2

    Monday, August 9, 2010 10:41 PM
  • User-547121016 posted

    hi

    we cant play with divs styles in iTextSharp have to move another option

    Tuesday, August 10, 2010 1:15 AM
  • User-861155893 posted

    I doubt you will find a Free Open Source Software (FOSS) that is as comprehensive or stable as iTextSharp that has the HTML parsing you need (I have hunted far and low for one). IF you find one that is free and accomplishes this let me know would you.

    Tuesday, August 10, 2010 4:00 AM