我想创建一个自由文本注释,矩形框边框颜色为绿色,文本颜色为红色和字体样式,矩形背景颜色为黄色。我无法一次实现所有目标。有人可以帮帮我。它是高度优先的。
我正在创建如下注释:
PdfAnnotation annotation = PdfAnnotation.createFreeText(stamper.getWriter(), rectangle, "Annotation text", pcb);
在这里,我想将字体样式、颜色应用于文本“注释文本”,并将文本放入应用边框和背景颜色的矩形框中。
PdfContentByte pcb = stamper.getOverContent(n);
BaseFont helv = BaseFont.createFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
pcb.setFontAndSize(helv, 9);
pcb.setColorFill(BaseColor.RED);
pcb.setColorStroke(BaseColor.GREEN);
PdfAnnotation annotation = PdfAnnotation.createFreeText(stamper.getWriter(), rectangle, "Annotation text", pcb);
annotation.setColor(BaseColor.YELLOW); // This is setting background colour for rectangle
使用 PdfContentByte 应用文本格式。通过上述操作,我能够应用字体样式和颜色。但是字体颜色被应用于注释矩形框。但我的意图是对注释文本和(矩形)边框颜色应用不同的颜色