如何在段落中垂直对齐文本和图像元素? 我想知道我如何在段落中垂直对齐元素与itext 9 val图标= image(imagedatafactory.create(xxx :: class.java.getResource(“/pdf/xxx.png”))))))))))))) .scaletofit(30f,30f)

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


    

ETEXTCORE至少有2个选项,并且两者都有一些隐藏。 选项1,使用Property.inline_vertical_alignment属性仅在html_mode渲染模式下工作。

VerticalAlignment

eption2,使用flexcontainerrenderer。

try (PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outFileName))) { Document document = new Document(pdfDoc); Paragraph p = new Paragraph().setBorder(new SolidBorder(1f)); p.setProperty(Property.RENDERING_MODE, RenderingMode.HTML_MODE); Image icon = new Image(ImageDataFactory.create(imageFileName)) .scaleToFit(30f, 30f).setBorder(new DashedBorder(1f)); icon.setProperty(Property.INLINE_VERTICAL_ALIGNMENT, new InlineVerticalAlignment(InlineVerticalAlignmentType.MIDDLE)); Text text = new Text(" %d best practices ") .setBorder(new SolidBorder(Color.createColorWithColorSpace(new float[]{1f, 0f, 0f}), 1f)); p.add(icon).add(text); document.add(p); } expectednext,您可以尝试ITEXT html2pdf addon -https://github.com/itext/itext/itext-pdfhtml-java

kotlin pdf itext itext7
1个回答
0
投票

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.