Automatically get your PDF spooled file from your intranet.
In a previous TechTip, I presented SCS2PDF, a utility that
allows you to easily convert spooled files into PDF documents, which are then
put into an IFS directory. Recently, some readers have asked if there is a way
to automatically start Acrobat PDF reader at the user's PC.
The simplest
way is to start the PDF reader from iSeries with RUNRMTCMD, but this technique
requires that you write the PDF to the IFS and leave it there to allow the user
to display it. However, in this tip, I will show you a way that does not require
any IFS writing because the final document can be written directly into a user's
browser, where it can be viewed or saved directly by the user.
You must
have your HTTP server (powered by Apache) running. Then, just add some
directives to the configuration file, write a simple HTML page for the initial
request, and modify the existing SCS2PDF to make it write the PDF document
directly to the requester's browser, instead of to an IFS folder.
In
order to automatically start the Acrobat Reader and open the PDF document, you
only have to write a header line like this:
Header = 'Content-Type: application/pdf' + newline +
'Content-Disposition: inline; filename=a.pdf'
+ newline + newline;
QtmhWrStout (Header:%len(%trim(Header)):ApiError);
In the program that now writes to IFS, replace this line of code
write(fd:%addr(Buffer):Len);
with this line of code
QtmhWrStout (Buffer:Len:ApiError);
Let's examine in detail the steps you have to take in order to put
sample DSPOBJD output into a PDF document directly in your browser.
First, download
the code and put all the source members in a source file in your iSeries. I
assume you already installed the SCS2PDF utility and you
already have your zlib c modules available in /pdf/zlib directory. Before
running the REXX script, replace RPGDIR = 'QSCS4WEB' with your actual source
file name. Then, run the script with PDF option 16. This will create all the
SCS4 objects.
Execute the DSPOBJDQ SQL script. This will create an
external definition of the parameters received from the HTML page request. Open
the DSPOBJDW RPGLE file, enter the name of the library where this external
definition can be found, and create a module in QTEMP with PDF option 15. Then,
create the program object:
CRTPGM PGM(DSPOBJDW) MODULE(QTEMP/DSPOBJDW) BNDSRVPGM(QTCP/QTMHCGI) BNDDIR(QC2LE)
Move the DSPOBJD.html into /www/YourServerName/htdocs. And finally, open
your HTTP configuration file (httpd.conf) and add the following
directives:
ScriptAliasMatch ^/DSPOBJD$ /QSYS.LIB/YOURLIBRARY.LIB/DSPOBJDW.PGM Options +ExecCGI Allow From all
Don't forget to replace YOURLIBRARY with the real name of the library
where the SCS4 objects and the DSPOBJDW program can be found.
Restart your HTTP server and point your browser to
http://YourServerName/DSPOBJD.html, as shown below.
Figure 1: Point your browser to http://YourServerName/DSPOBJD.html. (Click
images to enlarge.)
Now, fill in the form with the required parameters and press the DSPOBJD
button.
Figure 2: Fill in the form with the required parameters.
This
is just an example to show this technique. For production purposes, you will
probably give the HTML page a more exciting look, and of course you will have to
write your own specific code that interfaces with your existing applications to
create the printed reports that you want to get from the
intranet.
Giuseppe Costagliola is a programmer
in Turin, Italy. You can reach him at
This e-mail address is being protected from spam bots, you need JavaScript enabled to view it
.
|