Skip to content

How Does Printing Work?

Evan Ugarte edited this page Feb 10, 2024 · 16 revisions

Free printing is one of the most attractive features of being an SCE member. The actual process of printing involves three main parts: Core-v4, AWS and a Quasar. Below is a high level diagram of the print system. Quasar Architecture

Explanation of Each Component

Clark

It all begins on Clark's printing page: image

When the user drags and drops a file, we make use of a <form> and file <input> in the frontend to grab the file's data. The use of the library in Clark can be found in src/Pages/2DPrinting/2DPrinting.js:303.

The frontend submits the print request to SCE's backend in src/APIFunctions/2DPrinting.js:80. For more information about Clark's code structure, check the respective wiki page.

Clark's backend receives the request in Clark/api/peripheral_api/routes/Printer.js:44 which in turn sends the print request to Quasar though an SSH Tunnel.

Specifying Which Pages to Print

Its important to note that it is the Clark frontend that handles the logic for splitting up the pdf if the user wants to print specific pages. For example if the user wants to only print page 1, 3 and pages 5-9, they would input 1,3,5-9 in the pages input.

Clark then creates a new pdf file with those pages and sends that customized pdf to Quasar to print.

Quasar

Quasar recieves the print request in printer/server.py:122. The incoming Print request looks like:

{
  "raw": "base64 encoded file data",
  "copies": 1
}
  • raw is the actual pdf file, encoded in base64. This is a huge string.
  • copies is an integer which specified how many copies of the pdf file should be printed.

The Quasar server writes the pdf file to the local /tmp directory on printer/server.py:148 and then prepares a print command.

Upon successful download, we use the lp command to print the PDF file to either the left or right printer (printer/server.py:92). Finally, we delete the file from /tmp in printer/server.py:156

Quasar runs the print handler in a Docker container. The Dockerfile is found in printer/Dockerfile and uses drpsychick/airprint-bridge as a base image. This is to set up CUPS, the program which is able to setup and send print requests to our HP printers. Upon starting the container, a bash script is ran which sets up the left and right printers (here). The container relies on a config.json file that must be created before running the container. The config.json file has the IP addresses and names for the printers. For info on how to run the container, check out this repo's README.