如何更改 iTextPdf 中注释的字体大小? [英] How can I change the font size of annotations in iTextPdf?

查看:98
本文介绍了如何更改 iTextPdf 中注释的字体大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个系统,该系统生成一个包含用户提交的评论的 PDF 文件.我想减小注释的大小,即每个注释的字体大小.我使用的是 Java 版本的 iTextPdf.

I'm programming a system that generates a PDF file containing user-submitted comments. I want to reduce the size of the comments, i.e. the font size of each annotation. I'm using the Java version of iTextPdf.

我的代码:

PdfAnnotation annotation = PdfAnnotation.createText(pdfStamper.getWriter(),
    new Rectangle(x, valor, x+100f, valor+100f), "authors", 
    comentario.getComentario(), true, "Comment");
annotation.setColor(Color.ORANGE);

我可以像这样减小字体大小吗?

Can I reduce the font size like this?

annotation.setFontSize("2px");

推荐答案

您有两个选择.

  1. 您可以设置默认字体&大小,正如托加姆斯勋爵所描述的那样.

  1. You can set the default font & size, as Lord Torgamus described.

您可以使用注释的富文本值,您必须使用从 PdfDictionary 继承的方法 PdfAnnotation 直接访问该值:

You can use the Rich Text value of the annotation, which you have to directly access using the methods PdfAnnotation inherited from PdfDictionary:

annotation.put(PdfName.RC, new PdfString( "<font size=\"whatever\">" + 
                                          comentario.getComentario() + 
                                          "</font>" ) );

请注意,iText 无法呈现富文本字段外观(至少目前还没有),因此您必须关闭外观生成,这样生成的 PDF 将要求查看者执行此操作:

Note that iText cannot render Rich Text field appearances (at least not yet), so you have to turn off appearance generation so the resulting PDF will ask the viewer to do it:

myStamper.setGenerateAppearances( false );

是的,必须使用压模.

接受托格的建议可能更容易……但请注意兔子.与他人相处不好.

It's probably just easier to go with Torg's suggestion... but mind the rabbit. It doesn't play well with others.

PS:Splash 的 setAppearance() 技巧是可行的,但是你必须自己绘制整个东西......背景、边框和文本布局(由于 <代码>ColumnText).

PS: Splash's setAppearance() trick would work, but then you'd have to draw the whole thing yourself... background, borders, and text layout (which is much easier thanks to ColumnText).

这篇关于如何更改 iTextPdf 中注释的字体大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