我怎样才能改变iTextPdf注释的字体大小? [英] How can I change the font size of annotations in iTextPdf?

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

问题描述

我编程,生成包含用户提交的评论的PDF文件的系统。我想降低意见的大小,即每个注释的字体大小。我使用iTextPdf的Java版本。

我的code:

  PdfAnnotation注释= PdfAnnotation.createText(pdfStamper.getWriter()
    新的Rectangle(X,勇气,X + 100F,勇气+ 100°F),作家,
    comentario.getComentario(),真的,评论);
annotation.setColor(Color.ORANGE);

我可以减少字体大小也是这样吗?

  annotation.setFontSize(2px的);


解决方案

您有两种选择。


  1. 您可以设置默认字体和放大器;大小,主Torgamus描述。


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


  annotation.put(PdfName.RC,新PdfString(<字体大小= \\什么\\>中+
                                          comentario.getComentario()+
                                          &所述; /字体>中));

需要注意的是iText的无法呈现富文本字段露面(至少目前还没有),所以你必须关闭外观一代所以生成的PDF会问观众做到这一点:

  myStamper.setGenerateAppearances(假);

是的,必须使用一个模子。

这可能只是更容易去托格的建议......但是心里的兔子。它不与其他人打得好。

PS:飞溅的 setAppearance()招会的工作,但你必须绘制整个事情自己...背景,边框和文本布局(其是非常容易的感谢 Col​​umnText )。

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.

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

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

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

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

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