11 Replies Latest reply: May 26, 2012 12:52 PM by 825195 RSS

    Display BLOB File (pdf format) from database inside Oracle Form (6i)

    825195
      hi all.
      Apologies for a primitive question owing to the fact that i m new to development. I have a requirement to display a pdf document with in an oracle form. i want to know is there any such control for that? or any hint how to go about it?
      thanks in advance
        • 1. Re: Display BLOB File (pdf format) from database inside Oracle Form (6i)
          François Degrelle
          Hello,

          If you run your Forms 6i in Client/Server mode, and the PDF is stored on the client machine, you can use the following:
           host('cmd /c start "" "my_doc.pdf" ');
          Francois
          • 2. Re: Display BLOB File (pdf format) from database inside Oracle Form (6i)
            PeterValencic
            If you have a PDF inside blob field...

            1. you can download that content in local folder using (webutil) and then display it using host command

            2. you can make a jsp or servlet page which will return the stream for your filed.. here you have an example (http://www.java2s.com/Code/Java/Servlets/AnotherservlettoSendPDF.htm)

            3. you can stream datas from your blob on local disk (using httpclient library in java as PJC) and then display the contenet with host command or using Runtime.execute command from java...

            etc..
            • 3. Re: Display BLOB File (pdf format) from database inside Oracle Form (6i)
              825195
              Thanks for reply. My pdf file is saved on the server side. Do i need to first store it on the client side? is there any way to open it directly from the server database?
              • 4. Re: Display BLOB File (pdf format) from database inside Oracle Form (6i)
                PeterValencic
                If you store your report on server and if that report is acessed from your browser you can simply call
                web.show_document('http://your_server/your_folder/your_pdf.pdf','_blank); 
                If you have a PDF inside a table (blob).. than you have two options...

                1. is to make a servelt (example in my previous post)..

                2. is to make a PJC (java plugable component) which will connect to your db using jdbc.. then you select this field and save the content on your local folder.. after this you simply execute command script to display that pdf..

                for example
                connect to you db..
                download blob to your disk...
                
                 try {
                 
                          if ((new File("c:/your.pdf")).exists()) {
                 
                               Process p = Runtime
                                  .getRuntime()
                                  .exec("rundll32 url.dll,FileProtocolHandler c:/your.pdf");
                               p.waitFor();
                 
                          } else {
                 
                               System.out.println("File is not exists");
                 
                          }
                 
                          System.out.println("Done");
                 
                         } catch (Exception ex) {
                          ex.printStackTrace();
                       }
                • 5. Re: Display BLOB File (pdf format) from database inside Oracle Form (6i)
                  PeterValencic
                  Here I have found my jsp script...

                  How I get the PDF?
                  I call my script from pl/sql with

                  web.show_document('http://my_server/getblob.jsp?id=' || id_from_my_blob_table || '&baza=myhost:1521:sid','_blank');

                  <%@ page contentType="text/html;charset=windows-1250"%>
                  <%@ page import="java.sql.*" %>
                  <%@ page import="java.util.*" %>
                  <%@ page import="java.io.*" %>
                  <%@ page import="java.text.*" %>
                  <%@ page import="oracle.jdbc.driver.OracleDriver" %>
                  <%@ page import="oracle.jdbc.driver.OracleResultSet" %>
                  
                  <%
                  Connection con = null;
                  Statement stmt = null;
                  ResultSet rs= null;
                  oracle.sql.CLOB clob = null;
                  oracle.sql.BLOB blob = null;
                  String datoteka = "";
                  String host = "http://" + request.getHeader("host") + "/";
                  %>
                  
                  
                  <!--Peter Valencic 2003 -->
                  <html>
                  <head>
                  <title></title>
                  </head>
                  
                  <%
                     String tip =""; 
                     String id =""; 
                     String baza =""; 
                     String shema ="";
                  try
                  {
                     
                     id = request.getParameter("id");
                     baza = request.getParameter("baza");
                     shema = request.getParameter("shema");
                  
                  
                     if (request.getParameter("id")== null)
                     {
                        throw new Exception("id= null");
                     }
                     else if(request.getParameter("id").equals(""))
                     {
                        throw new Exception("id= null");
                     }
                     
                     
                     
                     if (request.getParameter("baza")== null)
                     {
                        throw new Exception("baza= null");
                     }
                     else if(request.getParameter("baza").equals(""))
                     {
                        throw new Exception("baza= null");
                     }
                  
                     if (request.getParameter("shema") == null)
                     {
                       shema ="";
                     }
                     else if (request.getParameter("shema").equalsIgnoreCase(""))
                     {
                       shema="";
                     }
                     else
                     {
                       shema =shema + ".";
                     }
                  }
                  catch(Exception e)
                  {
                     out.println("Priąlo je do napake: " + e.toString());
                     return;
                  }
                  
                  
                        try
                        {
                               
                              Class.forName("oracle.jdbc.driver.OracleDriver");
                              con = DriverManager.getConnection("jdbc:oracle:thin:@"+baza,"your_user","your_password");
                              stmt =con.createStatement();
                              rs = stmt.executeQuery ("Select * from "+shema+"DOK_VSEBINA_DOKUMENTA_BLOB where ID="+id);
                              boolean podatkib = rs.next();
                              if (!podatkib) 
                              { 
                                 out.print("<li>Ni podatkov za  ID="+id);
                                 return;
                              }
                              blob = ((oracle.jdbc.OracleResultSet)rs).getBLOB("VSEBINA");
                              datoteka = rs.getString("NAZIV_DATOTEKE").toUpperCase();
                                 
                                 File blobFile = new File(application.getRealPath("/uploads/blob")+"/"+datoteka);
                              
                                 
                              blobFile.createNewFile();
                              InputStream podatki = blob.getBinaryStream();
                              FileOutputStream strBlob= new FileOutputStream(blobFile);
                              int size = blob.getBufferSize();
                              byte[] buffer = new byte[size];
                              int length = -1;
                              while ((length = podatki.read(buffer)) != -1)
                              {
                                 strBlob.write(buffer,0,length);
                              }
                              podatki.close();
                              strBlob.close();
                              con.close();
                              out.print("<li>"+host+"in2/uploads/blob/"+datoteka);
                               
                                 response.sendRedirect(host+"in2/uploads/blob/"+datoteka);
                              
                              //odpremo z jsp-stranjo datoteko..
                              //response.sendRedirect("");
                              
                              
                  
                        }
                        catch(Exception blobException)
                        {
                           out.print("<li>(BLOB)Napaka pri prebiranju podatkov:</li>"+blobException.toString());
                           return;
                        }
                  
                  out.println("konec..");
                  
                  %>
                  
                  <body>
                  <form method="post">
                  Vnesi ID
                  <input type=text name="id">
                  <li> <input type=submit name="potrdi" >
                  
                  </form>
                  </body>
                  </html>
                  If you look my "old" script..
                  first it get 2 parameters baza= database (ip:port:sid), id= id from my table (PK)

                  at the end of my script I have:
                  response.sendRedirect(host+"in2/uploads/blob/"+datoteka);

                  this redirect will redirect you to your file stored on server side..
                  Because IE knows what file it must open it will open it with PDF reader...

                  hope this help you..

                  Edited by: peterv6i.blogspot.com on May 14, 2012 11:14 AM
                  • 6. Re: Display BLOB File (pdf format) from database inside Oracle Form (6i)
                    825195
                    Thanks. i will make a try. if hit by any problem. plz dont mind me getting back to u :)
                    • 7. Re: Display BLOB File (pdf format) from database inside Oracle Form (6i)
                      825195
                      hi.
                      The forms runs in client / server fashion. pdf docs are stored in a folder on the system from where the forms are being run. can i use host command behind a button on the form to open the pdf like follows? platform is Windows both on client and server:-
                              begin
                                host('cmd /c start "" "c:\employee36.pdf" ');
                              end;
                      thanks
                      • 8. Re: Display BLOB File (pdf format) from database inside Oracle Form (6i)
                        825195
                        hi.
                        The forms runs in client / server fashion. pdf docs are stored in a folder on the system from where the forms are being run. can i use host command behind a button on the form to open the pdf like follows? platform is Windows both on client and server:-
                                begin
                                  host('cmd /c start "" "c:\employee36.pdf" ');
                                end;
                        thanks
                        • 9. Re: Display BLOB File (pdf format) from database inside Oracle Form (6i)
                          825195
                          hi.
                          The forms runs in client / server fashion. pdf docs are stored in a folder on the system from where the forms are being run. can i use host command behind a button on the form to open the pdf like follows? platform is Windows both on client and server:-
                                  begin
                                    host('cmd /c start "" "c:\employee36.pdf" ');
                                  end;
                          thanks
                          • 10. Re: Display BLOB File (pdf format) from database inside Oracle Form (6i)
                            825195
                            hi all. sorry for botheration. i used following command in the button trigger of the oracle 6i form of mine
                               begin
                                 host('cmd /c start "" c:\employee36.pdf" ');
                                    
                            
                            and also
                               client_host('cmd /c start "" "c:\employee36.pdf" ');
                                    end;
                            
                            {code}
                            
                             but i get error host / client_host not declared. my requirement is simple. pdf documents are placed on a local disk from where the forms are run. there is a button on form which when clicked, should just show a pdf stored on local disk.
                            
                            can any one help me with that? bundles of thanks in advance.
                            
                            Edited by: jaykio77 on May 18, 2012 9:53 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
                            • 11. Re: Display BLOB File (pdf format) from database inside Oracle Form (6i)
                              825195
                              thanks for every one's help