@@ -480,6 +480,9 @@ def __init__(self, filename):
480
480
481
481
self .paths = []
482
482
483
+ self .pageAnnotations = [] # A list of annotations for the
484
+ # current page
485
+
483
486
# The PDF spec recommends to include every procset
484
487
procsets = [Name (x )
485
488
for x in "PDF Text ImageB ImageC ImageI" .split ()]
@@ -507,7 +510,8 @@ def newPage(self, width, height):
507
510
'Contents' : contentObject ,
508
511
'Group' : {'Type' : Name ('Group' ),
509
512
'S' : Name ('Transparency' ),
510
- 'CS' : Name ('DeviceRGB' )}
513
+ 'CS' : Name ('DeviceRGB' )},
514
+ 'Annots' : self .pageAnnotations ,
511
515
}
512
516
pageObject = self .reserveObject ('page' )
513
517
self .writeObject (pageObject , thePage )
@@ -519,6 +523,20 @@ def newPage(self, width, height):
519
523
# graphics context: currently only the join style needs to be set
520
524
self .output (GraphicsContextPdf .joinstyles ['round' ], Op .setlinejoin )
521
525
526
+ # Clear the list of annotations for the next page
527
+ self .pageAnnotations = []
528
+
529
+ def newTextnote (self , text , positionRect = [- 100 , - 100 , 0 , 0 ]):
530
+ # Create a new annotation of type text
531
+ theNote = {'Type' : Name ('Annot' ),
532
+ 'Subtype' : Name ('Text' ),
533
+ 'Contents' : text ,
534
+ 'Rect' : positionRect ,
535
+ }
536
+ annotObject = self .reserveObject ('annotation' )
537
+ self .writeObject (annotObject , theNote )
538
+ self .pageAnnotations .append (annotObject )
539
+
522
540
def close (self ):
523
541
self .endStream ()
524
542
# Write out the various deferred objects
@@ -2447,6 +2465,15 @@ def get_pagecount(self):
2447
2465
"""
2448
2466
return len (self ._file .pageList )
2449
2467
2468
+ def attach_note (self , text , positionRect = [- 100 , - 100 , 0 , 0 ]):
2469
+ """
2470
+ Add a new text note to the page to be saved next. The optional
2471
+ positionRect specifies the position of the new note on the
2472
+ page. It is outside the page per default to make sure it is
2473
+ invisible on printouts.
2474
+ """
2475
+ self ._file .newTextnote (text , positionRect )
2476
+
2450
2477
2451
2478
class FigureCanvasPdf (FigureCanvasBase ):
2452
2479
"""
0 commit comments