Skip to content

Generates a color PDF and prints it to a networked printer helping to keep your printer's ink flow. It also provides a flask web interface to get printer info and manage printer tasks.

License

Notifications You must be signed in to change notification settings

geertmeersman/print-color-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

maintainer buyme_coffee MIT License

GitHub issues Average time to resolve an issue Percentage of issues still open PRs Welcome

github release github release date github last-commit github contributors github commit activity

Docker Pulls Docker Image Version

πŸ–¨οΈ Print Color Test Docker Container

This Docker container automatically generates a color test PDF and prints it to a networked Canon printer using CUPS and cron.
It's designed to keep inkjet printers like the Canon Maxify GX7050 healthy by preventing ink from drying out or air from entering the tubes.

Additionally, it provides a Flask-based webserver to monitor print job execution, view logs, and see cron job schedules via a friendly interface.

Ideal for inkjet printer owners who don't print frequently but want to avoid clogged nozzles.


✨ Features

  • 🎨 Generates a PDF with Cyan, Magenta, Yellow, and Black blocks (or blank for testing)
  • πŸ–¨οΈ Prints via IPP using CUPS
  • πŸ•’ Scheduled weekly print every Friday at 11:00 AM CEST via cron
  • 🌐 Web interface for:
    • Viewing the latest print execution status and logs
    • Browsing print job history
    • Displaying human-readable cron job schedules
    • Showing container version and current year in footer
  • βš™οΈ Configurable via environment variables
  • πŸ“§ Sends email and/or Telegram notifications on print success/failure
  • πŸ§ͺ Supports dry-run with blank PDF generation

πŸ“¦ Docker Image

You can pull the image directly from Docker Hub:

docker pull geertmeersman/print-color-test

Or visit the repository directly:
πŸ”— https://hub.docker.com/r/geertmeersman/print-color-test


βš™οΈ Environment Variables

Variable Description
PRINTER_URI IPP URI of the printer (e.g. ipp://10.0.0.24:631/ipp/print)
PRINTER_NAME Optional printer name (used in notifications only, not in lp)
PRINTER_IP IP address of the printer (used by the web interface for status)
WEB_PORT Port for the Flask web interface (default: 80)
SMTP_SERVER SMTP server (e.g. smtp.gmail.com) to enable email notifications
SMTP_PORT SMTP server port (default: 587)
SMTP_USER SMTP username (usually same as EMAIL_FROM)
SMTP_PWD SMTP password or app password
EMAIL_FROM Sender email address
EMAIL_TO Recipient email address
TELEGRAM_BOT_ID Telegram bot token (e.g. 123456:ABCDEF)
TELEGRAM_CHAT_ID Telegram chat ID to receive messages

πŸ“Œ The actual printer used by lp is hardcoded as MyPrinter.


πŸ—οΈ Building the Image

docker build -t print-color-test .

πŸš€ One-Time Test Run

docker run --rm \
  -e PRINTER_URI=ipp://10.0.0.24:631/ipp/print \
  -e PRINTER_NAME="Canon GX7050" \
  -e PRINTER_IP=10.0.0.24 \
  print-color-test

πŸ” Run Persistently with Docker Compose

version: '3.8'

services:
  print-color-test:
    image: geertmeersman/print-color-test
    container_name: print-color-test
    environment:
      PRINTER_URI: ipp://10.0.0.24:631/ipp/print
      PRINTER_NAME: Canon GX7050
      PRINTER_IP: 10.0.0.24
      WEB_PORT: 80
      EMAIL_FROM: printer@example.com
      EMAIL_TO: you@example.com
      SMTP_SERVER: smtp.gmail.com
      SMTP_PORT: 587
      SMTP_USER: printer@example.com
      SMTP_PWD: your_app_password
      TELEGRAM_BOT_ID: 123456:ABCDEF
      TELEGRAM_CHAT_ID: -12345678
    ports:
      - "631:631"   # Optional: expose CUPS web interface
      - "80:80"     # Flask web interface (change if you set WEB_PORT differently)
    tty: true
docker-compose up -d

🌐 Web Interface Details

  • The Flask webserver runs on 0.0.0.0 binding to the port set by WEB_PORT (default: 80).
  • Use the web UI to:
    • Check current print job status and logs
    • Browse print history
    • View the cron job schedule in a human-readable format
    • See container version and current year in the footer

The webserver is automatically started inside the container by:

exec gunicorn --chdir /home/flask --bind 0.0.0.0:$WEB_PORT --worker-class eventlet --timeout 120 web_interface:app

Screenshot

Web interface screenshot


πŸ“† Weekly Scheduled Print

Prints every Friday at 11:00 AM CEST via cron.

Cron job:

0 11 * * 5 /usr/local/bin/weekly_print.sh >> /var/log/cron.log 2>&1

Script: weekly_print.sh

#!/bin/bash

echo "[INFO] Running weekly print job at $(date)"

# Generate PDF
python3 /home/generate_pdf.py

# Print
if lp -d MyPrinter /home/color_test_page_dated.pdf; then
    echo "[INFO] Print job succeeded. Sending notifications..."
    python3 /home/send_notification.py "SUCCESS" "Color test page printed successfully at $(date)."
else
    echo "[ERROR] Print job failed. Sending notifications..."
    python3 /home/send_notification.py "FAILURE" "Color test page FAILED to print at $(date)."
fi

πŸ› οΈ Printer and notifications Debugging

docker exec -it <container_id> bash

Inside the container:

lpstat -p             # Printer status
lpstat -o             # Print queue
cancel -a             # Cancel all jobs
/usr/local/bin/weekly_print.sh # Launch the color test print job and push notifications if the environment variables are set
lp -d MyPrinter /home/color_test_page_dated.pdf  # Manual print test
/home/test_empty.sh   # Generate an empty PDF, send it to the printer and push notifications if the environment variables are set

πŸ’¬ Community & Support

Questions, feedback, or want to chat?

πŸ“¨ Discord: discordapp.com/users/geertmeersman


πŸ“„ License

MIT


πŸ“¬ How to Set Up Telegram Notifications

To receive print job notifications via Telegram, you’ll need:

  • A Telegram Bot Token (TELEGRAM_BOT_ID)
  • Your Chat ID (TELEGRAM_CHAT_ID)

πŸ› οΈ Step 1: Create a Telegram Bot

  1. Open Telegram and search for @BotFather
  2. Start a chat and send:
    /newbot
    
  3. Follow the prompts to name your bot
  4. You’ll get a token that looks like:
    123456789:ABCDefGhIjKlMnOpQRStuvWxYz
    
    This is your TELEGRAM_BOT_ID

🧾 Step 2: Get Your Chat ID

  1. Start a chat with your new bot (just send it any message)
  2. Open your browser and visit:
    https://api.telegram.org/bot<YOUR_BOT_ID>/getUpdates
    
    For example:
    https://api.telegram.org/bot123456789:ABCDefGhIjKlMnOpQRStuvWxYz/getUpdates
    
  3. Look for the chat.id in the response:
    "chat": {
      "id": 123456789,
      ...
    }
    • If you’re using a group, add the bot to the group and look for a negative number like -987654321

This is your TELEGRAM_CHAT_ID

βœ… Example .env

TELEGRAM_BOT_ID=123456789:ABCDefGhIjKlMnOpQRStuvWxYz
TELEGRAM_CHAT_ID=123456789

About

Generates a color PDF and prints it to a networked printer helping to keep your printer's ink flow. It also provides a flask web interface to get printer info and manage printer tasks.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

  •  

Contributors 2

  •  
  •