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