Translate

Dienstag, 17. August 2021

APEX - Render PDF in Region

 sorry for crossposting - but this one is worth mentioning:

Thanks to Vinish Kapoor and his detailed post on rendering a pdf or image in a static region.

This is a working example for APEX 21.1 (not tested on other versions)

The steps in short:

1. have a table (my_table) with a blob column and mimetype column - and id ofcourse...

2. create an application process (in shared components) of type AJAX callback

DECLARE
  vBlob blob;
  vmimetype varchar2(50);
BEGIN
  SELECT BLOB_column, mimetype_column INTO vBlob, vmimetype
                FROM my_table
                WHERE ID = V('P3_ID');
                 
  owa_util.mime_header(vmimetype,false);
  htp.p('Content-Length: ' || dbms_lob.getlength(vBlob)); 
  owa_util.http_header_close;  
  wpg_docload.download_file(vBlob);
  exception 
  when no_data_found then
   null;
END;

3. create a page with a region type static content and insert this:

<p align="center">
<iframe src="f?p=&APP_ID.:0:&SESSION.:APPLICATION_PROCESS=display_blob:NO:P3_ID,&P3_ID." width="99%" height="1000">
</iframe>
</p>
Note: contrary to Vinishs example 
I had to delete one " : " between NO and :P3_ID... (as shown above)
4. for my purpose I created a 2nd region of type IR or 
classic report and put a link on one of the columns to 
point to the same page 3 ... and defined a hidden item 
named P3_ID.
So as you can see from the above the APEX-URL calls 
the APPLICATION_PROCESS "display_blob" and passes 
the ID from the page to the process... which in turn 
renders the pdf within the iFrame.
I put the report on the left side of the page and 
the 2nd region aside of it.
Have fun and thanks to Vinish again! Great job !

Keine Kommentare:

Kommentar veröffentlichen