Oracle Forms : Print Report Directly
September 21, 2012
Usually we display Oracle Reports in Oracle Forms in PDF format and then the user print it through Adobe Reader program or any other PDF reader program.
But the requirement is to print Oracle Report directly without displaying the report at screen.
To achieve this requirement in Oracle Forms 6i it is easy as you you set DESTTYPE parameter in report file to PRINTER and It will work correctly, But this feature not work with Oracle Forms 10g.
Some developers use java bean for this purpose but I will produce the below workaround to print report directly without using java bean.
1- Run Report and save it as PDF file at application server.
I will share folder c:\temp at application server for everyone for read only and save reports PDF files in this folder. The share path of the folder is \\ApplicationServer_IP\Temp\
2- Silent Print of PDF file at user machine using PDF reader programs like Adobe Reader
3- Close PDF reader program after printing.
Some Developers may use ORARRP utility and do its required configuration at server and client machine for direct printing too.
Procedure Code
I create Procedure (Program Unit) in Oracle Forms to do the previous steps
PROCEDURE PRINT_DRIRECTLY (IN_SERVER_NAME VARCHAR2,
IN_REP_NAME VARCHAR2,
IN_OBJ_NAME VARCHAR2)
IS
LC$REP VARCHAR2 (100);
LC$REP_STATUS VARCHAR2 (20);
LC$LN$ADOBE_PATH VARCHAR2 (500);
LN$PROCESS_ID WEBUTIL_HOST.PROCESS_ID;
REPID REPORT_OBJECT;
LC$FILE_PATH VARCHAR2 (1024);
LC$TEMP_PATH CONSTANT VARCHAR2 (256)
:= '\\ApplicationServer_IP\Temp\' ;
BEGIN
LC$FILE_PATH := LC$TEMP_PATH || 'ReportName.pdf';
REPID := FIND_REPORT_OBJECT (IN_OBJ_NAME);
SET_REPORT_OBJECT_PROPERTY (REPID, REPORT_FILENAME, IN_REP_NAME);
SET_REPORT_OBJECT_PROPERTY (REPID, REPORT_SERVER, IN_SERVER_NAME);
SET_REPORT_OBJECT_PROPERTY (REPID, REPORT_EXECUTION_MODE, BATCH);
SET_REPORT_OBJECT_PROPERTY (REPID, REPORT_COMM_MODE, SYNCHRONOUS);
SET_REPORT_OBJECT_PROPERTY (REPID, REPORT_DESTYPE, FILE);
--File name must be unique otherwise it will override the old file with same name
SET_REPORT_OBJECT_PROPERTY (REPID, REPORT_DESNAME, LC$FILE_PATH);
SET_REPORT_OBJECT_PROPERTY (REPID, REPORT_DESFORMAT, 'pdf');
LC$REP := RUN_REPORT_OBJECT (REPID);
LC$REP_STATUS := REPORT_OBJECT_STATUS (LC$REP);
WHILE LC$REP_STATUS IN ('RUNNING', 'OPENING_REPORT', 'ENQUEUED')
LOOP
LC$REP_STATUS := REPORT_OBJECT_STATUS (LC$REP);
END LOOP;
IF LC$REP_STATUS = 'FINISHED'
THEN
IF WEBUTIL_FILE_TRANSFER.IS_AS_READABLE (LC$FILE_PATH)
THEN
-- Try to get the correct instaled version of Adobe Reader program
FOR I IN REVERSE 5 .. 13
LOOP
BEGIN
LC$LN$ADOBE_PATH :=
CLIENT_WIN_API_ENVIRONMENT.
READ_REGISTRY (
'HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\Acrobat Reader\'
|| I
|| '.0\Installer',
'Path',
TRUE);
EXCEPTION
WHEN NO_DATA_FOUND
THEN
--If path not exists in Registery, it will raise NO_DATA_FOUND EXCEPTION
NULL;
END;
IF LC$LN$ADOBE_PATH IS NOT NULL
THEN
EXIT;
END IF;
END LOOP;
BEGIN
LN$PROCESS_ID :=
WEBUTIL_HOST.
NONBLOCKING (
'"'
|| LC$LN$ADOBE_PATH
|| 'Reader\AcroRd32.exe" /H /P '
|| LC$FILE_PATH);
EXCEPTION
WHEN OTHERS
THEN
NULL;
END;
--sleep for sometime until printing is finished
DBMS_LOCK.SLEEP (3);
-- Teminate Adobe Reader Program Process
IF NOT WEBUTIL_HOST.ID_NULL (LN$PROCESS_ID)
THEN
WEBUTIL_HOST.TERMINATE_PROCESS (LN$PROCESS_ID);
END IF;
ELSE
MESSAGE (
LC$FILE_PATH || ' is unreadable path at application server');
END IF;
END IF;
END PRINT_DRIRECTLY;
Use Guidelines
1- You pass three parameters to procedure
a- IN_SERVER_NAME : Report service name
b- IN_REP_NAME : physical file path of report file (rdf , rep files)
c- IN_OBJ_NAME : Report object name in your form
2- I expect that the installed program at client machine is Adobe reader if there are another program you use, then you should modify the code in below lines
LN$PROCESS_ID :=
WEBUTIL_HOST.
NONBLOCKING (
'"'
|| LC$LN$ADOBE_PATH
|| 'Reader\AcroRd32.exe" /H /P '
|| LC$FILE_PATH);
3- You should make report file name (Generated PDF file after running report) unique over the application, You should modify the below code to make it unique.
LC$FILE_PATH := LC$TEMP_PATH || 'ReportName.pdf';
No comments:
Post a Comment