Highlights are not defined with a rectangle, but with quads. You can convert the rect to a quad, but you have to use the latter for it to work.
On Mon, Feb 13, 2023 at 2:46 PM Jacob MacWilliams < jacobmacwilli...@gmail.com> wrote: > Hi, > > I've been trying to highlight a specific field in my pdf but can only > get it to work with the setQuads method and not with the setRectangle > method (which would be much nicer then manually recording the quad > points of the rectangle). Could somebody help clarify what I'm doing > incorrectly? > > PDField pdfield = pdf.getField(field); > List<PDAnnotationWidget> widgets = pdfield.getWidgets(); > > for (PDAnnotationWidget widget : widgets) { > > PDPage page = widget.getPage(); > PDRectangle rectangle = widget.getRectangle(); > > // Use info to instantiate approriate highlight box and add to page > PDAnnotationHighlight idAnnotation = new PDAnnotationHighlight(); > idAnnotation.setColor(new PDColor(new float[] { 0, 0, 1 }, > PDDeviceRGB.INSTANCE)); > idAnnotation.setConstantOpacity((float) 0.3); > idAnnotation.setRectangle(rectangle); > page.getAnnotations().add(idAnnotation); > } > } > > best, > > jake > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org > For additional commands, e-mail: users-h...@pdfbox.apache.org > >