2 Replies Latest reply: Dec 4, 2012 5:28 AM by VC RSS

    APEX_UTIL.GET_PRINT_DOCUMENT always returning empty BLOB

    977570
      Dear community,

      I have a huge problem when using the function APEX_UTIL.GET_PRINT_DOCUMENT in a job or database procedure.

      The following code runs perfectly when I integrate it in the APEX application directly e.g. using a button to execute it (of course I use an anonymous PL/SQL block in APEX itself). But when I run the same code as a procedure or job in the APEX database itself I always receive a mail with an empty PDF:

      CREATE OR REPLACE PROCEDURE APEX_DRUG_SAFETY.CALL_MAIL
      is
      l_id number;
      l_document BLOB;
      BEGIN

      wwv_flow_api.set_security_group_id;

      l_document := APEX_UTIL.GET_PRINT_DOCUMENT
      +(+
      p_application_id=>'105',
      p_report_query_name=>'TestReport',
      p_report_layout_type=>'pdf',
      p_document_format=>'pdf'
      +);+


      l_id := APEX_MAIL.SEND
      +(+
      p_to        => 'test@test.com',
      p_from      => 'test@test.com',
      p_subj      => 'sending PDF via print API',
      p_body      => 'Please review the attachment.',
      p_body_html => 'Please review the attachment.'
      +);+

      APEX_MAIL.ADD_ATTACHMENT
      +(+
      p_mail_id    => l_id,
      p_attachment => l_document,
      p_filename   => 'mydocument.pdf',
      p_mime_type  => 'application/pdf'
      +);+


      wwv_flow_mail.push_queue(
      P_SMTP_HOSTNAME => 'DESMTP.TEST.COM',
      P_SMTP_PORTNO => '25');

      end;


      The problem is that the function APEX_UTIL.GET_PRINT_DOCUMENT always returns an empty BLOB when executed outside of the APEX application. I found this issue in several other posts in this forum but I did not find a solution.

      The mail transmission itself works perfectly. Also with an attachment if e.g. I use another BLOB already stored in the database for testing purposes. So it is not the mail transmission that causes the problem but the empty variable l_document that is still empty.

      Thanks in advance for the help.