Problem: when displaying a PDF file, it displays OK as PDF if APEX 'Compatability Mode' = 'Pre 4.1', but displays as HTML when in either '4.1' or '4.2' mode.
Web server: Apache on Linux
More detailed description... this seems to be a MIME type issue related to APEX (or maybe DB) versioning. The following code works as expected when run in 'Pre 4.1' mode - ie. it displays an appropriate PDF document in the appropriate Acrobat/other plugin in several browsers (Firefox/Opera/Chrome/IE). But just by changing 'Compatability Mode' to '4.2' (or even '4.1'), it then downloads the file but displays it as a bunch of random characters, and the web page header MIME type is 'text/HTML'.
Note: this also happens with other file types such as xls/doc/etc, but I expect fixing PDF should also fix these.
I'm at a bit of a loss as to where this is happening, it seems there is a difference in the 'Compatibility Modes' between either the creating of the HTML header using 'OWA_UTIL.mime_header' or the component path it traverses before reaching apache.
The only other thing I could think of is that we do a bit of redirection to display the PDF, though this seems like it might be a red herring. Basically we use page 560 as a container, and then display the PDF with page 561 within a frame embeded within page 560. So, on the page 560, which is the one we reference throughout the application, we have a region with a source of '<iframe src=?p=&APP_ID.:561:&SESSION.height="500" width="700"></iframe></pre>'. Then on page 561, in a 'On Load - Before Header' process, we make the call to the code 'DOWNLOAD_APPLICANT_PDF' (below).
Note: I did try calling 'apex_application.stop_apex_engine' after 'DOWNLOAD_APPLICANT_PDF', as suggested in a couple threads, but it didn't fix the problem, and caused a couple low-level system errors.
CREATE OR REPLACE PROCEDURE DOWNLOAD_APPLICANT_PDF ( p_doc_id IN NUMBER
l_display_inline CHAR := '1';
SELECT pdf_data, DBMS_LOB.getlength (pdf_data)
INTO lob_loc, v_length
WHERE pdf_dest_id = p_doc_id;
OWA_UTIL.mime_header ('application/pdf', FALSE);
HTP.p ('Content-length: ' || v_length);
for some background information about the above changed behavior, have a look at 4.2 Before Header Processes and Browser Security HTTP Headers of the APEX 4.1. release notes.
Member of the APEX development team
My Blog: http://www.inside-oracle-apex.com
APEX Plug-Ins: http://apex.oracle.com/plugins