iText 7. 使用 TextAlignment.JUSTIFIED case 将文本环绕图像

问题描述 投票:0回答:1

是否可以使文本与浮动图像正确对齐?

现在看起来像这样:

我的代码:

val writer = PdfWriter("HelloWorld.pdf")
val pdf = PdfDocument(writer)
val document = Document(pdf)

val txt = (1..40).joinToString { "A Hello World PDF document..." }

val img = Image(ImageDataFactory.create("img.png"))

val scaledSize = img.scaledSize(document, 5f)

img
    .scaleAbsolute(scaledSize.first, scaledSize.second)
    .setMarginRight(16f)
    .setProperty(Property.FLOAT, FloatPropertyValue.LEFT)
    
val paragraph = Paragraph()
    .setTextAlignment(TextAlignment.JUSTIFIED)
    .add(img)
    .add(txt)
    
document.add(paragraph)

document.close()
writer.close()

但是如果我排除

.setTextAlignment(TextAlignment.JUSTIFIED)
,它看起来很正常:

java image kotlin pdf itext
1个回答
0
投票

您使用的 itext 版本是什么?我在 7.2.6 上测试了你的代码,它与 TextAlignment.JUSTIFIED 一起工作得很好

© www.soinside.com 2019 - 2024. All rights reserved.