Displaying PDF file from database BLOB

I have successfully added a PDF file to a table as a BLOB. Now, I need to display the BLOB. I have created the following package but it does not display anything. Can someone please help?
SQL> create or replace package image_get
2 as
3 procedure pdf( p_id in demo.id%type );
4 end;
5 /
Package created.
SQL> create or replace package body image_get
2 as
3
4 procedure pdf( p_id in demo.id%type )
5 is
6 l_lob blob;
7 l_amt number default 30;
8 l_off number default 1;
9 l_raw raw(4096);
10 begin
11 select theBlob into l_lob
12 from demo
13 where id = p_id;
14
15 owa_util.mime_header( 'image/pdf' );
16 begin
17 loop
18 dbms_lob.read(l_lob,l_amt,l_off,l_raw);
19 htp.prn(utl_raw.cast_to_varchar2(l_raw));
20 l_off := l_off+l_amt;
21 l_amt := 4096;
22 end loop;
23 exception
24 when no_data_found then
25 NULL;
26 end;
27 end;
28 end;
29 /
Package body created.
SQL> DECLARE
2 l_pdf int(1);
3 begin
4 l_pdf := 1;
5 image_get.PDF(l_pdf);
6 end;
7 /
PL/SQL procedure successfully completed.
SQL> DECLARE
2 Image1 BLOB;
3 ImageNum NUMBER := 1;
4 BEGIN
5 SELECT TheBLOB INTO Image1 FROM demo
6 WHERE id = ImageNum;
7 DBMS_OUTPUT.PUT_LINE('Size of the Image is: ' ||
8 DBMS_LOB.GETLENGTH(Image1));
9 /* more LOB routines */
10 END;
11 /
Size of the Image is: 14064
PL/SQL procedure successfully completed.
SQL> exit
Am I missing something? I recently discovered that I need to set SERVEROUTPUT on to display the DBMS_OUTPUT. Is their some other environment variable I need to set.
Thanks!

*Always post code wrapped in <a href=http://wikis.sun.com/display/Forums/Forums+FAQ#ForumsFAQ-Arethereanyusefulformattingoptionsnotshownonthesidebar?"><tt>\...\</tt> tags</a>:*
  PROCEDURE lf_html_pdf (pv_image IN VARCHAR2, pv_index IN NUMBER) is
     l_mime        VARCHAR2 (255);
     l_length      NUMBER;
     l_file_name   VARCHAR2 (2000);
     lob_loc       BLOB;
  BEGIN
      begin
        selecT OI_BLOB,DBMS_LOB.getlength (OI_BLOB)
        into lob_loc,l_length
        from ord_img
        where  oi_tno= pv_image
          and oi_ti='PDF'
          and oi_idx=pv_index;
      exception
            when others then
            null;
        end;
     OWA_UTIL.mime_header (NVL (l_mime, 'application/pdf'), FALSE);
     HTP.p ('Content-length: ' || l_length);
     OWA_UTIL.http_header_close;
     WPG_DOCLOAD.download_file (lob_loc);
  END lf_html_pdf; Start by getting rid of:
      exception
            when others then
            null;and never using it anywhere ever again.
If you're not actually going to use the <tt>l_mime</tt> and <tt>l_file_name</tt> variables then remove these as well. (Although I really think you should set a filename.)
>
Error report:
ORA-06502: PL/SQL: numeric or value error
ORA-06512: at "SYS.OWA_UTIL", line 356
ORA-06512: at "SYS.OWA_UTIL", line 415
ORA-06512: at "HCLABPRO.PKG_PDF", line 220
ORA-06512: at line 2
06502. 00000 - "PL/SQL: numeric or value error%s"
>
The error stack indicates that the exception is being raised in <tt>HCLABPRO.PKG_PDF</tt>: what is <tt>HCLABPRO.PKG_PDF</tt>? Does this actually have anything to do with the procedure above?
I get the error message as below when i execute the procedure above;How do you execute it?
What happens when it's executed without the <tt>when others...</tt> built-in bug?

