Skip to content

samshad/ClipboardToPDF

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📋 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 (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):
python -m venv venv
.\venv\Scripts\activate
  1. Install Dependencies: Create a requirements.txt file with the following content:
pdfkit>=1.0.0
pyperclip>=1.8.2
markdown>=3.4.1

Then run:

pip install -r requirements.txt

🖥️ Usage

  1. Copy Text: Highlight text from anywhere (AI Chat, Notepad, Browser) and press Ctrl+C.
  2. Run Script:
python clipboard_to_pdf.py
  1. 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:

# 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 file for details.


Author: Md Samshad Rahman

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages