geertmeersman/print-color-test

By geertmeersman

β€’Updated 11 months ago

Generates a color PDF and prints it to a networked printer helping to keep your printer's ink flow.

Image
Message queues
Content management system
Monitoring & observability
0

1.5K

geertmeersman/print-color-test repository overview

maintainer GitHub Repo buyme_coffee

β πŸ–¨οΈ 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

VariableDescription
PRINTER_URIIPP URI of the printer (e.g. ipp://10.0.0.24:631/ipp/print)
PRINTER_NAMEOptional printer name (used in notifications only, not in lp)
PRINTER_IPIP address of the printer (used by the web interface for status)
WEB_PORTPort for the Flask web interface (default: 80)
SMTP_SERVERSMTP server (e.g. smtp.gmail.com) to enable email notifications
SMTP_PORTSMTP server port (default: 587)
SMTP_USERSMTP username (usually same as EMAIL_FROM)
SMTP_PWDSMTP password or app password
EMAIL_FROMSender email address
EMAIL_TORecipient email address
TELEGRAM_BOT_IDTelegram bot token (e.g. 123456:ABCDEF)
TELEGRAM_CHAT_IDTelegram 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: [email protected]
      EMAIL_TO: [email protected]
      SMTP_SERVER: smtp.gmail.com
      SMTP_PORT: 587
      SMTP_USER: [email protected]
      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

Tag summary

Content type

Image

Digest

sha256:bcc12d5ce…

Size

198.6 MB

Last updated

11 months ago

docker pull geertmeersman/print-color-test:v3.0.2