You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by chitgoks <ch...@gmail.com> on 2023/06/29 07:58:06 UTC
how to set background opacity only for free text annotation
chitgoks <ch...@gmail.com>
Wed, Jun 28, 12:08 PM (21 hours ago)
to users
Hi this is my code when creating an annotation's appearance for free text
PDAnnotationMarkup freeText = (PDAnnotationMarkup) annotation;
cs.addRect(....................);
cs.setNonStrokingColor(Util.hex2PDColor(pdfJSAnnotation.getBackgroundColor()));
cs.fill();
String[] text = ["Column 1", "Column 2", "Column 3"]
PDType1Font font = PDType1Font.HELVETICA;
cs.setNonStrokingColor(Util.hex2PDColor(pdfJSAnnotation.getColor()));
cs.beginText();
cs.setFont(font, pdfJSAnnotation.getFontSize() * .75f);
float whatToUse = freeText.getRectangle().getHeight();
cs.newLineAtOffset(0, whatToUse -
(pdfJSAnnotation.getFontSize() * .75f) + .75f);
for (String s : text) {
if (s.equals("\n"))
cs.newLineAtOffset(0,
-((pdfJSAnnotation.getFontSize() * .75f) + 1.75f));
else
cs.showText(s);
}
cs.endText();
My problem is how to set the background color's opacity but not
affecting the text color. I tried adding this just before cs.fill()
but it changes opacity for both background and foreground. is this
possible?
PDExtendedGraphicsState gs = new PDExtendedGraphicsState();
gs.setNonStrokingAlphaConstant((float)
pdfJSAnnotation.getOpacity());
gs.setStrokingAlphaConstant(1f);
cs.setGraphicsStateParameters(gs);
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org