During this past week, I devoted the majority of my time to working on the next Polaris major release (codename “NX”). Among the numerous features that will be made available, “remote printing” is the most requested. It will allow duty crew members to print attendance sheets directly through the Polaris cloud printing service, eliminating the need for the driver take attendance by hand with the van sign-out form.
While the feature might sound very simple to implement, the engineering behind is quite difficult. At first, I thought about using Google Cloud Print, which is compatible with almost all the printers at Westtown School. Unfortunately, after going thought Google Cloud Print’s API documentation, I realized that the sample code was published back in 2011. The majority of the features in the sample code have been either deprecated or made unavailable.
Soon, I was able to come up with a second solution, which is printing with third-party APIs or PHP libraries. There is quite a lot of PHP printer libraries available on GitHub. Before I decided to give this solution a try, I stumbled upon an article on Stack Overflow, detailing the 4 ways to print a document with PHP. The first two methods detailed by the author were not applicable because Polaris runs neither PHP 5 nor on Windows Server. The last solution proposed by the author was also not applicable because it prompts the users to print through the system printing service, which defies the whole purpose of implementing the printing service through cloud.
This left me with the last option – option 3. The author writes that developers can open up a socket to print to any compatible printer on the network. Specifically, the author uses port 9100 and simply inputs the text and sends it to the printer via the HP JetDirect protocol. I was initially doubtful about this method and was surprised that it worked during my first attempt. The following is the code I wrote for my initial attempt:
$data = "Hello, Polaris.";
$conn = pfsockopen("192.168.1.201",9100);
Moreover, While selecting the type of printer, I was torn apart between two the options I had: POS receipt printer and normal printer. My original thought was that a POS receipt printer would be more eco-friendly as it uses less paper. After a short conversation with T. Carl Beehler, I found out that, after all, printing letter-size attendance sheets might not be a bad idea. It turned out that thermal paper tends to go completely black when exposed to extreme heat. It is also more harmful to the environment than regular paper because of the use of chemicals, making it unrecyclable.
Thanks for reading my blog. I will be going on my senior project next week and will not be posting another blog post until I return from spring break. I am looking forward to sharing my experience of Yunnan Province, China with you.
Beehler, Carl. Interview. 26 Feb. 2018.
Google. “Cloud Print.” Google Cloud Print, Google, http://www.google.com/cloudprint/learn/. Accessed 25 Feb. 2018.
User3150191, and Jens A. Koch. “Printing Data to Printer Using PHP.” Stack Overflow, Stack Exchange, 11 Mar. 2014, stackoverflow.com/questions/22313439/printing-data-to-printer-using-php. Accessed 26 Feb. 2018.