pdf.pdf

Attributes

_DocT

TABLE_CELL_CHAR_LIMIT

Classes

Pdf

A PDF document.

Module Contents

pdf.pdf._DocT[source]
pdf.pdf.TABLE_CELL_CHAR_LIMIT = 2000[source]
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.

toc: reportlab.platypus.tableofcontents.TableOfContents | None[source]
toc_numbering: dict[int, int][source]
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.ParagraphStyle, level: int) None[source]

Adds a heading with automatically adding an entry to the table of contents.

h1(title: str, style: ParagraphStyle | None = None) None[source]
h2(title: str, style: ParagraphStyle | None = None) None[source]
h3(title: str, style: ParagraphStyle | None = None) None[source]
h4(title: str, style: ParagraphStyle | None = None) None[source]
h5(title: str, style: ParagraphStyle | None = None) None[source]
h6(title: str, style: ParagraphStyle | None = None) None[source]
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.

figcaption(text: str, style: ParagraphStyle | None = None) None[source]

Adds a figure caption.

static strip(text: str) str[source]
static inner_html(element: lxml.etree._Element) str[source]
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.