Senin, 24 Juli 2017

Implementing PDF.js on Oracle APEX

Here step by step preparation :


  • Install PDF.js under image prefix apex

  • Prepare Download page helper
    • Page with alias : DOWNLOAD_PDF
    • Process : before header
    • declare
        r_data EMP_PDF%rowtype;
      BEGIN
        select * into r_data
          from emp_pdf
         where empno = :P4_EMPNO;
          sys.htp.init;
          sys.owa_util.mime_header( r_data.mimetype, FALSE);
          sys.htp.p('Content-length: ' || sys.dbms_lob.getlength( r_data.pdf_data ));
          sys.htp.p('Content-Disposition: inline; filename='||r_data.filename );
          -- tell the browser to cache for one hour, adjust as necessary
          sys.htp.p('Cache-Control: max-age=3600');
          sys.owa_util.http_header_close;
          
          sys.wpg_docload.download_file(r_data.pdf_data);
          apex_application.stop_apex_engine;
      exception when others then
          sys.htp.prn('error: '||sqlerrm);
          apex_application.stop_apex_engine;
      END;
      
Case 1 : On form
  • Create Static Region

  • Preview

Case 2 : On Tabular form


Rabu, 29 Maret 2017

Query APEX Metadata out of APEX Context

For example you need to query on sql developer or execute apex_email from oracle job

example:
Select *
  from APEX_MAIL_QUEUE;

result : no row selected
Solution : Create procedure to mimic APEX context
create or replace procedure set_apex_context (
  p_app_id in number 
) as 
begin
 FOR c1 IN (
   SELECT workspace_id
    FROM apex_applications
   WHERE application_id = p_app_id
  )
 LOOP
   apex_util.set_security_group_id(p_security_group_id => c1.workspace_id);
 END LOOP;
end set_apex_context;

How to use :
before execute query run the procedure:
execute set_apex_context (140); --i40 is app id 
Select *
  from APEX_MAIL_QUEUE;