Forum Stats

  • 3,733,067 Users
  • 2,246,687 Discussions
  • 7,856,492 Comments

Discussions

How to showing pdf file in browser before download it ?

Chazg
Chazg Member Posts: 7 Green Ribbon

i want to showing pdf file in browser first but the file is download instead.


my code


 PROCEDURE PR_SHOW_REPORT(io_blReport      IN OUT BLOB,

              i_vcContentDisposition IN VARCHAR2 DEFAULT 'inline',

              i_vcFilename      IN VARCHAR2 DEFAULT 'reportresult.pdf') IS

   l_mime    VARCHAR2 (255);

   l_length   NUMBER;

   l_file_name  VARCHAR2 (2000);

   lob_loc    BLOB;


 BEGIN  

   OWA_UTIL.mime_header ('application/pdf', FALSE);

   HTP.p ('Content-Length: ' || DBMS_LOB.GETLENGTH(io_blReport));

   HTP.p ('Content-Disposition: ' || i_vcContentDisposition ||'; filename="' ||  i_vcFilename || '"');

   OWA_UTIL.http_header_close;

   WPG_DOCLOAD.download_file(io_blReport);

 END;


Thanks.

Answers

  • Sylvain Martel
    Sylvain Martel Member Posts: 672 Bronze Trophy
    edited April 4

    Hello Chazg,

    I've been using a Dynamic PL/SQL region with success using this code:

    declare
    l_blob blob := empty_blob(); -- Blob to store the file content
    l_step number := 22500; -- Steps in bytes to print the file content
    l_filename xxapex_sb_inv_iface.invoice_file_filename%type;
    begin
      -- Get the blob content of the file
      l_blob := ...
     
      -- Open temporary lob
      dbms_lob.open(l_blob, dbms_lob.lob_readonly);
     
      -- Write the code to display the PDF
      htp.p('<embed src="data:application/pdf;base64,');
     
      -- Loop through the blob content
      for i in 0 .. trunc((dbms_lob.getlength(l_blob) - 1 )/l_step) loop
        -- Get a substring of the blob, encode it to Base64 and cast from RAW to varchar
        htp.p( utl_raw.cast_to_varchar2(utl_encode.base64_encode(dbms_lob.substr(l_blob, l_step, i * l_step + 1))));
      end loop;
    
      -- Close the HTML tag and add some properties
      htp.p('" height="600" width="700" >');
     
      -- Close lob objects
      dbms_lob.close(l_blob);
    
    end;
    
    

    Hope this help!

Sign In or Register to comment.