pdf.pdf
Attributes
Classes
A PDF document. |
Module Contents
- class pdf.pdf.Pdf(*args: Any, toc_levels: int = 3, created: str = '', logo: str | None = None, link_color: str | None = None, underline_links: bool = False, underline_width: float | str = 0.5, **kwargs: Any)[source]
Bases:
pdfdocument.document.PDFDocument
A PDF document.
- init_a4_portrait(page_fn: reportlab.platypus.doctemplate._PageCallback = empty_page_fn, page_fn_later: _PageCallback | None = None, *, font_size: int = 10, margin_left: float = 2.5 * cm, margin_right: float = 2.5 * cm, margin_top: float = 3 * cm, margin_bottom: float = 3 * cm) None [source]
- adjust_style(font_size: int = 10) None [source]
Sets basic styling (borrowed from common browser defaults).
- table_of_contents() None [source]
Adds a table of contents.
The entries are added automatically when adding headers. Example:
pdf = Pdf(file, author=’OneGov’, toc_levels=2) pdf.init_a4_portrait(page_fn=draw_header) pdf.table_of_contents() pdf.h1(‘Title’) pdf.generate()
- _add_toc_heading(text: str, style: reportlab.lib.styles.PropertySet, level: int) None [source]
Adds a heading with automatically adding an entry to the table of contents.
- h(title: str, level: int = 0) None [source]
Adds a header according to the given level (h1-h6).
Levels outside the supported range are added as paragraphs with h1/h6 style (without appearing in the table of contents).
- fit_size(width: float, height: float, factor: float = 1.0) tuple[float, float] [source]
Returns the given width and height so that it fits on the page.
- image(filelike: StrOrBytesPath | SupportsRead[bytes], factor: float = 1.0) None [source]
Adds an image and fits it to the page.
- pdf(filelike: StrOrBytesPath | SupportsRead[bytes], factor: float = 1.0) None [source]
Adds a PDF and fits it to the page.
- table(data: Sequence[Sequence[str | Paragraph]], columns: Literal['even'] | Sequence[float | None] | None, style: TableStyle | Iterable[_TableCommand] | None = None, ratios: Literal[False] = False) None [source]
- table(data: Sequence[Sequence[str | Paragraph]], columns: Literal['even'] | list[float] | None, style: TableStyle | Iterable[_TableCommand] | None = None, *, ratios: Literal[True]) None
- table(data: Sequence[Sequence[str | Paragraph]], columns: Literal['even'] | list[float] | None, style: TableStyle | Iterable[_TableCommand] | None, ratios: Literal[True]) None
- table(data: Sequence[Sequence[str | Paragraph]], columns: Literal['even'] | Sequence[float | None] | None, style: TableStyle | Iterable[_TableCommand] | None = None, ratios: bool = False) None
Adds a table where every cell is wrapped in a paragraph so that the cells are wrappable.
Adds a figure caption.
- mini_html(html: str | None, linkify: bool = False) None [source]
Convert a small subset of HTML into ReportLab paragraphs.
This is very limited and currently supports only links, paragraphs and non-nested ordered/unordered lists.
If linkifing is enabled, a-tags are cleaned and kept and the html is linkified automatically.