Tuesday, January 14, 2020

Printing to local (Zebra) printer from Oracle APEX in the Cloud

These days Oracle Application Express (APEX) is being used more and more in "local" applications like a bar, a restaurant, a power station, etc. On many occasions, they also have the requirement to print something to a local printer.

As the Always FREE Oracle Cloud is becoming more and more popular and stable, people use that service to host their APEX apps, instead of installing Oracle XE with APEX locally.

In this blog post, I will demonstrate how to print from the Oracle Cloud to a local Zebra printer by using APEX Office Print (AOP).

In my test case, I have a Zebra Printer GK420t connected to my local computer.

It's a 3 step process:

  1. Run APEX Office Print (AOP) on a local pc
  2. Make AOP available to the Oracle Cloud
  3. Use the AOP APEX Plug-in to do the print

1. Run APEX Office Print (AOP) on a local pc

The first thing we do is download the on-premises version of APEX Office Print (AOP) for your Operating System. Unzip the file and go to the server directory and run APEX Office Print.

./APEXOfficePrintOSX64

The first time you run AOP, AOP will create an aop_config.json file, which holds the configuration of AOP. We want to make a small modification to the file to include the local printer name.
So exit AOP again (CTRL-C) and do:

vi aop_config.json


On the last lines, you see post_process_commands, here you define your command to print to your local printer. Note that you can have as many post process commands by comma separating them.

If you want to know which printers are available on your machine, you can do:

lpstat -p | awk '{print $2}'


It will not only show you the local (connected) printers, but also the network printers. You can use any of those with AOP.

That's it! Just run AOP again and you are all set 😀



2. Make AOP available to the Oracle Cloud

Next, we need to make this local AOP server known to the Oracle Cloud. There are different ways of doing this, you could create a domain and point to the IP address of the local machine, but as the Oracle Cloud only accepts HTTPS, you would also need to set up an SSL certificate (e.g. with Letsencrypt). As this is a local machine, there's a high chance that the IP changes, so I looked for another solution which makes it easy to expose a local webserver to the internet.

This is exactly what a tool called ngrok is doing. Ngrok creates a public URL for a local webserver, in our case AOP.

Installation of ngrok, is as simple as installing AOP: download, unzip, run!

Download ngrok, unpack and run the executable:

./ngrok http 8010


It will show you the URL you can use to access your local AOP server, both HTTP and HTTPS.
In the Oracle Cloud, you always want to use the HTTPS connection.

3. Use the AOP APEX Plug-in to do the print

Import the AOP plug-in in your Oracle APEX app and specify the HTTPS URL as the AOP URL in the Component Settings of the Plug-in. Next, create a Dynamic Action and specify the Post Processing Command you want to run:


That's it! Don't think it can be any simpler than that ;)

No comments: