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[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') 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[RectangleObject, Tuple[float, float, float, float]], text: str = '', title_bar: str = '') 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
- static link(rect: ~typing.Union[~PyPDF2.generic._rectangle.RectangleObject, ~typing.Tuple[float, float, float, float]], border: ~typing.Optional[~PyPDF2.generic._data_structures.ArrayObject] = None, url: ~typing.Optional[str] = None, target_page_index: ~typing.Optional[int] = None, fit: ~PyPDF2.generic._fit.Fit = <PyPDF2.generic._fit.Fit object>) DictionaryObject [source]
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 (Fit) – Page fit or ‘zoom’ option.
- static rectangle(rect: Union[RectangleObject, Tuple[float, float, float, float]], interiour_color: Optional[str] = None) 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[RectangleObject, Tuple[float, float, float, float]], text: str, open: bool = False, flags: int = 0) 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) –