You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Jacob MacWilliams <ja...@gmail.com> on 2023/02/13 13:54:23 UTC
Setting borders of PDAnnotationHighlight with setRectangle method?
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-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org
Re: Setting borders of PDAnnotationHighlight with setRectangle method?
Posted by Tilman Hausherr <TH...@t-online.de>.
So you're trying to put an annotation over a widget annotation? That
sounds weird, I've never seen this before. Why not just change the field
background instead?
Tilman
On 13.02.2023 14:54, Jacob MacWilliams 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-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org
Re: Setting borders of PDAnnotationHighlight with setRectangle method?
Posted by Gilad Denneboom <gi...@gmail.com>.
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 <
jacobmacwilliams@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-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>