aGe
aGe

Reputation: 1

Wrapping justified text around a table using iText7

I try to wrap a text around a table. If the text alignment is LEFT than everything is ok but when I use the text alignment JUSTIFIED the output looks ugly.

try(PdfWriter writer = new PdfWriter("Justified.pdf"))
{
    try(PdfDocument pdfDocument = new PdfDocument(writer))
    {
        pdfDocument.setDefaultPageSize(PageSize.A5);
        try(Document document = new Document(pdfDocument))
        {
            String text = "Lorem ipsum dolor sit amet, ...";
            String text2 = "Lorem ipsum dolor sit amet, ...";

            Table table2 = new Table(1)
                    .setWidth(150f)
                    .setBorder(new SolidBorder(1f))
                    .setMargin(5f)
                    .setHorizontalAlignment(HorizontalAlignment.LEFT)
                    .addCell(new Cell()
                            .add(new Paragraph(text2)));
            table2.setProperty(Property.FLOAT, FloatPropertyValue.LEFT);
            document.add(table2);
            document.add(new Paragraph(text)
                    .setTextAlignment(TextAlignment.JUSTIFIED));
            Table table3 = new Table(1)
                    .setWidth(150f)
                    .setBorder(new SolidBorder(1f))
                    .setMargin(5f)
                    .setHorizontalAlignment(HorizontalAlignment.RIGHT)
                    .addCell(new Cell()
                            .add(new Paragraph(text2)));
            table3.setProperty(Property.FLOAT, FloatPropertyValue.RIGHT);
            document.add(table3);
            document.add(new Paragraph(text)
                    .setTextAlignment(TextAlignment.JUSTIFIED));
        }
    }
}
catch(Exception ex){}

Text alignment JUSTIFIED:

enter image description here

Text Alignment LEFT:

enter image description here

Upvotes: 0

Views: 1242

Answers (1)

Yulian Gaponenko
Yulian Gaponenko

Reputation: 588

This particular bug is fixed in iText since 7.1.1 version. Some additional fixes for alignment of text wrapped around floating elements (like in case of inline floating blocks and first line text indents) will be introduced in iText 7.1.2.

Upvotes: 2

Related Questions