New windows to open an Pdf File

Use this board to ask questions or have discussions with other Rich Displays users.
k2R400
Profound User
Posts: 62
Joined: Sat Feb 18, 2012 12:03 pm
First Name: Patrick
Last Name: THOMAS
Company Name: Oo2
Country: France
Contact:

New windows to open an Pdf File

Post by k2R400 »

Hello,

I need assistance to find the good method to open a PDF in a new window :

- In MyProgramA, if the user clic on an image (Pdf icon), i need to call a program with parameters to create a PDF spool and to show it in a new window (or new atrium tab).

A solution ?

1) onclick : window.open("http://myIBMi:8080/profoundui/start.htm ... XXXXXXXXXX");
2) MyProgramB receive the parameter and create a PDF ex: /profoundui/userdata/MyPDF.pdf
3) How to show the PDF ?

a) Into an iFrame with an EXFMT (MyProgramB) ?
b) Directly from MyProgramA ? But how ?
c) Another way ?
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: New windows to open an Pdf File

Post by Scott Klement »

Take a look at the pui.download API
http://www.profoundlogic.com/docs/displ ... 8config%29

Basically, what you want to do is have your PDF icon's onclick call the pui.download() API. The API can then pass an id (which can be any string -- make up a unique name that makes sense to you) and it will call an exit program (RPG program) named PUIDNLEXIT on the server.

That program can look for your id, and then can call your program that generates the PDF. It can then download the PDF to the user's PC, and delete it when the download is complete.

I can post an example of this if it is helpful.
k2R400
Profound User
Posts: 62
Joined: Sat Feb 18, 2012 12:03 pm
First Name: Patrick
Last Name: THOMAS
Company Name: Oo2
Country: France
Contact:

Re: New windows to open an Pdf File

Post by k2R400 »

Thanks a lot !
SDeanD
Profound User
Posts: 28
Joined: Thu Dec 12, 2013 11:34 pm
First Name: Dean
Last Name: ****
Company Name: RESD LLC
Phone: 812244-0647
Address 1: 1620 S 7th
City: Terre Haute
State / Province: Indiana
Zip / Postal Code: 47802
Country: United States
Contact:

Re: New windows to open an Pdf File

Post by SDeanD »

Scott

Please post the sample for the PDF generator. If it is not to much of a problem. A little confused on the exit Program Logic. thanks.
S Dean ****
CEO
R & E Software Design LLC.
IBM Business Partner since 1988
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: New windows to open an Pdf File

Post by Scott Klement »

For this example, set your onclick event to:

Code: Select all

pui.download({ "id": "itemrpt", "inline": true })
The "id" can be anything you want. It's just a key for the exit program to look for. In this case, when the exit program sees an id of "itemrpt" we want it to call a program that prints an item report to PDF format and download it. The "inline: true" tells it to open the PDF in a browser window (as opposed to initiating a download).

For security purposes, PUI will not simply download any document that you ask for. Instead, it calls an exit program, which is an RPG program that you write. It must be named PUIDNLEXIT and must be located in the library you installed Profound UI into (PROFOUNDUI is the library name by default, but can be changed when you install PUI)

The exit program can be used to do more than just look for a path name and validate it, however. It can also actually change the path name, and even generate an IFS document on the fly... which is what we want to do here. So it'll look for "itemrpt", and if found, it'll set up a temporary filename in the IFS and change the path name to that, and generate a PDF. It'll also delete teh PDF after the download is complete.

Code: Select all


      **********************************************************************************************
      *                                                                                            *
      *   Description: Profound UI File Download Exit Program                                      *
      *                                                                                            *
      *                Compile as PUIDNLEXIT in PROFOUNDUI product library using CRTBNDRPG.        *
      *                                                                                            *
      *                Return 1 in 'Allow' parameter to allow the upload, any other value will     *
      *                prevent the upload.                                                         *
      *                                                                                            *
      **********************************************************************************************
     H DFTACTGRP(*NO) ACTGRP(*CALLER)

     D InputData_t     ds                  qualified
     D                                     based(Template)
     D   fileid                     640a   varying
     D   userid                      10a
     D   ipAddr                      15a
     D   inline                       1n

     D Main            PR                  ExtPgm('PUIDNLEXIT')
     D   timingFlag                  10i 0 const
     D   inputData                         likeds(InputData_t) const
     D   stmfDir                    640a   varying
     D   stmfName                   256a   varying
     D   attName                    256a   varying
     D   contentType                255a   varying
     D   allow                        5i 0

     D Main            PI
     D   timingFlag                  10i 0 const
     D   inputData                         likeds(InputData_t) const
     D   stmfDir                    640a   varying
     D   stmfName                   256a   varying
     D   attName                    256a   varying
     D   contentType                255a   varying
     D   allow                        5i 0

     D RunItemRpt      PR
     D   tempfile                    50a   varying const

     D tmpnam          PR              *   extproc('_C_IFS_tmpnam')
     D   string                      39A   options(*omit)
     D unlink          PR            10I 0 ExtProc('unlink')
     D   path                          *   Value options(*string)

     D CmdExc          PR                  ExtPgm('QCMDEXC')
     D   cmd                      32702a   const options(*varsize)
     D   len                         15p 5 const

      /free
         allow = 0;

         if timingFlag=0;
           select;
           when inputData.fileId = 'itemrpt';
             stmfDir     = '/tmp';
             stmfName    = %subst(%str(tmpnam(*omit)):6) + '.pdf';
             attName     = 'itemReport.pdf';
             contentType = 'application/pdf';
             RunItemRpt( stmfDir + '/' + stmfName );
             allow = 1;

           // maybe have other 'when' situations here
           //  to have other IDs sent by different
           //  applications?
           endsl;
         endif;

         if timingFlag=1 and inputData.fileId='itemrpt';
            unlink( stmfDir + '/' + stmfName );
         endif;

         *inlr = *on;
      /end-free


      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      * RunItemRpt(): Run the RPG program that generates
      *               an item report
      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P RunItemRpt      B
     D                 PI
     D   tempfile                    50a   varying const

     D ITM001R         PR                  ExtPgm('ITM001R')

     D cmd             s            500a   varying
      /free
         // Run the Item Report and override the output to
         //  a PDF file in the temporary name

         monitor;
           cmd = 'ADDLIBLE SKTEST *LAST';
           CmdExc(cmd: %len(cmd));
         on-error;
         endmon;

         cmd = 'OVRPRTF FILE(QSYSPRT) DEVTYPE(*AFPDS) WSCST(*PDF) +
                        OVRSCOPE(*CALLLVL) +
                        TOSTMF(''' + TempFile + ''')';
         CmdExc(cmd: %len(cmd));

         ITM001R();

         cmd = 'DLTOVR FILE(QSYSPRT) LVL(*)';
         CmdExc(cmd: %len(cmd));
      /end-free
     P                 E 
