Is anyone out there able to create a clickable annotation that has an irregular shape?

I know I can create a rectangular one like this:

```float x1 = 100, x2 = 200, y1 = 150, y2 = 200;
iTextSharp.text.Rectangle r = new iTextSharp.text.Rectangle(x1, y1, x2, y2);
PdfAction ac = new PdfAction(lnk.linkUrl, false);
PdfAnnotation anno = PdfAnnotation.CreateLink(stamper.Writer, r, pfn, ac);
int page = 1;
Is there any way to do that with a graphics path?

Posted on StackOverflow on Nov 22, 2014 by ksliman

The secret ingredient you are looking for is called QuadPoints ;-)

First let's take a look at some code that constructs and draws a path:

``````PdfCanvas canvas = new PdfCanvas(pdfDoc.getFirstPage());
canvas.moveTo(36, 700)
.lineTo(72, 760)
.lineTo(144, 720)
.lineTo(72, 730)
.closePathStroke();
``````

I am using this code snippet only to show the irregular shape that we'll make clickable.

You already know how to create a clickable link with a rectangular shape:

``````Rectangle linkLocation = new Rectangle(36, 700, 144, 760);
.setHighlightMode(PdfAnnotation.HIGHLIGHT_INVERT)
.setAction(PdfAction.createGoTo(PdfExplicitDestination.createFit(1)));
``````

This corresponds with the code snippet you already provided in your question, just adapted for iText 7.

``````PdfArray arrayOfQuadPoints = new PdfArray(new int[]{72, 730, 144, 720, 72, 760, 36, 700});
``````

`x1 y1 x2 y2 x3 y3 x4 y4`
specifying the four vertices of the quadrilateral in counterclockwise order. For orientation purposes, such as when applying an underline border style, the bottom of a quadrilateral is the line formed by `(x1, y1)` and `(x2, y2)`.
If this entry is not present or the conforming reader does not recognize it, the region specified by the `Rect` entry should be used. `QuadPoints` shall be ignored if any coordinate in the array lies outside the region specified by `Rect`.
Note that I defined the `linkLocation` parameter in such a way that the irregular shape fits inside that rectangle.
Caveat: you can try this functionality by testing this example: link_polygon.pdf, but be aware that while this will work when viewing the file in Adobe Reader, this may not work with inferior PDF viewers that did not implement the `QuadPoints` functionality.