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-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: users-h...@pdfbox.apache.org

Reply via email to