Page 1 of 1

Load PDF Files

Posted: Tue Mar 31, 2009 5:15 pm
by burtguidry
We are creating our own web site and one of the things that we need to do is open PDF files. I copied the PDF's I needed from the PC to the IFS. I tried to use the window.open command but never could get it to work. Is there a special way to issue this command or is there another way to open these kind of files? Thanks for any help.

Re: Load PDF Files

Posted: Tue Mar 31, 2009 6:03 pm
by Rob
Create a smart page, remove all html and add the following RPG code.

To open a pdf file directly in the browser use the following code
RPG CODE
RPGspSetCntType('application/pdf');
RPGspClear();                      
RPGspFileOut('/home/myFiles/Invoice12345.pdf');
RPGspDone();
*InLr=*On;
Return;
To open the pdf in adobe reader use the following:
RPG CODE
RPGspSetCntType('application/pdf');
RPGspSetHeader('Content-Disposition: attachment;' +
                       'filename="Invoice.pdf"');
RPGspClear();                      
RPGspFileOut('/home/myFiles/Invoice12345.pdf');
RPGspDone();
*InLr=*On;
 Return;
The RPGspFileOut command can access files anywhere on the IFS, not just in the web root folder (usually /web). This is important because you would normally not want to place a PDF where it is accessible to any web user unless it is for public display.

Re: Load PDF Files

Posted: Wed Apr 01, 2009 9:52 am
by burtguidry
The tip works great but can you tell me how to incorporate it into a web page so that when someone clicks on a link on a web page it opens the PDF document? Again thanks for any help?

Re: Load PDF Files

Posted: Wed Apr 01, 2009 3:14 pm
by Rob
Below is the html for a page with three links. Each link will download a different PDF document. This page can be a smart page or a static HTML page.

Code: Select all

<html>
<head>
  <title></title>
</head>

<body>
  <h1>click to download PDF</h1>
<a href="/rpgsp/getpdf.pgm?pdfname=Invoice1">Invoice 1</a>
<a href="/rpgsp/getpdf.pgm?pdfname=Invoice2">Invoice 2</a>
<a href="/rpgsp/getpdf.pgm?pdfname=Invoice3">Invoice 3</a>
</body>
</html>
Each link above calls the same page (getpdf.pgm) and passes a parameter to identify the name of the pdf to retrieve.

getpdf (below) is a smart page with all HTML removed and consists of:
RPG CODE
<SCRIPT language=RPGLE>
RPGspSetCntType('application/pdf');                                                                                       
RPGspSetHeader('Content-Disposition: attachment;' +
            'filename="Invoice.pdf"'); 
RPGspClear(); 
RPGspFileOut('/home/' + RPGspIn('pdfname') + '.pdf'); 
                                                                    
RPGspDone();                                                                                                              
*InLr=*On;                                                                                                                
Return;                                                                                                                  
</SCRIPT>
The RPGspIn command in line 6 above, retrieves the parameter passed in from the link so the correct PDF is sent by RPGspFileOut. To get this code to work, place 3 pdf documents in the IFS folder /home The documents should be named: Invoice1.pdf, Invoice2.pdf & Invoice3.pdf.

Re: Load PDF Files

Posted: Thu Apr 26, 2012 11:45 am
by tiko_history
thank you for helpful information , i just need it