CUPS Backend Creates Bitmaps to Web Server

This set of scripts explore how to make a CUPS printer which actually sends the print job as a bitmap (jpeg) files.

The CUPS backend is written in bash and uses:

  • GhostScript to render the PostScript print job to jpeg
  • cURL to send the jpeg files to server
  • notify-send to interact with the user (but I haven’t been able to get this work)

The server software is written in PHP and:

  • needs a httpd-writeable path for resulting files (e.g. ./files/)

Install

The zip file contains all necessary scripts.

CUPS backend

cp meb /usr/lib/cups/backend
chown root.root /usr/lib/cups/backend/meb
chmod 744 /usr/lib/cups/backend/meb

Receiving Server

  • Place the server file (index.php) to whatever location to your PHP-enabled web server
  • Create a directory for job files and make this writeable to your web server
  • Edit the $FILES_PATH to point to this directory (relative paths are ok)

Create the CUPS printer

Create the CUPS printer with following command:

lpadmin -p [PRINTER_NAME] -m postscript -v "[SERVER_URI]" -D "[DESCRIPTION]" -L "[DESCRIPTION]" -E -P ./Generic-PostScript_Printer-Postscript.ppd -o PageSize=A4
  • [PRINTER_NAME] is the name of your printer (e.g. “demoprn”)
  • [SERVER_URI] points to the index.php (e.g. “meb://yourhost/path/to/index.php”). Note that the backend contacts the server with http (not https).
  • [DESCRIPTION] is the printer description (-D) and location (-L) shown to the user (e.g. “Bitmap Test Printer”)
  • You’ll get the ppd file from openprinting.org:
    • Select “Generic PostScript Printer”
    • Select “download”
    • Click “Generate PPD file”

Testing

Now your should see the newly created printer. You may debug the printing process from /tmp/meblog.txt.

Discussion

Technically speaking the approach works. The client sends the bitmap files to server which stores them.

The script is able to send the progress notifications to the user using notify-send (Debian package libnotify-bin). For this the backend searches the user’s DBUS_SESSION_BUS_ADDRESS environment variable from the user’s process information.

For some reason my installation produced hanging /tmp/foomatic-XXXXXX files. No idea who does not take care of its cleanup.

The http upload fails if the number of pages is high and therefore the size of the resulting files exceed the maximum settings in your php.ini (upload_max_filesize and post_max_size).

3 thoughts on “CUPS Backend Creates Bitmaps to Web Server

  1. Hi

    I installed the index.php on my web server (php correctly enable) and install the printer (meb:/web_server_IP/meb-cups/index.php) with correct ppd driver.

    I set FILES_PATH to /var/www/html/meb-cups/files/ and chmod 777 the “files” directory (web_server_IP/meb-cups/files

    The problem is when i’m printing a .txt file to the printer i cannot get the jpg file on the files directory
    When i go to http://web_server_IP/meb-cups/index.php i can only see:
    Received-Pages: 0

    I disable the line: rm ${JOB_FILENAME_BASH}
    and i see that the jpg file is correctly present in the /tmp directory
    (meb_2016-07-17_12:42:56-001.jpg)

    Any idea where the problem is ?

    Regards

    1. Thanks for your comment. It appears that the CUPS backend creates the jpg files but they are not uploaded or saved to the server.

      1) What’s in “/tmp/meblog”? In the line 110 the curl uploads the bitmaps to the server. Any errors? Double-check that your CUPS client has the curl installed (make sure that “which curl” gives an path to curl binary).
      2) Try to upload whatever bitmap to the server: “curl -i -F username=johnsmith -F page1=@file_to_upload.jpg http://url/to/index.php“. This makes it easier to debug the server side.
      3) Check the web server log. Any info there?
      4) Make sure that you have updated the “$FILES_PATH” variable at the top of the index.php. The files are stored to this directory and it must be writable to the web server. As this is just a proof-of-concept (right?) you may use “chmod 777 /path/to/your/FILES_PATH”.
      5) You don’t access the uploaded files through index.php. Check the directory pointed by “$FILES_PATH”.

      I hope these hints are helpful in debugging!

Leave a Reply

Your email address will not be published. Required fields are marked *

fifty six − forty seven =