An open API service indexing awesome lists of open source software.

https://github.com/samshad/clipboardtopdf

A Python automation utility that instantly converts clipboard content (Markdown or Plain Text) into professionally styled PDFs. Features smart auto-naming, date-based archiving, and crash-proof error handling.
https://github.com/samshad/clipboardtopdf

automation clipboard-tool markdown pdf-generation productivity python wkhtmltopdf workflow

Last synced: about 2 months ago
JSON representation

A Python automation utility that instantly converts clipboard content (Markdown or Plain Text) into professionally styled PDFs. Features smart auto-naming, date-based archiving, and crash-proof error handling.

Awesome Lists containing this project

README

          

# 📋 ClipboardToPDF

**ClipboardToPDF** is a lightweight Python automation tool that instantly converts your clipboard content into professionally styled PDF documents.

Unlike standard "Save as PDF" workflows, this tool automates the entire metadata process: it intelligently parses your text to generate a filename, detects dates for organization, and archives files into a structured timeline folder system.

## 🚀 Key Features

* **Universal Input:** Works with **Markdown** (headers, tables, code blocks) or **Plain Text**.
* **Smart Auto-Naming:**
* Detects Markdown headers (`# Title`) to name the file.
* Falls back to the first line of text for generic notes.

* **Automatic Filing:** Creates a timeline directory structure (`Documents/Clipboard_Archives/2025/12_December/`) so you never have to organize files manually.
* **Professional Styling:** Applies a clean, minimal CSS theme suitable for printing (A4/Letter margins).
* **Crash-Proof:** Includes robust error handling for empty clipboards and text encoding issues.

## 🛠️ Prerequisites

### 1. System Dependency (Critical)

This tool requires the **wkhtmltopdf** rendering engine.

* **Windows:** Download the [wkhtmltopdf installer](https://wkhtmltopdf.org/downloads.html) (64-bit).
* **Default Path:** The script expects it at `C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe`.

### 2. Python Environment

* Python 3.8+ recommended.

## 📦 Installation

1. **Clone or Download** this repository.
2. **Create a Virtual Environment** (Recommended):
```bash
python -m venv venv
.\venv\Scripts\activate

```

3. **Install Dependencies**:
Create a `requirements.txt` file with the following content:
```text
pdfkit>=1.0.0
pyperclip>=1.8.2
markdown>=3.4.1

```

Then run:
```bash
pip install -r requirements.txt

```

## 🖥️ Usage

1. **Copy Text:** Highlight text from anywhere (AI Chat, Notepad, Browser) and press `Ctrl+C`.
2. **Run Script:**
```bash
python clipboard_to_pdf.py

```

3. **Done:** The script will print the saved location and automatically open the folder containing your new PDF.

### Example Inputs & Outputs

| Input Type | Extracted Filename | Filing Path |
| --- | --- | --- |
| **Markdown Report** | `# Shift Log Dec 19` | `.../2025/12_December/Shift Log Dec 19.pdf` |
| **Grocery List** | `Milk, Eggs, Bread...` | `.../2025/12_December/Milk_Eggs_Bread.pdf` |
| **Code Snippet** | `# Python Script` | `.../2025/12_December/Python Script.pdf` |

## ⚙️ Configuration

You can customize the script by editing the constants at the top of `clipboard_to_pdf.py`:

```python
# Change where files are saved
BASE_SAVE_DIR = Path.home() / "Documents" / "Clipboard_Archives"

# Update if you installed wkhtmltopdf in a custom location
WKHTMLTOPDF_PATH = Path(r'C:\Custom\Path\wkhtmltopdf.exe')

```

## 🔧 Troubleshooting

**Error: "wkhtmltopdf not found"**

* Ensure you have installed the software (not just the Python library).
* Verify `WKHTMLTOPDF_PATH` matches your installation path.

**Error: "Clipboard is empty"**

* Copy your text *before* running the script.
* Some remote desktop apps do not share the clipboard with the host machine.

## 📄 License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

---

**Author:** Md Samshad Rahman