Search code examples
c#cssitextphrase

Text Proper Formatting and alignment in itextsharp


I m using this code to align two phrases/two columns together in a table

        table = new PdfPTable(2);
        table.TotalWidth = 450f;
        table.LockedWidth = true;
        float[] widths= new float[] { 100f, 350f };
        table.SetWidths(widths);
        table.WidthPercentage = 85;
        table.HorizontalAlignment = Element.ALIGN_LEFT;
        cell = new PdfPCell();
        cell = PhraseCell(new Phrase("Repair 2 - Tongue pig biltong picanha:", newfntbld), PdfPCell.ALIGN_LEFT);
        cell.PaddingTop = 12f;
        table.AddCell(cell);
        cell = PhraseCell(new Phrase("Ham beef ball tip, pastrami sausage ribeye meatloaf salami kielbasa. Ground round bresaola pastrami ham capicola pork belly, tri-tip drumstick. Beef hamburger pork loin bacon doner chuck shank strip steak ham hock meatloaf. Flank meatball swine frankfurter.", newlightfnt), PdfPCell.ALIGN_LEFT);
        cell.PaddingTop = 12f;
        cell.Border = 0;
        table.AddCell(cell);       

I m getting this as result enter image description here

but i want to show like this:

enter image description here


Solution

  • Tables typically don't give you that kind of layout. Why would you shoehorn this into a table?

    It's a lot easier to just construct this as a paragraph:

    Phrase phrase1 = new Phrase("Repair 2 - Tongue pig biltong picanha - ", newfntbld);
    Phrase phrase2 = new Phrase("Ham beef ball tip, pastrami sausage ribeye meatloaf salami kielbasa. Ground round bresaola pastrami ham capicola pork belly, tri-tip drumstick. Beef hamburger pork loin bacon doner chuck shank strip steak ham hock meatloaf. Flank meatball swine frankfurter.", newlightfnt);
    Paragraph para = new Paragraph();
    para.Add(phrase1);
    para.Add(phrase2);