How do I rotate a PDF annotation by an arbitrary angle?

Q:

I want to rotate an annotation while drawing it on a rotated page in an Android application. We have created a transformation matrix (Matrix2D) from the page rotation. But confused how to apply the same in Annotation. A help is much appreciated.

A:

Unfortunately, there is no easy way to rotate annotations (e.g. by an arbitrary angle) according the PDF standard. Annotations themselves have no rotation, instead they are always rotated with the page rotation, or with the e_no_rotate_flag, not rotated when the page rotation. This is typically used with annotations like a post-it note style, so no matter which way the user rotates the page, including while viewing it in a PDF reader, it is always orientated one way.

So, if you want to explicitly control rotation, you actually need to create your own content stream (search for SetApprarance() in this forum), and surround it with a transformation matrix, and then apply it to the annotation.

Here is a forum post describing this: https://groups.google.com/d/msg/pdfnet-sdk/t1e9hODFa9Y/TF2zUwuEWMcJ

See the ElementBuilderTest example for more on how to create appearance/content streams, including how to set the transformation matrix (to rotate): http://www.pdftron.com/pdfnet/samplecode.html#ElementBuilder

There is now an API to support this, though as mentioned above, since this is not supported by the PDF specification, if the annotation is later edited in anyway the custom rotation most likely will be lost.