Load PDF Files

Use this board for starting discussions, asking questions, and giving advice on Web programming for the IBM i platform (and predecessors.)
burtguidry
New User
Posts: 2
Joined: Wed Jul 16, 2008 7:49 am
First Name: Burton
Last Name: Guidry
Company Name: Drago Supply Company
Phone: 409-984-7799
Address 1: 740 Houston Ave
City: Port Arthur
State / Province: Texas
Zip / Postal Code: 77640
Country: United States
Contact:

Load PDF Files

Post 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.
User avatar
Rob
Profound Logic Staff Member
Posts: 135
Joined: Fri Jan 04, 2008 12:12 pm
First Name: Rob
Last Name: Ferguson
Company Name: Profound Logic Software
Contact:

Re: Load PDF Files

Post 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.
burtguidry
New User
Posts: 2
Joined: Wed Jul 16, 2008 7:49 am
First Name: Burton
Last Name: Guidry
Company Name: Drago Supply Company
Phone: 409-984-7799
Address 1: 740 Houston Ave
City: Port Arthur
State / Province: Texas
Zip / Postal Code: 77640
Country: United States
Contact:

Re: Load PDF Files

Post 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?
User avatar
Rob
Profound Logic Staff Member
Posts: 135
Joined: Fri Jan 04, 2008 12:12 pm
First Name: Rob
Last Name: Ferguson
Company Name: Profound Logic Software
Contact:

Re: Load PDF Files

Post 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.
tiko_history
New User
Posts: 1
Joined: Thu Apr 26, 2012 11:42 am
First Name: Gevorg
Last Name: Gorgisyan
Company Name: Basket
Phone: 4629064
Address 1: Koryun 25
City: Yerevan
State / Province: Outside Canada/USA
Zip / Postal Code: 0054
Country: Armenia
Location: Yerevan
Contact:

Re: Load PDF Files

Post by tiko_history »

thank you for helpful information , i just need it
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest