Add a note to PDF

Manipulate PDF
4/18/2014

Downloads

This code sample shows how to add a note to a PDF document.

The note pops up whenever you mouse-over it, and it will then display the note text.

C# code sample

1 //create new document 2 Document document = new Document(); 3 4 //crate a page and add to the document 5 Page page = new Page(PageSize.Letter); 6 document.Pages.Add(page); 7 8 //create a note 9 Note note = new Note(100, 600, 20, 20) 10 { 11 Text = "This page is empty.", 12 IconName = "Note" 13 }; 14 15 //create a popup and assign it to the note 16 Popup popup = new Popup(140, 500, 200, 100) { Open = true }; 17 note.Popup = popup; 18 19 //add the note to the page 20 page.Markups.Add(note); 21 22 //write the PDF document to the disk 23 const string fileName = @"..\..\addnote.pdf"; 24 using (FileStream file = new FileStream(fileName, FileMode.Create, FileAccess.Write)) 25 { 26 document.Write(file); 27 }

VB.NET code sample

1 Dim document As New Document() 2 Dim page As New Page(PageSize.Letter) 3 document.Pages.Add(page) 4 5 Dim note As New Note(300, 300, 10, 10) 6 note.Text = "This page is empty." 7 note.IconName = "Note" 8 page.Markups.Add(note) 9 10 Dim popup As New Popup(320, 350, 200, 100) 11 popup.Open = True 12 note.Popup = popup 13 14 Using file As New FileStream("..\..\addnote.pdf", FileMode.Create, FileAccess.Write) 15 document.Write(file) 16 End Using

The result:

PDF-with-note-added.png