Skip to main content

A Python Document Management Framework for generating and sending (pdf, docx, etc) documents to customers

Project description

PyPI

Creates, merges, splits, edits documents(mainly docx/pdf) as well as sending them by email. Originally created for QR bills integration but is generic and can be used for much more.

Installation

Installation with pip:

$ pip install doc-workflow

Usage

From the command line:

$ docwf <path_to_json_config_file>

From Python:

from docwf import DocWorkflow

config_obj = {
    "globals": {
        "workbook": "source.xlsx",
        "sheet": "mailmergesheet",
        "constants": {
            "language": "fr"
        }
    },
    "tasks": [
        {
            "active": 1, # you can activate/deactivate tasks
            "name": "create bills", # name for debug purpose
            "locals": {
                "key" : "value", # overrides global arguments for the task
            },
            "task": {
                "type": "myplugin", # or builtin plugins (see below)
                "task_dependent_argument": "value{param}",
            }
        },
    ]
}
my_plugins = {
    "myplugin": MyPluginClass
}
DocWorkflow(config_obj, plugins=my_plugins).gen()

Typical workflow tasks

Assume the data is in the source.xlsx in the sheet named bills

clientnr

email

send_email

total

reference

etc

1

c1@gmail.com

yes

1032

ref2022c1

2

c2@gmail.com

yes

1232

ref2022c2

Create bills from Word template

{
    "active": 1, # you can activate/deactivate tasks
    "name": "create bills", # name for debug purpose
    "task": {
        "type": "mailmerge",
        "input_docx": "templates/template_bill.docx",
        "output_docx": "bills/bill_{year}.docx" # output depends on the column year, it should be constant throughout all rows
    }
},

Create pdf from the generated docx

It uses the Word Application (Mac/Windows). If the docx template has dynamic fields (IF, etc), the generated docx will ask permission to update all fields before saving it as pdf.

{
    "name": "save pdf from docx (uses Word)",
    "task": {
        "type": "makepdf",
        "input_docx": "bills/bill_{year}.docx",
        "output_pdf": "bills/bill_{year}.pdf"
    }
},

Fills in QR codes

for the bills by adding a page to each bill or by merging the QR bill into one of the pages.

{
    "name": "create qr bills",
    "locals": {
        "creditor": {
            "iban": "CH....",
            "name": "The Good Company",
            "pcode": "xyzt",
            "city": "Bern",
            "street": "Dorfstrasse 1"
        },
        "task_params": {
            "extra_infos": "reference", # fixed keys for bill reason ...
            "amount": "total"   # and the amount. With task_params you can create data entries out of existing columns
        }
    },
    "task": {
        "type": "qr",
        "merge_type": "merge", # or "append"
        "input_filename": "bills/bill_{year}.pdf",
        "delete_input": true, # delete the input filename after creating the output
        "pages": 2, # the number of pages per each bill
        "merge_pos": 2, # or "insert_pos" if "append"
        "output_filename": "bills/bill_{year}_with_qr.pdf"
    }
},

Split the bills into separate pdf files.

From one input to multiple outputs

{
    "name": "split bills",
    "task": {
        "type": "split_pdf",
        "input_filename": "bills/bill_{year}_with_qr.pdf",
        "pages": 2,
        "makedir": "bills/bills_{year}", # if the output directory doesn't exist, create it
        "output_filename": "bills/bills_{year}/bill_{year}_{clientnr}.pdf" # output filename using unique name for each customer
    }
},

Unify bills that are to be printed

This shows how to filter rows. The same split_pdf plugin is used, from multiple inputs to one output.

{
    "name": "unify bills for print",
    "filter": {"column": "send_email", "value": "no"},
    "task": {
        "type": "split_pdf",
        "input_filename": "bills/bills_{year}/bill_{year}_{clientnr}.pdf",
        "delete_input": true,
        "pages": 2,
        "output_filename": "bills/bills_{year}_paper.pdf"
    }
},

Send the bills by email

{
    "name": "send emails",
    "locals": {
        "sender": {
            "email": "info@domain.com",
            "name": "Info",
            "server": "smtp.gmail.com:587",
            "username": "info@domain.com",
            "password": "strongpassword",
            "bcc": "bills@domain.com",
            "headers": {
                "Reply-To": "contability@domain.com"
            }
        },
    },
    "filter": {"column": "send_email", "value": "yes"},
    "task": {
        "type": "email",
        "recipient": "email", # the key/column name for the customer email
        "subject" : "Bill for year {year}", # can contain dynamic parts
        "body_template_file" : "templates/email_template.txt", # text template for the email body
        "attachments" : [ "bills/bills_{year}/bill_{year}_{clientnr}.pdf" ] # list of attachments
    }
},

Watermark PDF files

Mark reminder bills

{
    "name": "save reminder",
    "filter": {"column": "reminder", "value": "yes"},
    "task": {
        "type": "watermark",
        "makedir": "bills/bills_{key_year}/reminders/",
        "watermark": "REMINDER",
        "input_filename": "bills/bills_{year}/bill_{year}_{clientnr}.pdf",
        "pages": 2,
        "output_filename": "bills/bills_{year}/reminders/bill_{year}_{clientnr}_reminder.pdf"
    }
},

Send reminder bills

{
    "name": "send reminder emails",
    "locals": {
        "sender": {
            ...
        },
    },
    "filter": [
        {"column": "send_email", "value": "yes"},
        {"column": "reminder", "value": "yes"}
    ],
    "task": {
        "type": "email",
        "recipient": "email", # the key/column name for the customer email
        "subject" : "Bill for year {year} (reminder)", # can contain dynamic parts
        "body_template_file" : "templates/reminder_email_template.txt", # text template for the email body
        "attachments" : [ "bills/bills_{year}/reminders/bill_{year}_{clientnr}_reminder.pdf" ] # list of attachments
    }
},

Todo / Wish List

  • Create unit tests

  • Develop the command line to be able to run simple tasks directly

  • Add Google Sheets support for the data

  • Create more advanced filters

  • Auto-magically create directories (remove the makedir argument)

Contributing

  • Fork the repository on GitHub and start hacking

  • Send a pull request with your changes

Credits

This repository is created and maintained by Iulian Ciorăscu.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

doc-workflow-0.1.0a12.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

doc_workflow-0.1.0a12-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file doc-workflow-0.1.0a12.tar.gz.

File metadata

  • Download URL: doc-workflow-0.1.0a12.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for doc-workflow-0.1.0a12.tar.gz
Algorithm Hash digest
SHA256 3eeb8a67c958da7c12d36878d053aba87b0e53dc22a57636c6f870c5e55d75d8
MD5 7373a28467dc42cde8362f0b793ca18a
BLAKE2b-256 19cb07be331c78d274bd24feb7f0e2ae8d44ff8a9116654a39be4c337ac53d3f

See more details on using hashes here.

File details

Details for the file doc_workflow-0.1.0a12-py3-none-any.whl.

File metadata

File hashes

Hashes for doc_workflow-0.1.0a12-py3-none-any.whl
Algorithm Hash digest
SHA256 57f831f5ef3c7b3d533ac4aa61bd0d7037c97dd8a52f841c65f47eebe2f17b18
MD5 c961a4467fd50f59ab3548dc798755b2
BLAKE2b-256 1b54a8164b624c4ea05fa19ffab104a472dfb593d5a0b62eb849f670aaaa4d9b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page