18.3.3 Printing Personalized Certificate
Generate a personalized PDF certificate in the background and store it temporarily for email delivery.
The Generate Certificate child process uses Invoke API to call the
procedure below, passing in the candidate employee ID from
P34_EMPLOYEE_EMPNO. It does the following key tasks:
- Sets employee ID into
G_EMPLOYEE_EXCELLENCE_EMPNOapp item the report query references - Generates PDF certificate using report query by static ID and its associated report layout
- Creates an
EMP_EXCELLENCE_CERTIFICATEcollection - Adds generated PDF to it for use in email attachment.
-- In package eba_demo_woodshr_reward
procedure generate_certificate(
p_empno in number)
is
l_certificate_pdf blob;
begin
apex_background_process.set_status('Generating Certificate');
-- Set application item referenced in Report Query to passed empno
apex_session_state.set_value('G_EMPLOYEE_EXCELLENCE_EMPNO',p_empno);
-- Generate the document using a report query by static id
l_certificate_pdf := apex_print.generate_document(
p_application_id => V('APP_ID'),
p_report_query_static_id => 'emp_excellence_certificate');
-- Create collection and add PDF blob for email attachment to it
apex_collection.create_or_truncate_collection('EMP_EXCELLENCE_CERTIFICATE');
apex_collection.add_member(
p_collection_name => 'EMP_EXCELLENCE_CERTIFICATE',
p_blob001 => l_certificate_pdf);
apex_background_process.set_progress(p_totalwork => c_steps, p_sofar => 8);
apex_background_process.set_status('Generating Certificate Completed');
end generate_certificate;Parent topic: Offloading Work to the Background