13 Replies Latest reply: Mar 26, 2013 7:58 AM by PhHein RSS

    Show PDF ....

    894843
      Hi all..

      APEX: 4.1
      Database:11g
      APEX Listener

      How can i show a PDF DOC in the browser without giving a download option to the users?
      I have a PDF doc saved in the database as a BLOB content.
      I am using the following PROC to download the PDF from the database.

      Everything is working fine, I am able to download the PDF from the database.
      But instead of downloading i want to show the PDF in a separate browser(inline)

      I tried changing ""'Content-Disposition:""" to ""inline"".

      My code:

      I have a button on a page..
      with URL target as
      {code}
      javascript:open_pdf_doc();
      {code}

      {code}
      function open_pdf_doc() {

      var v_url = 'download_doc?i_doc_id=' + '&P405_DOC_ID.';
      window.location.href = v_url;

      }

      {code}



      {code}

      create or replace
      PROCEDURE download_doc(i_doc_id in number) AS

      v_mime VARCHAR2(48) := 'PDF' ;
      v_length NUMBER;
      v_filename VARCHAR2(200);
      v_blob BLOB;

      BEGIN

      SELECT doc_image, DBMS_LOB.GETLENGTH(doc_image), doc_filename
      INTO v_blob , v_length, v_filename
      FROM test_download_doc
      WHERE doc_id = to_number(i_doc_id);


      --
      -- set up HTTP header
      --
      -- use an NVL around the mime type and
      -- if it is a null set it to application/octect
      -- application/octect may launch a download window from windows
      owa_util.mime_header( nvl(v_mime,'application/octet'), FALSE );

      -- set the size so the browser knows how much to download
      htp.p('Content-length: ' || v_length);
      -- the filename will be used by the browser if the users does a save as
      htp.p('Content-Disposition: attachment; filename="'||replace(replace(substr(v_filename,instr(v_filename,'/')+1),chr(10),null),chr(13),null)|| '"');
      -- close the headers
      owa_util.http_header_close;
      -- download the BLOB
      wpg_docload.download_file( v_blob );

      end download_doc;


      {code}

      Thank you...
        • 1. Re: Show PDF in a browser (inline)..
          jariola
          Hi,


          This might help
          http://stackoverflow.com/questions/291813/best-way-to-embed-pdf-in-html


          Also search forum. If I recall this is discussed quite many times.

          Regards,
          Jari

          http://dbswh.webhop.net/dbswh/f?p=BLOG:HOME:0
          • 2. Re: Show PDF in a browser (inline)..
            894843
            Hi jari or anyone..

            please help with this issue..

            jari..

            I created a PL/SQL dynamic content region with the following code.
            declare
              src  varchar2(256);
            begin
             src := 'src="#OWNER#.download_doc?i_doc_id=4" ';
              htp.p('<div style="">');
              htp.p('<embed height="600" width="1200" name="statement" ');
              htp.p(src);
              htp.p('type="application/pdf" />');
              htp.p('</div>');
            end;
            I am getting the following issue..

            1)The PDF if not embedding into the page.It is opening in a new window , showing ""blank"" on the APEX page.
            ""may be it is the browser issue"" IE7. Can anyone help me with this?

            **** Instead of embeding PDF on the page, is it possible to show inline in the browser like how oracle shows any PDF docs in the browser ****


            Jari..

            I have gone through the link that you sent, even in that thread everyone mentioned to use a ""DIV"" and a ""embed"" tag.
            Is it the way that the PDF shows inline in the browser?
            • 3. Re: Show PDF in a browser (inline)..
              jariola
              Hi,

              Can you create example of this problem to apex.oracle.com?

              Regards,
              Jari
              • 4. Re: Show PDF in a browser (inline)..
                894843
                Hi jari...

                I created a sample application as you said.
                Please check the following Application if you get a chance.

                http://apex.oracle.com/pls/apex/f?p=52018

                worspace: kumar2003
                username: test_user
                password: test

                application: 52018

                BROWSER: IE 7
                • 5. Re: Show PDF in a browser (inline)..
                  jariola
                  Hi,

                  Sample works for me.
                  I do not have IE7 , but I did check with IE8 on IE7 mode.

                  Have you try set to procedure you use get file
                  Content-Disposition:  inline;
                  Regards,
                  Jari
                  • 6. Re: Show PDF in a browser (inline)..
                    894843
                    Hi jari..

                    as you said it works fine in IE-8, i tested in my personal laptop.
                    I also tried ""Content-disposition: inline"" jari.
                    even with that the PDF is not embedded into the page.

                    Do you think it might be issue with the IE 7 or with my procedure?

                    this is proc that i am using..
                    create or replace PROCEDURE get_doc(i_doc_id in number) AS
                    
                      v_mime      VARCHAR2(48) := 'PDF' ;
                      v_length    NUMBER;
                      v_filename  VARCHAR2(200);
                      v_blob      BLOB;
                     
                    BEGIN
                    
                      SELECT test_image, DBMS_LOB.GETLENGTH(test_image)
                      INTO   v_blob   ,  v_length
                      FROM test_image
                      WHERE id = to_number(i_doc_id);
                      v_filename  := 'Test.pdf';
                    
                      --
                      -- set up HTTP header
                      --
                      -- use an NVL around the mime type and
                      -- if it is a null set it to application/octect
                      -- application/octect may launch a download window from windows
                      owa_util.mime_header( nvl(v_mime,'application/octet'), FALSE );
                     
                      -- set the size so the browser knows how much to download
                      htp.p('Content-length: ' || v_length);
                      -- the filename will be used by the browser if the users does a save as
                      htp.p('Content-Disposition:  attachment; filename="'||replace(replace(substr(v_filename,instr(v_filename,'/')+1),chr(10),null),chr(13),null)|| '"');
                      -- close the headers            
                      owa_util.http_header_close;
                      -- download the BLOB
                      wpg_docload.download_file( v_blob );
                    
                    end get_doc;
                    Instead of showing it as a ""embedded pdf"" on a page.
                    Is it possible to show the PDF "inline"" in browser.
                    something like the following

                    {code}
                    http://samplepdf.com/sample.pdf
                    {code}
                    • 7. Re: Show PDF in a browser (inline)..
                      jariola
                      Hi,

                      What I can test issue seems be more IE7 problem as your sample works for me on all browsers I can test. And I can not test on IE7.


                      Instead of showing it as a ""embedded pdf"" on a page.
                      Is it possible to show the PDF "inline"" in browser.
                      something like the following

                      {code}
                      http://samplepdf.com/sample.pdf
                      {code}
                      I'm not quite sure what you mean. But you can place PDF files to server folder where HTTP server can serve those.
                      Then you can have URL like in your example.

                      But do you really like store PDF files outside of database?

                      Regards,
                      Jari
                      • 8. Re: Show PDF in a browser (inline)..
                        Patrick Wolf-Oracle
                        Hi kumar,

                        I don't have IE7, but I have changed your procedure to use "application/pdf" as mime type and also corrected your content-disposition as it should be.

                        I have also added a new link "Open PDF inline" into the first region which should open the PDF inline in the same browser tab but not within the same APEX page. That should be similar to your http://samplepdf.com/sample.pdf example.

                        Can you try again? I also remember that in the past it was possible in Adobe Acrobat to specify if a PDF file should be opened inline in the browser or in a separate Adobe Acrobat window.

                        Regards
                        Patrick
                        -----------
                        My Blog: http://www.inside-oracle-apex.com
                        APEX Plug-Ins: http://apex.oracle.com/plugins
                        Twitter: http://www.twitter.com/patrickwolf
                        • 9. Re: Show PDF in a browser (inline)..
                          894843
                          Hi Patrick...

                          Thanks a tonnn. It is working prefectly now.
                          You mentioned
                          "" I also remember that in the past it was possible in Adobe Acrobat to specify if a PDF file should be opened inline in the browser or in a separate Adobe Acrobat window""

                          ""or in a separate Adobe Acrobat window""

                          So, If i need to open by PDF (which is in database) in a ""separate ADF window"" (not inline in browser).
                          Is it is the Adobe settings that i need to change???
                          or is there any other MIME TYPES that i can use?

                          """
                          which should open the PDF inline in the same browser tab but not within the same APEX page
                          """
                          when i click the link that you created, the PDF is ""opening in the same page""".


                          For anyone who are looking to open a PDF in the browser (inline)

                          {code}
                          v_mime VARCHAR2(48) := 'application/pdf' ; -- mime type that you need to set
                          Content-Disposition: inline -- content disposition should be ""inline""
                          {code}

                          Jari...

                          Thanks a lot for all the help...
                          • 10. Re: Show PDF in a browser (inline)..
                            Patrick Wolf-Oracle
                            So, If i need to open by PDF (which is in database) in a ""separate ADF window"" (not inline in browser).
                            Is it is the Adobe settings that i need to change???
                            or is there any other MIME TYPES that i can use?
                            If you want to open the PDF file in a new tab/window, just create a link with a target="_blank"
                            &lt;a href="your_download_link" target="_blank">PDF</a>
                            which should open the PDF inline in the same browser tab but not within the same APEX page
                            when i click the link that you created, the PDF is ""opening in the same page""".
                            Yes, but not like in your example in a region of the APEX page. It just replaces the existing HTML content with a new content. Like you would navigate to a different web site.

                            Regards
                            Patrick

                            Edited by: Patrick Wolf on Dec 1, 2011 5:46 PM
                            • 11. Re: Show PDF in a browser (inline)..
                              AshPatel2
                              Hi Kumar I know this is a really old post but I just checked your example app posted in this thread about pdf viewing, is there any chance I could get access to the application workspace to see the code please, the account listed in the thread is locked so cant access.

                              Regards
                              Ash
                              • 12. Re: Show PDF in a browser (inline)..
                                JEC
                                I would like access as well, if possible. Thanks so much!

                                Joyce
                                • 13. Re: Show PDF in a browser (inline)..
                                  PhHein
                                  Please don't hijack years old threads, you don't even know whether the old users are still active. Start your own thread and include links to relevant threads.

                                  Mod: locking this zombie.