66// Load the existing PDF document using FileStream
77using ( FileStream inputStream = new FileStream ( Path . GetFullPath ( @"Data/Input.pdf" ) , FileMode . Open , FileAccess . Read ) )
88{
9+ // Load the PDF document from the input stream
910 using ( PdfLoadedDocument ldoc = new PdfLoadedDocument ( inputStream ) )
1011 {
11- // Get the first page
12- PdfLoadedPage lpage = ldoc . Pages [ 0 ] as PdfLoadedPage ;
12+ // Access the first page of the document
13+ PdfLoadedPage page = ldoc . Pages [ 0 ] as PdfLoadedPage ;
1314
14- // Get all annotations on the page
15- PdfLoadedAnnotationCollection annots = lpage . Annotations ;
15+ // Get the collection of annotations from the page
16+ PdfLoadedAnnotationCollection annotations = page . Annotations ;
1617
17- // Access the 65th annotation (index starts at 0)
18- if ( annots . Count > 64 && annots [ 64 ] is PdfLoadedCircleAnnotation Icircle )
18+ // Check if at least one annotation exists and it's a popup annotation
19+ if ( annotations . Count > 0 && annotations [ 0 ] is PdfLoadedPopupAnnotation annotation )
1920 {
20- // Get the author of the circle annotation
21- string author = Icircle . Author ;
22-
23- // Get the review history and comments
24- PdfLoadedPopupAnnotationCollection collection = Icircle . ReviewHistory ;
25- PdfLoadedPopupAnnotationCollection collectionComments = Icircle . Comments ;
26-
27- // Check if there's at least a second item in the review history
28- if ( collection != null && collection . Count > 1 )
29- {
30- PdfLoadedPopupAnnotation annotation = collection [ 1 ] as PdfLoadedPopupAnnotation ;
31-
32- if ( annotation != null )
33- {
34- // Set custom state and state model
35- annotation . SetValues ( "State" , "Approved" ) ;
36- annotation . SetValues ( "StateModel" , "ReviewWorkflow" ) ;
37- annotation . SetValues ( "ReviewedBy" , "John Doe" ) ;
38- annotation . SetValues ( "ReviewedOn" , DateTime . Now . ToString ( "yyyy-MM-dd" ) ) ;
39- }
40- }
21+ // Set a custom key-value pair in the annotation's metadata
22+ annotation . SetValues ( "custom" , "This is the custom data for the annotation" ) ;
4123 }
4224
43- // Save the modified document using FileStream
25+ // Save the modified document using a new FileStream
4426 using ( FileStream outputStream = new FileStream ( Path . GetFullPath ( @"Output/Output.pdf" ) , FileMode . Create , FileAccess . Write ) )
4527 {
46- ldoc . Save ( outputStream ) ;
28+ // Save changes to a new PDF file
29+ ldoc . Save ( outputStream ) ;
4730 }
48-
31+ // Close the document and release resources
4932 ldoc . Close ( true ) ;
5033 }
5134}
0 commit comments