文本在itextsharp中正确格式化和对齐

时间:2015-10-20 10:29:39

标签: c# css itextsharp phrase

我使用此代码在表格中将两个短语/两列对齐

        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);       

我得到了这个结果 enter image description here

但我希望这样表现出来:

enter image description here

1 个答案:

答案 0 :(得分:3)

表通常不会给你那种布局。你为什么要把它变成桌子?

将其构建为段落要轻松得多:

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);