The question of how to display a PDF in a page comes up very often in our APEX courses. In our case, the PDF comes from a table in the Oracle database.
Preparation:
- Create Table
Example-Table: emp_lob
CREATE TABLE emp_lob (
EMPNO NUMBER(4,0),
ENAME VARCHAR2(10 BYTE),
DATEINAME VARCHAR2(512 BYTE),
BESCHREIBUNG VARCHAR2(4000 BYTE),
DATEITYP VARCHAR2(100 BYTE),
L_UPDATE DATE,
BILD BLOB)
- Place the form with report on this table. You can then use this to load the PDF into your table
- Create a new application item (Shared Components / Application Logic / Application Item) in APEX (name: EMPNO) and set this item to unrestricted.
Create an application process (Shared Components / Application Logic / Application Process) in APEX: Name getPDF and define as Ajax Processes
The process has the following code:
begin
for file in (select * from emp_lob
where empno = :EMPNO
and dateityp='application/pdf') loop
sys.htp.init;
sys.owa_util.mime_header( file.dateityp, FALSE );
sys.htp.p('Content-length: ' || sys.dbms_lob.getlength( file.bild));
sys.htp.p('Content-Disposition: inline; filename="' || file.fname || '"' );
sys.htp.p('Cache-Control: max-age=3600'); -- tell the browser to cache for one hour, adjust as necessary
sys.owa_util.http_header_close;
sys.wpg_docload.download_file( file.bild );
apex_application.stop_apex_engine;
end loop;
end;
- Create a new page with a static content region:
Please adjust the IP address and possibly the port on your server - In this region (we are now starting from page 1) there should be an item with the name P1_EMPNO. The corresponding line in which the PDF is located can then be selected there.
The page should then have a submit button (e.g. via a button) <object
data="http://127.0.0.1:8080/ords/f?p=100:0:&SESSION.:APPLICATION_PROCESS=getPDF:::EMPNO:&P1_EMPNO." style="width:100%;height:700px">
<a href="http://127.0.0.1:8080/ords/f?p=100:0:&SESSION.:APPLICATION_PROCESS=getPDF:::EMPNO:&P1_EMPNO.">PDF laden</a>
</object>
And now have fun displaying all your PDFs. We use it to display our PDF invoices in APEX :-)
See you (hopefully) soon in one of our courses ...