The tmpnam() call is an IBM-provided API to calculate a unique temporary file name. So this will just generate a name that's not in use. The tmpnam() will return a path name beginning with /tmp/Qxxxx -- but since PUI wants the directory name in a separate variable, we use %SUBST to remove the first 5 characters to remove "/tmp/" from the start.

So /tmp goes in the directory variable, and the rest of the temporary name goes in the file name variable.

The "attName" is the filename that the user will see. Instead of reporting the temporary filename (that we actually use) to the browser, I'm specifying "itemReport.pdf" so it looks a bit nicer to the user.

The "runItemReport" procedure is just calling an exiting RPG program, but using an override to force the output into the temporary filename that we calculated previously. It's using IBM's "transformation services" licensed program that needs to be installed if you haven't done so already. "transformation services" is a no-charge item included with the operating system if you are at V6R1 or higher.

The PUIDNLEXIT exit program will be called twice. Once before the download (so it can generate the PDF) and once after teh download is complete (so it can delete the temporary IFS object). The timingFlag variable will be set to 0 when it is called before the download, and 1 when it is called after the download, so this program checks for that parameter, and uses it to decide whether to create or delete the temporary IFS file.

Hope that helps.
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: New windows to open an Pdf File

Post by Scott Klement »

One more thing... make sure you store the source code for PUIDNLEXIT in your own library. The compiled object goes in PROFOUNDUI (or whereever you installed PUI) but the source code should go in your own library. The reason is because each time you install an upgrade for PUI, it will replace the source code in the PROFOUNDUI library... however, it will not replace the compiled object.
SDeanD
Profound User
Posts: 28
Joined: Thu Dec 12, 2013 11:34 pm
First Name: Dean
Last Name: ****
Company Name: RESD LLC
Phone: 812244-0647
Address 1: 1620 S 7th
City: Terre Haute
State / Province: Indiana
Zip / Postal Code: 47802
Country: United States
Contact:

Re: New windows to open an Pdf File

Post by SDeanD »

Scott,

trying to use this. I am having an issue. IS there a way to start debug on the PUIDNLEXIT program. SO I can watch execution. I am sure it something simple. Just cant see it.

I have been using the STRSRVJOB and the Debug = 1 switch. but this job does not seem to run under the calling job.

thanks,
Dean
S Dean ****
CEO
R & E Software Design LLC.
IBM Business Partner since 1988
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: New windows to open an Pdf File

Post by Scott Klement »

Dean,

Yes, you're right, this runs in a separate job. You can debug it with a service entry point (SEP) if you like -- that's the easiest way.

Are you familiar with those?
SDeanD
Profound User
Posts: 28
Joined: Thu Dec 12, 2013 11:34 pm
First Name: Dean
Last Name: ****
Company Name: RESD LLC
Phone: 812244-0647
Address 1: 1620 S 7th
City: Terre Haute
State / Province: Indiana
Zip / Postal Code: 47802
Country: United States
Contact:

Re: New windows to open an Pdf File

Post by SDeanD »

No I have not used SEP's but, Just by knowing they exist, I could use them!.

I added an old school logfile to the exit point and my called program. I solved a couple of typo's.

but I am struggling with the js to make a subfile grid button pass a unique id to the pui.download.

here is where I am at now:

Code: Select all

function pdfclick(row) {
  var fileid = getObj("Grid4").grid.getCellValue(row, "PDFCLICK");
  pui.download({ "id": fileid, "inline": true })
}
pdfclick(row) ;
this is on the on click event of a button in a subfile with a list of reports to re-print

I am not a web /JS programmer so this is new to me.
so, be gentle. and don't laugh to hard.
any thoughts,
thanks much Dean
S Dean ****
CEO
R & E Software Design LLC.
IBM Business Partner since 1988
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: New windows to open an Pdf File

Post by Scott Klement »

the 2nd parameter to getCellValue should be a number. Is that what you're having trouble with?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest