Question:
I want to allow users to create line annotations that also have text on them.
Answer:
You will get the best overall result, by replicating/modifying the Line annotation tool code, and replace the RefreshAppearance code with your own custom appearance, which would include this extra text.
Note that by default, double clicking an annotation such as a Line annotation will trigger (in most PDF readers) a popup dialog where users can enter “Hidden” text. You could re-use this behaviour and instead display this text as part of the annotation. Of course handling large amounts of text can become difficult, especially if you want it displayed completely on top of the page content.
When creating your custom appearance the Rect entry of the annotation should define bounding box that contains all the visible on screen content, so especially for larger text you will need to determine if you need to expand this box or not.
To get started, modify the LineCreate.cs Create method. After the call to RefreshAppearance(), you would get the appearance stream, and create a new one based on it, but with your text added.
For further appearance customization, see the following sample code.
http://www.pdftron.com/pdfnet/samplecode/ElementBuilderTest.cs.html
However for the code above, which operates on Page appearance streams, you would use the following code.
`
Obj app_stm = annot.GetAppearance();
reader.Begin(app_stm);
writer.Begin(doc);
… read from reader, writing everything to the writer, and add your new content
Obj appearance_stream = writer.End();
appearance_stream.PutRect(“BBox”,0,0,w,h); // update based on added text. This is a clipping box and needs to contain your text
annot.SetAppearance(appearance_stream);
`
The post provides the starting point for creating a stream from scratch (not calling RefreshAppearance)
https://groups.google.com/d/msg/pdfnet-sdk/VKV_M2r8c_8/ELadsgU3R9gJ