簡體   English   中英

使用iText7將合理的文本環繞表格

[英]Wrapping justified text around a table using iText7

我嘗試將文本環繞在桌子上。 如果文本對齊方式為LEFT,則一切正常,但是當我使用文本對齊方式JUSTIFIED時,輸出看起來很難看。

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){}

文字對齊方式已確定:

在此處輸入圖片說明

文字對齊方式左移:

在此處輸入圖片說明

從7.1.1版本開始,此特定錯誤已在iText中修復。 iText 7.1.2中將引入一些其他對齊方式,用於對齊包裹在浮動元素周圍的文本(例如,內聯浮動塊和第一行文本縮進)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM