SyntaxHighlighter

Friday, April 20, 2012

Example: How to print a Oracle report using a URL


Oracle Reports 10g
Windows Server 2008
For those of us that use Oracle Reports in our environments, most of us (I assume), use the web browser to run the report. The report is then returned back to the browser window for viewing (typically). But what happens if I want to run the report directly to a printer without viewing it? 

Perhaps I want to have a payroll run that prints a few thousand pay sheets. Not something I want to preview or download to my browser. It's also not something I would print to my local printer that only does 15-20ppm.

Or, maybe I want a document that requires particular stationary, delicate watermarking and copy protection only available on a specialised corporate printer. Like perhaps a vehicle license document or access card printer.

Anyway, there is quite a bit of documentation about printing from Oracle Reports on UNIX servers (because it's so much more complex on UNIX systems), but basically none on Windows servers because it is so simple. Still, it took me a little while to find just the right parameters to set when running the report. So here it is then, a simple guide to printing Oracle Reports to a designated printer via a URL browser command....
Firstly, I am only dealing with Windows servers here. You will need to refer to Oracle documentation for information on setting up printing on Linux/UNIX server environments. Secondly, I would assume that you are able to run Oracle Reports via the standard RWSERVLET commands from a Web Browser

For my simple example, I use the following URL which I am able to run in any web browser:
http://windev:7777/reports/rwservlet?testkeymap&report=test_report&mimetype=application%2Fpdf&destype=cache&desformat=PDF

This URL returns the Oracle Report back to my browser as a PDF document. For more information on running running Oracle Reports using a URL, see Running Report Reqeusts

My report example makes use of a key map file that fills in some parameters by default to make it easier for me to run reports using a URL. This is the CGICMD.DAT mapping entry:
testkeymap: %* userid=username/password@tnsname

Starting off with the configuration:
If you want to run the report directly to a printer, you will need to add the printer to the server devices first. I added a Brother HL 7050 series printer just as a test for the printing. Now, the adding of printers is really simple on Windows and you will know you have it added correctly when you are able to print a test page to it from the servers "Printers and Devices" panel. 

I found there is a catch though.... By default, Windows will add the printer using it's product name as the actual device name in the "Printers and Devices" panel. This often includes spaces in the name which seems to be a no-no if you want to use it with Oracle Reports. My experience has been that you must not have any spaces in the name of your printer. I renamed my printer from "Brother HL-7050 series" to simply "BrotherHL-7050series", just removing the spaces. If you have spaces in the printer name, then you will likely receive the following error when running your report from your browser:
REP-50159: Executed successfully but there were some errors when distribute the output

In terms of config, that's the only change I needed to make.

Running the report to the printer:
So, we already have our test URL we used to run the report back to my browser. I just need to provide the parameters to redirect the report to my printer. The parameters involved are simply:
  • DESTYPE: Set this to "printer" to tell RWSERVELET that we are sending the report to a printer. Strangely, this parameter name seems to be case sensitive, so use "DESTYPE" (in upper case) in your query string.
  • DESNAME: Set this to the name of the printer that we set in the configuration (remember no spaces)

The revised URL will now look like this:
http://windev:7777/reports/rwservlet?testkeymap&report=test_report&desformat=pdf&DESTYPE=printer&desname=BrotherHL-7050series

Running the URL from any web browser should return a Success message and output at your printer.
Post a Comment