Environment:
APEX 5.0
ORDS
Oracle 12c
Tomcat
I'm trying to code and apex app to send a query result as a PDF attachment to an email.
I've read a few different instructions online, and for some reason i'm having issues.
I'm using the GET_PRINT_DOCUMENT(2) option
APEX_UTIL.GET_PRINT_DOCUMENT (
p_application_id IN NUMBER,
p_report_query_name IN VARCHAR2,
p_report_layout_name IN VARCHAR2 default null,
p_report_layout_type IN VARCHAR2 default 'xsl-fo',
p_document_format IN VARCHAR2 default 'pdf',
p_print_server IN VARCHAR2 default null)
RETURN BLOB;
My Setup:
Here is my After Submit email process:
| DECLARE |
| l_id number; |
| l_document BLOB; |
| BEGIN |
| l_document := APEX_UTIL.GET_PRINT_DOCUMENT |
| ( |
| p_application_id=>'102', |
| p_report_query_name=>'xmlqry', p_report_layout_name=> 'mylayout', |
| p_report_layout_type=>'xsl-fo', |
| p_document_format=>'pdf' |
| ); |
| l_id := APEX_MAIL.SEND |
| ( |
| p_to | => 'nouser@yahoo.com', | |
| p_from | => 'nouser@yahoo.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' |
| ); |
I built a simple query like so "Select user_id, username, name, role from myuserstable where id = 1"
and called it XML_QRY.
I tested the query in the query builder and it works just fine.
Upon sending the email, its sends and i get the email successfully with the assumed PDF document attached.
But when i try to open the PDF, its says its corrupt.
I can download a PDF document directly from an interactive or classic report with no problems.
Any ideas of what i'm doing wrong?