Sunday, January 19, 2020

Print PDF from Oracle APEX to Local or Remote Printer

On Twitter, I got a lot of reactions on my previous blog post Printing to local (Zebra) printer from Oracle APEX in the Cloud.


As more people asked the question of how to print to a local printer from Oracle APEX, I will cover 3 options in this post. All options make use of some features of APEX Office Print (AOP).

When you install the AOP Sample Application, you find the examples under the following sections:


1. Call Print Window of the browser directly from a button


Create a button on the page e.g. PDF and add a Dynamic Action to it. The Dynamic Action calls some JavaScript:


This JavaScript calls following AJAX Process, which uses the AOP PL/SQL API to generate a PDF:


When the PDF is produced, the printJS JavaScript function is being called, which opens the browser's print window. The end-user can change the Printer and hit the Print button.
So this option is not a direct print to a predefined printer, but a two-step process: open print window, hit print.

2. Print directly to an IP Printer

One of APEX Office Print's unique features is that the AOP Server can send a document directly to the IP address of a printer. AOP is really smart and if it sees the printer doesn't support native PDF or the document type we send, it will convert to PDF or Postscript, which all printers support.

The only thing you have to do, in order to print directly to an IP Printer is to add some global variables of AOP. In the below example it will send a PDF to the IP Printer on the same server AOP is running but on port 3000.


3. Use of Post-Process command

You can configure the AOP Server with some post-processing commands, which allow you to run some command-line tools before and after the AOP Server is creating the output. This is a really powerful feature and one use case is to send the document directly to a local (or network or remote) printer.


Just like with the IP Printer, you define the post-process command in some global variables of AOP.

This technique I also described in the previous blog post where we printed to a local Zebra printer. The only special thing in that post was that we used ngroc to make AOP known to the Oracle Cloud.
When you have the AOP Server running on-premises, you don't have that step as your APEX app will call the on-premises AOP Server. The only thing you need to make sure is that AOP Server knows the printer you configured in the post-process command.


There you go, three options to print from your Oracle APEX app directly to a local or remote printer using APEX Office Print.

7 comments:

  1. The server directory is not available on the Cloud version. How can I create my post-process command? I am trying to implement printing to Zebra Designer GX430t.

    ReplyDelete
  2. See http://dgielis.blogspot.com/2020/01/printing-to-local-zebra-printer-from.html

    ReplyDelete
  3. Is there a way to trial on premise version of AOP?If I get this working mostt like it means an enterprise license purchase.

    ReplyDelete
  4. Hi J,

    Absolutely, you can download the on-premise version from https://www.apexofficeprint.com

    ReplyDelete
  5. Yes, it worked :) Thanks.

    ReplyDelete
  6. Thank you for the useful information

    ReplyDelete
  7. How to install printJS on apex

    ReplyDelete