java 如何在itext 5.2.1 中将图像添加到标题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11203831/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 04:13:25  来源:igfitidea点击:

How to add image to header in itext 5.2.1

javapdfitext

提问by Rancho

enter image description hereHow to add image to header in itext 5.2.1?

在此处输入图片说明如何将图像添加到 itext 5.2.1 中的标题?

As the picture shows, the logo should fill the header.

如图所示,徽标应填充标题。

回答by Piotr Olaszewski

Try to use it:

尝试使用它:

Image logo = Image.getInstance("/image.gif");
logo.setAlignment(Image.MIDDLE);
logo.scaleAbsoluteHeight(20);
logo.scaleAbsoluteWidth(20);
logo.scalePercent(100);
Chunk chunk = new Chunk(logo, 0, -45);
HeaderFooter header = new HeaderFooter(new Phrase(chunk), false);
header.setAlignment(Element.ALIGN_CENTER);
header.setBorder(Rectangle.NO_BORDER);
document.setHeader(header);

of course object document is: Document document = new Document();

当然对象文档是:Document document = new Document();

回答by Alexis Pigeon

You already posted a quite similar questionsome days ago. In my answer to that question, I pointed to this other answer. Instead of adding text to the header table as described there, you can add an Image.

几天前您已经发布了一个非常相似的问题。在我对那个问题的回答中,我指出了另一个答案。您可以添加一个图像,而不是像那里描述的那样向标题表添加文本。