Monday, May 9, 2022

Direct Print using Webutil

Direct Print using Webutil

Step 01:

First you have to create the procedure with the name of Print_Directly.

========================================================================

Step 02:

Procedure Print_Directly(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);
  Printer_Path     Varchar2(2000);
  Lc$temp_Path Constant Varchar2(256) := '\\192.168.10.5\temp\';
  Pl_Id Paramlist;
Begin
  Pl_Id := Get_Parameter_List('tmpdata');

  If Not Id_Null(Pl_Id) Then
    Destroy_Parameter_List(Pl_Id);
  End If;

  Pl_Id := Create_Parameter_List('tmpdata');
  Add_Parameter(Pl_Id, 'v_id ', Text_Parameter, :Vn);
  Lc$file_Path := Lc$temp_Path || In_Rep_Name || To_Char(Sysdate, 'hhmiss') ||'.pdf';  
  Repid := Find_Report_Object(In_Obj_Name);
  Set_Report_Object_Property(Repid, Report_Filename, In_Rep_Name);--'<Directory_Location>\myreport.rdf'
  Set_Report_Object_Property(Repid, Report_Server, 'rep01');
  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');
  --Add_Parameter(pl_id,'repot paramter', TEXT_PARAMETER, form parameter);
  Lc$rep        := Run_Report_Object(Repid, Pl_Id);
  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;
        When Others Then
          Message('others');
      End;
      If Lc$ln$adobe_Path Is Not Null Then
        Exit;
      End If;
    End Loop;
  
    Begin
      Ln$process_Id := Webutil_Host.
                       Nonblocking('cmd.exe /c start 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 PDF 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;

========================================================================
Step 03:
Now Call this procedure to button where you want to call it.

I hope it's helpful for you. If you have any queries, don't hesitate to contact me.

Name : Muhammad Sahal Qasim
E-mail : s.m.sahal789@gmail.com

Thank you.

0 comments:

Post a Comment

If you have any doubts, please let me know. I will help you.