https://github.com/djav1985/v-gpt-pdf-generator
The v-gpt-pdf-generator is an efficient, FastAPI-based web service designed to convert HTML and CSS content into high-quality PDFs. By leveraging WeasyPrint for PDF generation, it facilitates asynchronous operations using Aiohttp and Aiofiles, ensuring fast and scalable performance. The application is containerized for ease of deployment.
https://github.com/djav1985/v-gpt-pdf-generator
ai api chatgpt dify docker fastapi flowise flowise-ai gpt openai openapi pdf pdf-generation python weasyprint
Last synced: 2 months ago
JSON representation
The v-gpt-pdf-generator is an efficient, FastAPI-based web service designed to convert HTML and CSS content into high-quality PDFs. By leveraging WeasyPrint for PDF generation, it facilitates asynchronous operations using Aiohttp and Aiofiles, ensuring fast and scalable performance. The application is containerized for ease of deployment.
- Host: GitHub
- URL: https://github.com/djav1985/v-gpt-pdf-generator
- Owner: djav1985
- Created: 2024-07-05T20:55:34.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-09-19T22:41:53.000Z (9 months ago)
- Last Synced: 2025-09-20T00:57:19.462Z (9 months ago)
- Topics: ai, api, chatgpt, dify, docker, fastapi, flowise, flowise-ai, gpt, openai, openapi, pdf, pdf-generation, python, weasyprint
- Language: Python
- Homepage: https://vontainment.com
- Size: 4.62 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Agents: AGENTS.md
Awesome Lists containing this project
README
Transform Ideas into PDFs, Effortlessly!
Developed with the software and tools below.
Table of Contents
- [๐ Overview](#-overview)
- [๐งฉ Features](#-features)
- [๐๏ธ Repository Structure](#๏ธ-repository-structure)
- [๐ฆ Modules](#-modules)
- [๐ Getting Started](#-getting-started)
- [โ๏ธ Installation](#๏ธ-installation)
- [๐ค Usage](#-usage)
- [๐ Project Changelog](#-project-changelog)
- [๐ License](#-license)
## ๐ Overview
The project is a robust PDF Generation API built on FastAPI, designed to streamline the creation of PDF documents from HTML content. It offers a user-friendly interface that allows users to submit requests and generate customized PDFs while ensuring secure access through API key validation. By leveraging containerization with Docker, the application ensures seamless deployment and operation, facilitating efficient scaling and management. The value proposition lies in its ability to provide high-quality, customizable document generation capabilities, making it an essential tool for developers needing to integrate PDF functionalities into their applications while maintaining a clean and organized codebase.
---
## ๐งฉ Features
| | Feature | Description |
|----|-------------------|---------------------------------------------------------------|
| โ๏ธ | **Architecture** | A microservice architecture utilizing FastAPI for web services and asynchronous capabilities. Docker containers orchestrate the PDF generation service, enhancing deployment and scalability. |
| ๐ฉ | **Code Quality** | The codebase follows PEP 8 style guidelines with clear variable names, modular functions, and consistent formatting. It emphasizes clean code practices, improving readability and maintainability. |
| ๐ | **Documentation** | Documentation is comprehensive, detailing setup with `requirements.txt`, `Dockerfile`, and `docker-compose.yml`. In-line comments and structured organization guide users through the core functionalities. |
| ๐ | **Integrations** | Essential integrations include FastAPI for building APIs and WeasyPrint for PDF generation. These components facilitate seamless data handling and PDF services. |
| ๐งฉ | **Modularity** | The codebase is highly modular, with separate files for routing, models, and dependencies. This structure promotes reusability and easier testing, allowing developers to update components independently. |
| ๐งช | **Testing** | Automated test suite covers PDF generation, request validation, authentication, cleanup, and routes. |
| โก๏ธ | **Performance** | Optimized for high efficiency, the application handles multiple requests concurrently with FastAPI, minimizing response times and resource usage through asynchronous programming. |
| ๐ก๏ธ | **Security** | Employs API key validation and secure access measures. Techniques like input validation and error handling safeguard against common vulnerabilities during PDF generation. |
| ๐ฆ | **Dependencies** | Key dependencies include FastAPI, WeasyPrint, Pydantic for data validation, aiofiles for file handling, and uvicorn for running the application, ensuring robust functionality and performance. |
| ๐ | **Scalability** | Designed to scale effectively with containerization using Docker. FastAPI enables asynchronous processing, allowing the application to manage increased loads and user requests without degradation of performance. |
---
## ๐๏ธ Repository Structure
```sh
โโโ /
โโโ Dockerfile
โโโ README.md
โโโ app
โ โโโ __init__.py
โ โโโ dependencies.py
โ โโโ main.py
โ โโโ models.py
โ โโโ routes
โ โโโ __init__.py
โ โโโ create.py
โโโ docker-compose.yml
โโโ requirements.txt
โโโ v-gpt-pdf-generator.png
```
---
## ๐ฆ Modules
.
| File | Summary |
| --- | --- |
| [requirements.txt](requirements.txt) | Defines essential dependencies for the application, ensuring compatibility and functionality of key libraries. By incorporating FastAPI, WeasyPrint, and other critical packages, it enables robust web service capabilities, document generation, and efficient data handling, aligning seamlessly with the repositorys architecture to support the overall application goals. |
| [docker-compose.yml](docker-compose.yml) | Facilitates the orchestration of a PDF generation service within the repositorys architecture by defining the containerized environment. It configures essential parameters such as network settings, environment variables, and persistent storage, ensuring seamless integration and operation of the PDF generation application. |
| [Dockerfile](Dockerfile) | Facilitates the creation and deployment of a FastAPI application by establishing a multi-stage Docker environment. It efficiently manages Python dependencies, integrates necessary system libraries for rendering, and configures runtime parameters while ensuring the application is accessible on port 8888, aligning with the overall architecture of the repository. |
app
| File | Summary |
| --- | --- |
| [main.py](app/main.py) | Facilitates the core functionality of the PDF Generation API by establishing a FastAPI application, integrating routing for PDF creation, and serving generated PDFs through a dedicated static files directory. This setup enhances the repositorys architecture by providing a scalable and organized approach to handle PDF generation requests. |
| [dependencies.py](app/dependencies.py) | Facilitates asynchronous PDF generation and cleanup tasks within the repository. It crafts customized HTML templates from content and CSS, integrates code highlighting, and manages a downloads folder by removing outdated files. Additionally, it ensures API key validation for secure access to the application. |
| [models.py](app/models.py) | Defines a data model for generating PDFs, ensuring structured input through required fields like title and body content, while allowing optional custom styling and filenames. This model seamlessly integrates with the applications architecture to facilitate user-friendly PDF creation from HTML content, enhancing overall functionality. |
app.routes
| File | Summary |
| --- | --- |
| [create.py](app/routes/create.py) | Facilitates PDF generation by processing user requests and producing downloadable files. It ensures unique filename creation, integrates API key verification, and handles exceptions gracefully, enhancing the overall functionality of the application by linking user inputs with the PDF creation process effectively within the repositorys architecture. |
---
## ๐ Getting Started
**System Requirements:**
* **Python**: `version 3.10`
### โ๏ธ Installation
1. **Download the `docker-compose.yml` file**:
Save the provided `docker-compose.yml` file to your project directory.
2. **Edit Environment Variables**:
The application reads `BASE_URL`, `ROOT_PATH`, and `API_KEY` using a Pydantic
`Settings` model located in `app/config.py`. These values can be supplied via
environment variables or a `.env` file. Open the `docker-compose.yml` file and
set the environment variables according to your setup:
```yaml
environment:
BASE_URL: https://api.servicesbyv.com # Set this to your actual base URL
ROOT_PATH: /pdf
API_KEY: # Optional API key to connect to the API
WORKERS: 1 # Number of Uvicorn workers; 1 is usually enough for personal use
UVICORN_CONCURRENCY: 32 # Max connections; anything over this number is rejected
```
3. **Run the Docker Compose**:
Use the following command to start the service:
```bash
docker-compose up
```
4. **(Optional) Run in Detached Mode**:
To run the containers in the background, use:
```bash
docker-compose up -d
```
### ๐ค Usage
#### From `docker-compose`
1. **Access the OpenAPI Specifications**:
To get the OpenAPI specifications and integrate with your AI tool, navigate to:
```
BASE_URL/openapi.json
```
Replace `BASE_URL` with the actual URL of your application (e.g., `https://api.servicesbyv.com/pdf/openapi.json`).
A generated copy of this specification is available in `openapi.json` at the project root.
2. **Generate a PDF**:
Send a POST request to the root endpoint with a JSON body:
```bash
curl -X POST "$BASE_URL/" \\
-H "Content-Type: application/json" \\
-H "X-API-Key: $API_KEY" \\ # optional
-d '{
"pdf_title": "Example",
"body_content": "
Hello
",
"contains_code": false,
"css_content": "p { color: blue; }",
"output_filename": "example"
}'
```
The response includes a `url` to download the generated PDF from `/downloads`.
If `BASE_URL` is not set, this will be a relative path.
---
## ๐ Project Changelog
- `โบ Added better default CSS`
- `โบ Added title parameter to set the H1 header`
- `โบ Added contains_code parameter to allow formatted code blocks`
- `โบ Added output_filename parameter for custom file names`
---
## ๐ License
This project is protected under the MIT Licence
---
[**Return**](#-overview)
---