The annotations module

PDF specifies several annotation types which pypdf makes available here.

The names of the annotations and their attributes do not reflect the names in the specification in all cases. For example, the PDF standard defines a ‘Square’ annotation that does not actually need to be square. For this reason, pypdf calls it ‘Rectangle’.

At their core, all annotation types are DictionaryObjects. That means if pypdf does not implement a feature, users can easily extend the given functionality.

class pypdf.annotations.AnnotationDictionary[source]

Bases: DictionaryObject, ABC

property flags: AnnotationFlag
class pypdf.annotations.MarkupAnnotation(*, title_bar: Optional[str] = None)[source]

Bases: AnnotationDictionary, ABC

Base class for all markup annotations.

Parameters

title_bar – Text to be displayed in the title bar of the annotation; by convention this is the name of the author

class pypdf.annotations.Ellipse(rect: Union[RectangleObject, Tuple[float, float, float, float]], *, interior_color: Optional[str] = None, **kwargs: Any)[source]

Bases: MarkupAnnotation

class pypdf.annotations.FreeText(*, text: str, rect: Union[RectangleObject, Tuple[float, float, float, float]], font: str = 'Helvetica', bold: bool = False, italic: bool = False, font_size: str = '14pt', font_color: str = '000000', border_color: Optional[str] = '000000', background_color: Optional[str] = 'ffffff', **kwargs: Any)[source]

Bases: MarkupAnnotation

A FreeText annotation

class pypdf.annotations.Highlight(*, rect: Union[RectangleObject, Tuple[float, float, float, float]], quad_points: ArrayObject, highlight_color: str = 'ff0000', printing: bool = False, **kwargs: Any)[source]

Bases: MarkupAnnotation

class pypdf.annotations.Line(p1: Tuple[float, float], p2: Tuple[float, float], rect: Union[RectangleObject, Tuple[float, float, float, float]], text: str = '', **kwargs: Any)[source]

Bases: MarkupAnnotation

class pypdf.annotations.Polygon(vertices: List[Tuple[float, float]], **kwargs: Any)[source]

Bases: MarkupAnnotation

class pypdf.annotations.PolyLine(vertices: List[Tuple[float, float]], **kwargs: Any)[source]

Bases: MarkupAnnotation

class pypdf.annotations.Rectangle(rect: Union[RectangleObject, Tuple[float, float, float, float]], *, interior_color: Optional[str] = None, **kwargs: Any)[source]

Bases: MarkupAnnotation

class pypdf.annotations.Text(*, rect: ~typing.Union[~pypdf.generic._rectangle.RectangleObject, ~typing.Tuple[float, float, float, float]], text: str, open: bool = False, flags: int = AnnotationFlag.None, **kwargs: ~typing.Any)[source]

Bases: MarkupAnnotation

A text annotation.

Parameters
  • rect – array of four integers [xLL, yLL, xUR, yUR] specifying the clickable rectangular area

  • text – The text that is added to the document

  • open

  • flags

Bases: AnnotationDictionary

class pypdf.annotations.Popup(*, rect: Union[RectangleObject, Tuple[float, float, float, float]], parent: Optional[DictionaryObject] = None, open: bool = False, **kwargs: Any)[source]

Bases: AnnotationDictionary