PdfReport

class pdfpug.PdfReport(**kwargs)

This is the main class that assembles the elements together to create the final PDF output. All the PdfPug elements defined in the API Documentation section need to be added to this class.

Parameters:
  • theme (Optional[Theme]) – PDF file theme
  • show_page_numbers (bool) – Hide/Show page numbers (defaults to True)
  • size (Optional[PageSize]) – Size of pages in the PDF (defaults to A4)
  • orientation (Optional[PageOrientation]) – Orientation of pages in PDF (defaults to portrait)
>>> from pdfpug.modules import Header
>>> from pdfpug import PdfReport
>>> header = Header('PdfPug Header')
>>> report = PdfReport()
>>> report.add_element(header)
>>> report.generate_pdf('pug-report.pdf')

PdfPug ships with a predefined themes that can be used to further style and modernise the output pdf file.

>>> from pdfpug.common import Theme
>>> report = PdfReport(theme=Theme.mood_swing)
>>> report.generate_pdf('pug-report.pdf')
add_element(element)

Add an element to the PDF file

Parameters:element (BasePugElement) – Object instance of the different modules supported by PdfPug
Raises:TypeError – If object instance is not a PdfPug element
Return type:None
add_elements(elements)

Add multiple elements in one call to the PDF file

Parameters:elements (List[BasePugElement]) – Each element must be an object instance supported by PdfPug
Raises:TypeError – If object instance is not a PdfPug element
Return type:None
set_meta_information(title=None, description=None, authors=None, keywords=None)

Set the document’s meta information such as title, description, author etc.

Parameters:
  • title (Optional[str]) – Document title
  • description (Optional[str]) – Document description
  • authors (Optional[List[~T]]) – Document authors
  • keywords (Optional[List[~T]]) – Document keywords
Return type:

None

generate_pdf(pdf_file_path)

Generate PDF file

Parameters:pdf_file_path (str) – Absolute path of the PDF file to be created
Return type:None
class pdfpug.common.PageSize

Predefined Page sizes

a3 = 'A3'

ISO Dimensions 297mm x 420mm

a4 = 'A4'

ISO Dimensions 210mm x 297mm (most frequently used for printing)

a5 = 'A5'

ISO Dimensions 148mm x 210mm

b5 = 'B5'

ISO Dimensions 176mm x 250mm

b4 = 'B4'

ISO Dimensions 250mm x 353mm

letter = 'letter'

Equivalent to the dimensions of letter papers in North America 8.5in x 11in

legal = 'legal'

Equivalent to the dimensions of legal papers in North America 8.5in x 14in

ledger = 'ledger'

Equivalent to the dimensions of ledger papers in North America 11in x 17in

class pdfpug.common.PageOrientation

Orientation of Report

portrait = 'portrait'

Page is displayed in portrait mode where the longest edge of the page is vertical

landscape = 'landscape'

Page is displayed in landscape mode where the longest edge of the page is horizontal