Aspose.Pdf

Attach Note Annotation to PDF Document

Adding note annotation to the PDF documents is one of the best features provided by Aspose.Pdf . The beauty of Aspose.Pdf is to create complex things with less effort.

 

To attach a note annotation, we will again make use of Attachment class and set its AttachmentType property to AttachmentType.Note enumeration value. Then we can specify the content to display in the note using NoteContent property of Attachment class. Title of the note can also be specified by setting the NoteHeading property of Attachment class.

 

Moreover, if developers need to open the note when the PDF document gets opened then they can make use of IsNoteOpen property. IsNoteOpen is a boolean property that can be set to true to implement this effect.

 

As a reference, two different phases of a note annotation are displayed below:

 

note1

 

Figure: Note annotation view when PDF document is opened

 

note1

 

Figure: Note annotation view when note is clicked

To attach a note annotation in your PDF document like the above figure, you can follow the example given below.

 

Code Snippet

 

[C#]

 

//Instantiate attachment instance

Attachment noteAttachment = new Attachment();

 

//Add the attachment in the paragraphs collection of the section

sec1.Paragraphs.Add(noteAttachment);

 

//Set the attachment type to note to make it a note annotation

noteAttachment.AttachmentType = AttachmentType.Note;

 

//Set the content of the note annotation

noteAttachment.NoteContent = "This is a note.";

 

//Set the title or heading of the note

noteAttachment.NoteHeading = "The title";

 

//Set the note to be opened when PDF document is opened

noteAttachment.IsNoteOpen = true;

 

[VB.NET]

 

'Instantiate attachment instance

Dim noteAttachment As Attachment = New Attachment()

 

'Add the attachment in the paragraphs collection of the section

sec1.Paragraphs.Add(noteAttachment)

 

'Set the attachment type to note to make it a note annotation

noteAttachment.AttachmentType = AttachmentType.Note

 

'Set the content of the note annotation

noteAttachment.NoteContent = "This is a note."

 

'Set the title or heading of the note

noteAttachment.NoteHeading = "The title"

 

'Set the note to be opened when PDF document is opened

noteAttachment.IsNoteOpen = True

 

[JAVA]

 

//Instantiate attachment instance by calling its empty constructor

Attachment noteAttachment = new Attachment(sec1, new Rectangle(36, 72, 0, 0));

 

//Add attachment in the paragraphs collection of the section

sec1.getParagraphs().add(noteAttachment);

 

//Set attachment type to File using AttachmentType enumeration

noteAttachment.setAttachType(AttachmentType.Note);

 

//Set the content of the note annotation

noteAttachment.setNoteContent("This is a note.");

 

//Set the title or heading of the note

noteAttachment.setNoteHeading("The title");                                         

 

//Set the note to be opened when PDF document is opened

noteAttachment.setNoteOpen(true);

 

[XML]

 

<Attachment AttachmentType="Note" IsNoteOpen="true" NoteContent="This is a note."

                NoteHeading="The title">

</Attachment>

 

Note: The note annotation icon can be changed if desired. To change the note icon type, any of the pre-defined value of NoteIconType enumeration can be assigned to NoteIconType property of Attachment class. Different note icon types supported by Aspose.Pdf are shown below in the figure: