PDF Aggregator is a Python library and wrapper script that generates a PDF report based on data provided. It uses the ReportLab library to create the PDF document.
- Generate PDF reports with customizable data.
- Support for fetching data from a PostgreSQL database.
- Simple and easy-to-use interface.
- Clone the repository:
git clone https://github.com/williambiederman/pdf-aggregator.git- Change into the project directory:
cd pdf-aggregator-
Install the required dependencies:
- Using a virtual environment
python -m venv venv . venv/bin/activate (venv) pip install -r requirements.txt- Directly.
pip install -r requirements.txt
-
Optional: Copy the
.env_examplefile to.envand update theDATABASE_CONNECTION_STRING. You can pass this in with the--databaseoption later.
This tool allows a user to dynamically create a PDF from data in a PostgreSQL table with the following command.
python main.py -d DATABASE_CONNECTION_STRING -q SQL_QUERY -o OUTPUT_FILENAME
-d, --database: Database connection string. This can also be set in a .env file.
-q, --query: SQL query to be rendered in the PDF.
-o, --output: Output file path.
If the --database argument is not provided, the tool will attempt to use the DATABASE_CONNECTION_STRING from the .env file.
If any of the required arguments are missing, an error message will be displayed.
If you do not already have a PostgreSQL installation and would like to use the example server, follow these steps.
Navigate to the root directory of this project and modify the Dockerfile with any credentials you'd like.
Build the image using the Dockerfile.
docker build -t example-postgres-image .
Next, run the container with this command.
docker run -d --name example-postgres-container -p 5432:5432 example-postgres-image
You can use this command with the settings from the Dockerfile to test the connection.
docker exec -it example-postgres-container psql -h localhost -p 5432 -U POSTGRES_USER -d POSTGRES_DB
If you've set the DATABASE_CONNECTION_STRING in the .env file, you can run the current unit tests by navigating to the root directory of the project and using this commands.
python -m unittest discover -s tests -p 'test_*.py'Note: If you're using a virtual environment, you'll have to activate it to run tests.
This project is licensed under the MIT License. See the LICENSE file for more information.