Skip to Main Content

 
Titelbild Muniqsoft Training

Auswahl  

Komplett Übersicht aller Oracle Tipps

PDF display from table in APEX 

Oracle
APEX
APEX 22.2:APEX 23.1:APEX 23.2:APEX 24.1:APEX 24.2:RDBMS 19.1
26.03.25 (MP)
05.04.25(MP)
APEX, PDF, Tabelle

Passende Schulungen zum Thema

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:

  1. Create Table
    Example-Table: emp_lob
     
  2. 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)
  3. Place the form with report on this table. You can then use this to load the PDF into your table
  4. Create a new application item (Shared Components / Application Logic / Application Item) in APEX (name: EMPNO) and set this item to unrestricted.
  5. 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;
  6.  Create a new page with a static content region:
    Please adjust the IP address and possibly the port on your server
  7. 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)
  8. <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 ...