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);
}
next,您可以尝试ITEXT html2pdf addon -https://github.com/itext/itext/itext-pdfhtml-java