Skip to content

This is a client-server script that used to interact the printing between linux (Mac) with Windows when the printer driver is not available for Linux/Mac

License

Notifications You must be signed in to change notification settings

tangingw/python_winprint

Repository files navigation

Python WinPrint

Python WinPrint consists of two major components; server and client. Server receives the print requests via Redis server, which acts as a queue server, together with the file uploaded via HTTP POST from the client. The client currently can only prints pdf file. Hence the user has to convert any file format to pdf format before using the client to send the print job.

Sypnosis

This is a small tool created when the author faced difficulty of printing when the linux/mac os driver is not available for his OS platform. Hence with the limited resource in hand, he created a printer server on Windows, which allows him to send print jobs via Redis Server to print his document.

Installation

There are few steps to set up both server and client (Note: Please follow the following sequence):

  • Client (Ubuntu 16.04)

    • git clone this repo

      git clone https://github.com/tangingw/python_winprint.git
      
    • on the directory ~/python_winprint, type the following command

      SHELL>mkdir ~/print_dir
      SHELL>cd ~/python_winprint
      SHELL>make install_ubuntu

      this will install the necessary library and setup a redis server on your computer

    • Configure Redis server

      • Change the following line in /etc/redis/redis.conf
      bind 127.0.0.1
      

      to

      bind 0.0.0.0
      
    • Restart the Redis server

      SHELL>sudo service restart redis-server
    • Edit ~/python_winprint/config/config.json

      1. Change the CLIENT -> PRINT_PATH to /home/<YOUR_USERNAME>/print_dir/
      2. Change the REDIS_SERVER to your host IP address
      {
          "SERVER": {
              "PRINT_PATH": "C:\\Users\\<YOUR WIN_ID>\\test_upload\\"
          },
          "CLIENT":{
              "PRINT_PATH": "/home/<YOUR_USERNAME>/print_dir/"
          },
          "UPLOAD_URL": "http://<YOUR FLASK APP IP>:5000/upload",
          "REDIS_SERVER": "<YOUR HOST IP ADDRESS>"
      }
  • Server (Windows 8.x, Windows 10, Windows Server 2012 R2)

    • Prepare a Windows Machine

      • You can either use a physical Windows machine or virtual machine (both laptop and desktop and make sure you have a legal copy of Windows). The author uses Windows Server 2012 R2, virtual machine hosted in KVM.
    • Install your printer driver on Windows Machine

      • Without this, the print_server.py will not work. Make sure you do a test print after you have installed your printer driver so that it will not cause any issue to printer_server.py
    • Install python 3.x on your Windows machine

      • Currently print_server.py is coded in python 3.x since the author wants to learn python 3.x.
    • Install latest copy of Adobe Reader

    • git clone this repo

      git clone https://github.com/tangingw/python_winprint.git
      
    • Install necessary library

      pip install win32compat win32core win32ext redis flask
      
    • Edit config.json in C:\Users\<YOUR_WIN_ID>\python_winprint\config folder

      {
          "SERVER": {
              "PRINT_PATH": "C:\\Users\\<YOUR WIN_ID>\\test_upload\\"
          },
          "CLIENT":{
              "PRINT_PATH": "/var/print/"
          },
          "UPLOAD_URL": "http://<YOUR FLASK APP IP>:5000/upload",
          "REDIS_SERVER": "<YOUR REDIS IP>"
      }
    • Start your application in Powershell

      POWER_SHELL> cd .\python_winprint\
      POWER_SHELL> python print_server.py

How to print

print_client.py mimics the famous unix printing command, lpr, hence shares some similar positional parameters.

  • Print the whole document
    SHELL>~/python_winprint/print_client.py foo_bar.pdf
  • Print single page, e.g. page 10 only
    SHELL>~/python_winprint/print_client.py foo_bar.pdf 10-10 
  • Print multiple pages, e.g. from 200 to 214
    SHELL>~/python_winprint/print_client.py foo_bar.pdf 200-214

To Do

  • Add authentication system
  • Add a database system to capture the print records. The print records are currently stored in Redis Server

About

This is a client-server script that used to interact the printing between linux (Mac) with Windows when the printer driver is not available for Linux/Mac

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published