https://github.com/muhammadrafayasif/labs-to-pdf
A python script that compiles and executes lab programs, captures results, and generates formatted PDF reports ready for submission.
https://github.com/muhammadrafayasif/labs-to-pdf
assignments automation python3 script
Last synced: 3 months ago
JSON representation
A python script that compiles and executes lab programs, captures results, and generates formatted PDF reports ready for submission.
- Host: GitHub
- URL: https://github.com/muhammadrafayasif/labs-to-pdf
- Owner: muhammadrafayasif
- License: mit
- Created: 2025-10-19T11:52:41.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-11-21T15:26:18.000Z (8 months ago)
- Last Synced: 2025-11-21T17:18:08.367Z (8 months ago)
- Topics: assignments, automation, python3, script
- Language: C++
- Homepage:
- Size: 768 KB
- Stars: 1
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# π§Ύ Automated Lab Report Generator (Python + ReportLab)
This project automatically compiles, runs, and generates PDF lab reports for programming labs.
It handles everything β from compiling C++ files to capturing output and formatting it into a professional, university-style PDF with your name, roll number, and department.
---
## πΈ Sample Output
The generated PDF includes:
- University logo and title page
- Each lab questionβs source code
- Automatically captured program output (styled like a terminal)
- Execution time for each task
- Automatic date and metadata
Example PDF: [CT-24000.pdf](/Lab%201/CT-24000_Lab1.pdf)
---
## βοΈ Features
- β
Automatic Compilation β Uses `g++` to compile each `.cpp` file
- π€ Output Capture β Captures console output and formats it like a terminal
- ποΈ Beautiful PDF Generation β Uses ReportLab for clean, styled reports
- π§βπ Customizable Branding β Add your own logo, name, roll number, department, and degree
- π Multi-Lab Support β Process multiple folders like `"Lab 1"`, `"Lab 2"`, etc.
- β±οΈ Execution Timing β Displays how long each program took to run
- π οΈ Error Handling β Gracefully reports compilation or runtime errors
---
## ποΈ Project Structure
```bash
π¦ labs-to-pdf/
β
βββ Lab 1/
β βββ 1.cpp
β βββ 2.cpp
β βββ ...
β
βββ logo.png # University logo for the title page
βββ make_pdfs.py # Main automation script
βββ README.md
```
---
## π§° Requirements
Youβll need:
* Python 3.8+
* A C++ compiler (e.g., `g++`)
* ReportLab for PDF generation
Install dependencies with:
```bash
pip install reportlab
```
---
## π§βπ» Usage
1. Place your files inside folders like `Lab 1`, `Lab 2`, etc.
2. Update configuration at the top of `make_pdfs.py`:
```python
EXTENSION = "cpp"
LOGO_PATH = "./logo.png"
PROCESS = ["Lab 1"] # Folder names, must match exactly
KEEP_TOGETHER = True # Skip to next page if the question starts at the end of page
KEEP_EXE = False # Remove or keep the .exe file generated automatically
""" Enter the user inputs for each lab in the following order:
INPUTS = [
[Q1 INPUTS, Q2 INPUTS, Q3 INPUTS, ...], # For Lab 1 (According to the first lab provided in the PROCESS list)
[Q1 INPUTS, Q2 INPUTS, Q3 INPUTS, ...], # For Lab 2 (According to the second lab provided in the PROCESS list)
...
]
For example, If Q2 does not take input, leave it as an empty string
["2 2", "", "1 4"]
"""
INPUTS = [
]
""" The QUESTIONS list follows the same format as the INPUT list provided above """
QUESTIONS = [
]
EXECUTION_TIMEOUT = 5 # seconds
UNIVERSITY = "NED University of Engineering and Technology"
NAME = "NAME"
ROLL_NO = "CT-24000"
DEPARTMENT = "Department of Computer Science and Information Technology"
DEGREE = "Bachelor of Science (BS)"
```
3. Run the generator:
```bash
python make_pdfs.py
```
4. PDFs will be generated inside each lab folder individually.
---
## π§ Tips
* A custom font can be used, simply replace `font.ttf` with another font of your choice.
* Ensure your files compile cleanly and produce output.
* Customize fonts, colors, and layout by editing the paragraph and table styles in the script.
* Adjust the `EXECUTION_TIMEOUT` constant in the script if your programs take longer to run.
---
## πͺͺ License
This project is released under the [MIT License](LICENSE).
Feel free to modify and adapt it for your institution or personal use.
---