I'm working with iTextSharp on Visual Studio. I created a Pdfannotation like that:
PdfAnnotation annotation = PdfAnnotation.CreateText(stamper.Writer, rect, "Author", "I write my text", true, "New Paragraph");
stamper.AddAnnotation(annotation, 1);
So my annotation contents a text "I write my text". When I go on Adobe Acrobat Reader to open my pdf, and when I click on the button "Comment" to see all the comments I wrote on my pdf, I see my comment and near to my comment "I write my text", I see a little square that I can check or uncheck. This is a little Checkbox which was automatically created when I created my Pdf annotation. I didn't create it by myself.
I would like to check or uncheck this little checkbox using iTextSharp.
I thought about doing that, but it doesn't work :
RadioCheckField checkbox = new RadioCheckField(stamper.Writer, rect, "bonjour", "on");
checkbox.CheckType = RadioCheckField.TYPE_CHECK;
checkbox.Checked = true;
PdfFormField field = checkbox.CheckField;
annotation.Put(PdfName.A, field);
Does anyone know how to do it ?
Thank you a lot!
Have a good day! :)
The question was somewhat confusion because of the terminology "check/uncheck" in the context of a text (or Sticky Note) annotation. The correct terminology would have been: How to I mark/unmark a text annotation?
Checking/unchecking immediately makes us think about check boxes, but the following screen shot shows what is meant when we talk about marking a text annotation:
Marking a text annotation isn't a matter of checking a check box. Marking a text annotation is done by adding a hidden "In Reply To" (IRT) annotation. See How to add an "In Reply To" annotation? on the official site for more information about "In Reply To" annotations.
I've adapted the AddInReplyTo example with the AddMarked as result:
The example is in Java, but it should be fairly easy to adapt it to C#. It's important to know that marking the original annotation
sticky
is done by adding an extra annotationreplySticky
. The difference with an ordinary IRT annotation, is that we are going to hide the annotation by addingFLAGS_HIDDEN
to the flags of the annotation. We also set the/State
toMarked
and the/StateModel
toMarked
.This code turns hello_sticky_note.pdf into hello_marked.pdf as was requested, but there's a catch! The check box will only be visible if you are logged in as user "Bruno". This check box is for personal use only.
If you want others to see a review status, you shouldn't use the "Marked" feature. Instead you should use "Review". This is poorly documented in ISO-32000. See the table with title "Additional entries specific to a text annotation":
This table refers to the table with title "Annotation States":
We have used the combination StateModel = Marked; State = Marked, which means that the annotation has been marked by the user. I didn't find any reference in the spec that this mark is only visible on the machine of the user who marked the document.
After discovering this, I've created the AddAccepted example:
This example is identical to what we had before, except that we now use the combination: StateModel = Review; State = Accepted. As you can tell from the "Annotation states" table, other possible options for the State are "Rejected", "Cancelled", "Completed" and "None" (which is the default value).
The result looks like this:
As you can see, a green check mark appears in the comments panel. It shows "Bruno Accepted" on a computer where the logged in user isn't Bruno. You can check this for yourself here: hello_accepted.pdf