Similar Messages

  • Write PDF files from database to file system

    Hi,
    I have a requirement of writing PDF files that are stored in Oracle 10g's BLOB column to the FILE SYSTEM using PL/SQL (Not java or any external stored Proc), since i need to write a shell script which will load the PDF files from database on a timely basis.
    Could anyone suggest me the way of executing this?
    Environment: Oracle 10G (10.2.0.1.0) with Windows 2003 server.
    Regards,
    Nagarjun.

    You could try to use the UTL_FILE package that is able to read/write text and binary data in a file located on the box hosting the database instance.

  • Html db to display pdf files saved as blob in the data base

    Hi all,
    I have a DB page to call next page to display pdf files.
    A procedure is being called when the link is clicked on the first page.
    However, the procedure output a juck code insteand the pdf files. Please help.
    Thanks,
    n_length number;
    n_image BLOB;
    begin
    select note_image, dbms_lob.getlength(note_image)
    into n_image, n_length
    from n100_notes where note_id = nid;
    owa_util.mime_header('application/pdf');
    htp.p('Content-length: ' || n_length);
    wpg_docload.download_file(note_image );

    we use:
    owa_util.mime_header('application/pdf',false);
    htp.p('Content-Length: ' || dbms_lob.getlength(l_blob));
    owa_util.http_header_close;
    wpg_docload.download_file(l_blob);
    see plpdf.com
    LL

  • Display pdf file from server on android

    Hi,
    I don't know if here is a right place to ask this question.
    I am new to Flash Builder 4.5 and I need to show a PDF file from my server on Android device.
    Is there any suggestion how I can do this.
    Thanks in advance,
    Mana

    I really don't know how I should use <html>, But if you mean "htmlloader", that doesn't work on android. I have a piece of code as below:
    private var pdf:HTMLLoader;var request:URLRequest = new URLRequest("a URL/mypdf.pdf");
    pdf = new HTMLLoader();pdf.load(request);
    But it does not work.
    Could you help me with <html> and how i can use it in my code?
    Thanks,
    Mana

  • Displaying PDF files (stored as BLOBs in Database) using Forms 6i

    Hi,
    We have PDF and Word documents stored in Database (Version 8.1.7). We are using Oracle Forms 6i as User Interface. Through Forms we could view word documents which are stored in database, using OLE container.
    But we could not view PDF files.
    It would be more helpful and valuable if I get ideas/suggestions on this.
    Thanks in advance,
    Umasankar

    Frank,
    You are correct, I totally agree with you.
    TOAD software which i suggested was not for user interface but more for testing purpose - To ensure that the documents is uploaded to BLOBS correctly.
    I am not a WEB person, but I believe sugnificant coding is required in forms6i/9i with WEB features to display the respective documents.
    If, the purpose in ONLY for testing, then TOAD can be used which requires no coding.
    -- Shailender Mehta --

  • How to batch upload PDF files into database BLOB

    Hello.
    I have a requirement to batch upload PDF files into BLOB column of an Oracle 8.1.7 table from Forms 6i Web. The content of the blob column (ie. the PDF content) MUST be displayable from all client software (eg. Oracle Web forms, HTML forms, etc.)
    Our environment is
    Middle-tier is 9iAS on Windows/2000
    Database is Oracle 8.1.7.0.0 on VMS
    Oracle Web Forms 6i Patch 10
    Basically my Oracle web form program will display a list of PDF files to upload and then the user can click on the &lt;Upload&gt; button to do the batch upload. I have experimented the following approaches but with no luck.
    1. READ_IMAGE_FILE forms built-in = does NOT work because it cannot read PDF file. I got error FRM-47100: Cannot read image file
    2. OCX and OLE form item = cannot use this because it does NOT work on the Web. I got error FRM-41344 OLE object not defined
    3. I cannot use DBMS_LOB to do the load because the PDF files are not in the database machine.
    4. Metalink Note 1682771.1 (How to upload binary documents back to database blob column from forms). When I used this, I got ORA-6502 during the hextoraw conversion. In using this solution, I have downloaded a bin2hex.exe from the Google site. I've noticed that when I looked at the converted HEX file, each line has the character : (colon) at the beginning of each line. I know the PDF file has been converted correctly to HEX format because when I convert the HEX file back to BIN format using hex2bin.exe, I'm able to display the converted bin file in Acrobat Reader. When I removed the : (colon) in the HEX file, I did NOT get the ORA-6502 error but I CANNOT display the file in Acrobat Reader. It gives an error "corrupted file".
    5. upload facility in PL/SQL Web toolkit - I tried to automatically submit the html form (with htp.p) but it does NOT load the contents of the file. I called the URL from Oracle forms using web.show_document. There seems to be issues with Oracle Web forms (JInitiator) and HTML (+ htp.p).
    The other options I can think of at this point are:
    1. Use SQL*Loader to do the batch upload via SQL*Net connection and use HOST() built-in from Oracle Webforms to execute SQL*Loader from the 9iAS.
    2. Write a Visual Basic program that reads a binary file and output the contents of the file into a byte array. Then build a DLL that can be called from Oracle webforms 6i via ORA_FFI. I don't prefer this because it means the solution will only work for Windows.
    3. Write a JSP program that streams the PDF file and insert the contents of the PDF file into blob column via JDBC. Call JSP from forms using web.show_document. With this I have to do another connection to the database when I load the file.
    4. Maybe I can use dbms_lob by using network file system (NFS) between the application server and VMS. But this will be network resource hungry as far as I know because the network connection has to be kept open.
    Please advise. Thank you.
    Regards,
    Armando

    I have downloaded a bin2hex.exe from the Google site.
    ... each line has the character : (colon) at the
    beginning of each line. I'm afraid it isn't a correct utility. I hope you'll find the source code of a correct one at metalink forum:
    Doc ID: 368771.996
    Type: Forum
    Subject: Uploading Binary Files: bin2hex and hex2bin do not reproduce the same file
    There is some links to metalink notes and some example about working with BLOB at http://www.tigralen.spb.ru/oracle/blob/index.htm. Maybe it helps. Sorry for my English. If there is any problem with code provided there, let me know by e-mail.

  • Downloading a file from Database [Blob field]

    I am trying to write an application which can upload and download files [Excel, Word etc.] to/from an Oracle 9i database Blob field. I am using Java/JSP for the same.
    The upload part works just fine. However, when I try to download the file that I uploaded, I get an error.
    A dialog box comes up asking me to Open/Save the file. However, when I try to save it, it says
    �Internet Explorer cannot download �..tion=download&planId= testplan from localhost
    Internet Explorer was not able to open this Internet Site. The requested site is either unavailable or cannot be found. Please try again later.�
    I am using IE 6.0. I tested the same with Firefox browser and was able to download the file.
    Can anyone help?
    Code:
    Following is the code I am using for the same.
    /* Code to retrieve from Blob field */
    String sqlString = "SELECT PLAN_DOCUMENT_NAME,PLAN_DOCUMENT FROM BRS_PLAN_DESCRIPTION WHERE PLAN_ID = ?";
    ps = con.prepareStatement(sqlString);
    ps.setString (1,planId);
    rs = ps.executeQuery();
    while (rs.next()) {
         fileBytes = rs.getBytes("PLAN_DOCUMENT");
         fileName = rs.getString("PLAN_DOCUMENT_NAME");
    brsPlanDocument.setPlanId(planId);
    brsPlanDocument.setFileName(fileName);
    brsPlanDocument.setFileBytes(fileBytes);
    /* Code for download */
    String fileName = brsPlanDocument.getFileName();
    String fileType = fileName.substring(fileName.indexOf(".")+1,fileName.length());
    if (fileType.trim().equalsIgnoreCase("txt"))
         response.setContentType( "text/plain" );
    else if (fileType.trim().equalsIgnoreCase("doc"))
         response.setContentType( "application/msword" );
    else if (fileType.trim().equalsIgnoreCase("xls"))
         response.setContentType( "application/vnd.ms-excel" );
    else if (fileType.trim().equalsIgnoreCase("pdf"))
         response.setContentType( "application/pdf" );
    else if (fileType.trim().equalsIgnoreCase("ppt"))
         response.setContentType( "application/ppt" );
    else
         response.setContentType( "application/octet-stream" );
    response.setHeader("Content-Disposition","attachment; filename=\""+fileName+"\"");
    response.setHeader("cache-control", "no-cache");
    byte[] fileBytes=brsPlanDocument.getFileBytes();
    ServletOutputStream outs = response.getOutputStream();
    outs.write(fileBytes);
    outs.flush();
    outs.close();

    Hi,
    is this problem solved for you, I am also writing the java code to store different files in blob fields in database(db2udb) and allow users to open them through jsp pages. Upload seems to be working fine.....My big problem is only excel files are opened properly in both IE and Firefox. Word files, image files are not getting opened. Any suggestion as what I could be doing wrong....my jsp is kind of similar to the above one...
    thanks in advace, please guide me
    long pmsId = new Long(request.getParameter("pmsId")).longValue();
    String fileName = request.getParameter("fileName");
    int fileSeq = new Integer(request.getParameter("fileSeq")).intValue();
    if(fileName.endsWith("txt")) {
    response.setContentType("text/plain");
    log.debug(" this is a text file");
    } else if(fileName.endsWith("xls")) {
    response.setContentType("application/vnd.ms-excel");
    log.debug(" this is a excel file");
    } else if(fileName.endsWith("gif")) {
    response.setContentType("image/gif");
    log.debug(" this is a image file");
    } else if(fileName.endsWith("doc")) {
    response.setContentType("application/msword");
    log.debug(" this is a doc file");
    } else if(fileName.endsWith("pdf")) {
    response.setContentType("application/pdf");
    log.debug(" this is a pdf file");
    } else if(fileName.endsWith("ppt")) {
    response.setContentType("application/ppt");
    log.debug(" this is a ppt file");
    } else {
    response.setContentType("application/everythingelse");     
    log.debug(" this is a unknown ile");
    response.setHeader("Content-Disposition", "attachment;filename="+fileName);
    OutputStream out1 = response.getOutputStream();
    Class.forName("com.ibm.db2.jcc.DB2Driver");
    db2Conn = DriverManager.getConnection("jdbc:db2:TESTDB","db2admin","db2fv1000");
    //log.debug("connection obtained");
    pstmt = db2Conn.prepareStatement(" SELECT * FROM UPLOADDOCS WHERE PMSID = ? AND DOCSEQ = ? ");
    //log.debug("statemenmt prepared");
    pstmt.setLong(1, pmsId);
    pstmt.setInt(2, fileSeq);
    rs = pstmt.executeQuery();
    int count = 0;
    if(rs.next()){
    InputStream is = rs.getBinaryStream("DOCUMENT"); //"is" is
    //now the binary data
    //of the file
    byte[] buf = new byte[4096];
    int len;
    while ((len = is.read(buf)) > 0)
         out1.write(buf, 0, len);
    out1.close();
    out1.flush();

  • How to Create a PDF file from database package/procedure in 10g?

    Hi,
    Is there a way to create a pdf file in 10g Application Server using PL/SQL package/procedure in 10g database?
    Thanks in advance.
    Regards
    Vishnu Nekkanti

    http://technology.amis.nl/2010/10/20/as_pdf-generating-a-pdf-document-with-some-plsql/
    http://technology.amis.nl/2012/04/11/generating-a-pdf-document-with-some-plsql-as_pdf_mini-as_pdf3/

  • Wont display pdf files from bookmarked sites

    I've upgraded to Firefox 4 and now when I go to some of bookmarked sites that have attached PDF files, I'm unable to view those PDF files. I didn't have this problem with Firefox 3.5, however, per your suggestion, I've downloaded Firefox 4 to avoid any possible security issues. Any possible solutions, or is it possible to revert to using 3.5 w/0 any security issues?

    Back up all data.
    Quit Safari. In the Finder, select Go ▹ Go to Folder... from the menu bar, or press the key combination shift-command-G. Copy the line of text below into the box that opens, and press return:
    /Library/Internet Plug-ins
    From the folder that opens, remove any items that have the letters “PDF” in the name. You may be prompted for your login password. Then launch Safari and test.
    If you still have the issue, repeat with this line:
    ~/Library/Internet Plug-ins
    If you don’t like the results of this procedure, restore the items from the backup you made before you started. Relaunch Safari again.

  • Safari doesn't display pdf file from within Dropbox

    When I click on a link on a web page that takes me to a pdf file located in a shared Dropbox folder, Safari only gives me a solid black page and doesn't open the pdf file.  All the other browsers do, Chrome, Firefox and even IE.  How can I fix this?  I have Mountain Lion and the latest version of Safari.  Pdf-plugin-244 is installed.  I tried the suggestion in another posting about viewing pdf files in Safari, and it didn't fix the problem.

    Pdf-plugin-244 is installed.
    Test without it.

  • How to access a PDF file from Oracle DATABASE SERVER

    Hi
    I have some pdf files in "\home2\docs" directory in Oracle database server 10g. (OS is Linux) I want to access those pdf files from my client system through Oracle Forms. How is it possible?
    Please Help!!!! It is very urgent !!!
    Expecting fast response!!!!!
    Bye

    hi
    Thank u for ur response.
    Initially i tried to access pdf file from database server. I didn't get any solution for that. So I copied all my pdf files to Application server which is in Linux environment at "/home2/docs" directory.
    I gave the following command for accessing the pdf files kept in Lnux Application Server from Oracle 10g forms in a button press trigger.
    web.show_document('http://192.168.1.53:7779/home2/docs/test.pdf');
    It says "page cannot be found"
    So I copied one of the pdf file named "test.pdf" to "/oracle/oas10g/IasHome/forms90/java" in Linux Application Server . Then the following command
    web.show_document('http://192.168.1.53:7779/forms90/java/test.pdf');
    has opened the the pdf file in browser.
    192.168.1.53 is my Linux Application Server IP. and 7779 is the port.
    Actually we have lacs of pdf files. So i cannot keep all the pdf files in "/oracle/oas10g/IasHome/forms90/java" directory in Linux Application Server. And also all the pdf files not in the same directory , "/home2/docs" some of the pdf files r in the subdirectories of "/home2/docs/" like /home2/docs/sub1, /home2/docs/sub2, /home2/docs/sub3 etc.
    Then how to configure my "/oracle/oas10g/IasHome/forms90/server/forms90.conf" file for retrieving pdf files from "/home2/docs/" and its subdirectories. Is Anything other than this, required for solving my problems.
    Now My PDF files r in LINUX APPLICATION SERVER not in database server.
    Please help!! It is VERY URGENT!!!

  • Problems opening pdf-files from KM of portal

    Hi,
    we store documents in our portal in KM. When I use pdf-files that where not saved with Office2007 tools I get the problem, that I can open the file once. If I open it the second time I get the error message "file doesn't start with "%PDF-". and the file will not be opend. If I delete the temporary files in the internet explorer, the file can be opended, again.
    If I open the file directly in the internet explorer I don't have those problems, so it seems, that the portal uses a different viewer than the internet explorer itself. 
    Has anyone an idea how to solve this problem?
    Regards
    Ulrike

    Ulrike,
    I think this is a known issue.
    Affected versions:
    o KMC SAP NetWeaver 7.0 (formerly named 2004s) SP 14
    o KMC SAP NetWeaver 7.0 (formerly named 2004s) SP 15
    If you have the above KMC and SP Versions then you need to follow the below SAP note:
    Note 1146711 - Problem opening PDF files.
    Have you checked the belowSAP Note?
    Note 954627 - Issues with opening/displaying PDF files from KM
    Regards,
    Karthick Eswaran

  • How to Save pdf file in the BLOB field in the database

    I have to save a pdf file which is on the client machine to save in the database column of type BLOB. How can i do that?

    LostWorld wrote:
    I have to save a pdf file which is on the client machine to save in the database column of type BLOB. How can i do that?PL/SQL code cannot hack across the network. break into that client machine, and read that PDF file from the client's harddrive.
    There is a very fundamental client-server principle at stake here - the purpose of the client. What is the purpose of the client? Amongst others, it is to interface with the client hardware and peripherals and devices. Like reading the client keyboard and sending that to the server. Or reading data from the sever and rendering it on the client's display device. Or to receive CSV data from the server and writing it to a local file.
    It's purpose is also to read a local file, like a PDF file, and submit that file's contents to the server for storage.
    The following pseudo code explains the basic principle:
    client
      // call oracle to create a LOB
      ExecuteSQL( 'DBMS_LOB.CreateTemporary( .. )' )
      open file( fileHandle )
      while not EOF( fileHandle )
        // read data from the file
        read file( fileHandle, buffer )
        // write this buffer to the LOB in Oracle
        ExecuteSQL( 'DBMS_LOB.writeAppend( .. )' )
      end while
      close file( fileHandle )
      // now tell Oracle what to do with that LOB
      ExecuteSQL( '...' )
      .. etc..Thus the client:
    a) creates a LOB in Oracle via a PL/SQL call
    b) passes data from the client and appends it to the LOB
    c) tells Oracle what to do with LOB, such as inserting it into a table

  • Lately pdf files from the Web do not display properly; what is wrong and how can I fix it so I don't have to use IE?

    I am a professor and frequently need to open pdfs of academic journal articles from electronic databases. Within the last two or three weeks, when I try to do this using Firefox, only the first page of the pdf displays and the rest are blank. In addition, a bar appears across the top with the message "This pdf file may not display properly." So I have had to switch to Internet Explorer to open the files and do my research. What is going on and how can I fix it so I can open pdf files from the Web in Firefox and have them display properly?

    My question is simple - why would you put an application in production that has a lot of bugs? To replace a good and steady Adobe product? My customers will believe that I put a pathetic fallible form online. They are not sophisticated on computers so I just tell them to use IE. Ugh
    I must agree with pgwebgirl!

  • Pulling a PDF file from the database

    How would I display a pdf file from the database, or should I convert it to an image and if so how do I convert it into an image?

    Hi Phil_Kenya,
    Some samples here:
    https://social.msdn.microsoft.com/Forums/vstudio/en-US/db1556be-0f71-41cb-92de-b95f1e1ca3a3/how-can-i-load-a-pdf-file-in-my-database-filemdf-in-aspnet-web-project?forum=csharpgeneral
    http://stackoverflow.com/questions/7747796/displaying-pdf-files-in-a-web-page-from-a-sql-database-directly-without-needing
    I suggest you post this issue to the language development forum like above case, I think you would get more dedicated support.
    Best Regards,
    Jack
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

