The AnnotationBuilder Class

class PyPDF2.generic.AnnotationBuilder[source]

Bases: object

The AnnotationBuilder creates dictionaries representing PDF annotations.

Those dictionaries can be modified before they are added to a PdfWriter instance via writer.add_annotation.

See adding PDF annotations for it’s usage combined with PdfWriter.

static free_text(text: str, rect: Union[PyPDF2.generic._rectangle.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: str = '000000', background_color: str = 'ffffff') PyPDF2.generic._data_structures.DictionaryObject[source]

Add text in a rectangle to a page.

Parameters
  • text (str) – Text to be added

  • rect (RectangleObject) – or array of four integers specifying the clickable rectangular area [xLL, yLL, xUR, yUR]

  • font (str) – Name of the Font, e.g. ‘Helvetica’

  • bold (bool) – Print the text in bold

  • italic (bool) – Print the text in italic

  • font_size (str) – How big the text will be, e.g. ‘14pt’

  • font_color (str) – Hex-string for the color

  • border_color (str) – Hex-string for the border color

  • background_color (str) – Hex-string for the background of the annotation

static line(p1: Tuple[float, float], p2: Tuple[float, float], rect: Union[PyPDF2.generic._rectangle.RectangleObject, Tuple[float, float, float, float]], text: str = '', title_bar: str = '') PyPDF2.generic._data_structures.DictionaryObject[source]

Draw a line on the PDF.

Parameters
  • p1 (Tuple[float, float]) – First point

  • p2 (Tuple[float, float]) – Second point

  • rect (RectangleObject) – or array of four integers specifying the clickable rectangular area [xLL, yLL, xUR, yUR]

  • text (str) – Text to be displayed as the line annotation

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

Add a link to the document.

The link can either be an external link or an internal link.

An external link requires the URL parameter. An internal link requires the target_page_index, fit, and fit args.

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

  • border – if provided, an array describing border-drawing properties. See the PDF spec for details. No border will be drawn if this argument is omitted. - horizontal corner radius, - vertical corner radius, and - border width - Optionally: Dash

  • url (str) – Link to a website (if you want to make an external link)

  • target_page_index (int) – index of the page to which the link should go (if you want to make an internal link)

  • fit (str) – Page fit or ‘zoom’ option (see below). Additional arguments may need to be supplied. Passing None will be read as a null value for that coordinate.

  • fit_args (Tuple[int, ...]) – Parameters for the fit argument.

Valid fit arguments (see Table 8.2 of the PDF 1.7 reference for details)

/Fit

No additional arguments

/XYZ

[left] [top] [zoomFactor]

/FitH

[top]

/FitV

[left]

/FitR

[left] [bottom] [right] [top]

/FitB

No additional arguments

/FitBH

[top]

/FitBV

[left]

static rectangle(rect: Union[PyPDF2.generic._rectangle.RectangleObject, Tuple[float, float, float, float]], interiour_color: Optional[str] = None) PyPDF2.generic._data_structures.DictionaryObject[source]

Draw a rectangle on the PDF.

Parameters

rect (RectangleObject) – or array of four integers specifying the clickable rectangular area [xLL, yLL, xUR, yUR]

static text(rect: Union[PyPDF2.generic._rectangle.RectangleObject, Tuple[float, float, float, float]], text: str, open: bool = False, flags: int = 0) PyPDF2.generic._data_structures.DictionaryObject[source]

Add text annotation.

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

  • open (bool) –

  • flags (int) –