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:
Text Alignment LEFT:
答案 0 :(得分:2)
自7.1.1版以来,此特定错误已在iText中修复。在iText 7.1.2中将引入一些用于对齐浮动元素周围文本的附加修复(如内联浮动块和第一行文本缩进)。