Skip to content

Fill variables (of a given dataset input) into the Austrian "Post AG - Vorlage mit Absender" letter template using ReportLab library in Python.

License

Notifications You must be signed in to change notification settings

roboes/at-post-letter-template

Repository files navigation

Austrian Post Letter Template

Description

This tool aims to fill variables (of a given dataset input) into the Austrian Post AG - Vorlage mit Absender letter template using ReportLab library in Python and save it as a .pdf file. The main features are:

  • Create a .pdf letter in A4 respecting the letter design settings defined by the Post AG.
  • Iteration to create a .pdf with multiple pages (one letter per page), taking recipients from a given dataset (an example is provided in the at-post-letter-template.py code).
  • Fully personalizable: each text block is divided into frames; for each frame, it is possible to change the font and font size, add boundary to the text frames, change text colors, etc. Also specific words/sentences can be formatted (bold, italic, etc.) using simple HTML.

Output

Output

Usage

Python dependencies

python -m pip install babel pandas reportlab

Functions

create_document

create_document(df, title, author, file_name)

Description

  • Fill variables (of a given dataset input) into the Austrian Post AG - Vorlage mit Absender letter template and outputs it as a .pdf file.

Parameters

  • df: DataFrame. The input DataFrame containing names, gender and addresses data.
  • title: str. PDF title metadata attribute (e.g. title='Post AG - Vorlage mit Absender').
  • author: str. PDF author metadata attribute (e.g. author='Post AG').
  • file_name: str. File name of the generated Austrian Post AG - Vorlage mit Absender letter template (e.g. file_name='Post AG - Vorlage mit Absender.pdf').

Code Workflow Example

# Create example DataFrame with names, gender and addresses
df = pd.DataFrame(
    data=[
        [
            'Eva Muster',
            'F',
            'Österreich',
            'Musterbundesland',
            '9875',
            'Musterstadt',
            'Musterstraße 1',
        ],
        [
            'Max Mustermann',
            'M',
            'Österreich',
            'Musterbundesland',
            '9875',
            'Musterstadt',
            'Musterstraße 1',
        ],
        [
            'Firma ABC',
            '',
            'Österreich',
            'Musterbundesland',
            '9875',
            'Industriestadt',
            'Industriestraße 1',
        ],
    ],
    index=None,
    columns=[
        'name',
        'gender',
        'location_country',
        'location_state',
        'location_postal_code',
        'location_city',
        'location_street',
    ],
    dtype=None,
)

# Create .pdf document
create_document(
    df=df,
    title='Post AG - Vorlage mit Absender',
    author='Post AG',
    output_directory=os.path.join(os.path.expanduser('~'), 'Downloads'),
    file_name='Post AG - Vorlage mit Absender.pdf',
)

Documentation

About

Fill variables (of a given dataset input) into the Austrian "Post AG - Vorlage mit Absender" letter template using ReportLab library in Python.

Resources

License

Stars

Watchers

Forks

Languages