Maybe you are looking for

  • My ipod is a complete mystery

    My ipod is really causing me some problems. Let me give a little backstory. Recently, a tree was struck by lightning in our front yard and created a lot of problems. For instance, the power supply in the computer was blown. Upon replacing the power s

  • Can PCI flash storage on the new MBPs be replaced with a HDD?

    I'm looking to buy a new Macbook Pro. Apple's store has several available, all but one of which use PCI-based flash storage as opposed to SATA drives. My question is, if I buy one of these, is it possible to swap out the flash storage drive for a har

  • Is jsp:plugin supported in weblogic 5.1 or 6.0?

    I tried to compile %WEBLOGIC_ROOT%\examples\applets\phonebook12.jsp in WLS5.1.The generated servlet class(using a java decompiler to generate a source code or using anotepad to view the class file directly) still has <jsp:plugin> tag in it.jspc does

  • Any benefit to import java.util.Vector over import java.util.*?

    By benefit I mean does it reduce compile time or have some other beneficial side effect to import only those classes you're using in a class rather than importing the package they reside in. For example: // this? import java.util.Vector; // or this..

  • IDVD disk reading problem on MacBook Pro

    When I burn a movie using iDVD v.7.0.3, I'm not able to play it on my MacBook Pro. When I burn the same movie on another machine using iDVD v.6.0.4, I can play it on the MacBook Pro with no problem. Please advise. Thanks, Greg