java lowagie字体设置,我怎样才能改变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.

My code:

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");

解决方案

You have two options.

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

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( "" +

comentario.getComentario() +

"" ) );

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 );

Yep, have to use a stamper.

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

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).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值