Cutout and complex annotations

Skip to first unread message


Nov 16, 2016, 7:35:21 PM11/16/16
Q: We will soon be required to provide "cutout" support for our shaped annotations.  For example, suppose we start with a rectangle annotation.  We now need to provide the ability for a user to remove or "cut out" a section of that rectangle.  Let's say we were to accomplish this by allowing the user to draw a second rectangle (the eraser).  Once the second shape is defined, perhaps we could calculate a new shape?  Visually, this could look like the following:

Above, we have a 6-sided polygon that was generated by starting with a rectangle and placing a "cutout" rectangle in the original rectangle's lower-right corner.

I'm guessing there is a polygon "difference" tool out there that will help me calculate the resulting polygon after the cutout, and I could define the resulting polygon as an annotation with PDFTron by supplying the list of vertices?  That's the simple case.  

The problem becomes more complex when the cutout rectangle is placed wholly within the first rectangle.  Then, you would end up with a donut-like shape.  Allow me to describe the shape.  Consider a standard, coordinate plane with the origin in the lower left.  Use the following points to create a shape, moving from one point to the next in order:

1: (0,20)
2: (0,0)
3: (20,0)
4: (20,20)
5: (10,20)
6: (10,15)
7: (15,15)
8: (15,10)
9: (5,10)
10: (5,15)
11: (10,15)
12: (10,20)

Note that points 6 and 11 and points 5 and 12 are the same.  If you were to plot this, you should see a rectangle within a rectangle (like the donut shape mentioned above).  Here's an image:

Is this even a polygon?  Would PDFTron handle a polygon annotation (and draw it correctly) if I were to give it the list of 12 vertices above?

This task becomes even further complicated when you allow any polygon original shape (not just a rectangle) with any polygon cutout (again, not just a rectangle).

Can PDFTron (and basic, underlying PDF) support annotations of this nature?  How would you recommend we get started on this task?  


You could perform polygon set operations using a library such as GPC or Boost Polygon ( library.

In terms of PDF representation, you could potentially store the result using Ink Annotations (Section in PDF Reference

Its a bit more powerful that Polygon annotation for representation of generic shapes with multiple contours.

One important thing to keep in mind is that in PDF annotations can store appearance that is distinct from the annotation type. So you should be able to define an explicit appearance using annot.setAppearance ... as showing in the following KB articles:

In this case the underlying annotation type is only important when it comes to editing operations in third party PDF apps.

P.S you can use our free CosEdit tool ( to inspect annotations and content of existing PDF files (e.g. ones produced using other apps) and to find out the annotation type / attributes used to represent the cutout (or whatever). 

Reply all
Reply to author
0 new messages