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:
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 (http://www.boost.org/doc/libs/1_57_0/libs/polygon/doc/index.htm) library.
In terms of PDF representation, you could potentially store the result using Ink Annotations (Section 184.108.40.206.3 in PDF Reference https://www.xodo.com/view/#/c0c11968-ee14-478e-9b09-6dc5635c0915):
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 (https://www.pdftron.com/downloads/CosEditDemo.zip, https://www.pdftron.com/assets/pdfs/support/PDFTron_CosEdit_User_Manual.pdf) 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).