Using Custom XSL-FO Layout And Calling the APEX Print APIs directly in Custom PL/SQL code to Generate a PDF Results in 503 - Service Unavailable Error (Doc ID 1561550.1)

Last updated on MARCH 08, 2017

Applies to:

Oracle REST Data Services - Version 2.0.1 and later
Oracle Application Express (formerly HTML DB) - Version 4.2.2 and later
Information in this document applies to any platform.

Symptoms

Calling the Apex Listener FOP from the Apex Print API generates a 503 error and a corrupt PDF. This happens when using a custom PL/SQL process to call a Report Query whose layout is based on a custom XSLT-FO named column report layout.

When the report query is called directly, it works fine.  So the custom XSL-FO layout works.
The custom XSL-FO layout does not work only when a PL/SQL call is made to generate a pdf.
The downloaded pdf file is corrupted which when opened in notepad shows HTML code which when rendered on a .html file shows "503 - Service Unavailable" error.

Example Apex code / steps to reproduce the problem:


1) Create a PL/SQL process on an application page run on submit.
2) This PL/SQL process refers to a 'Report Query' in the shared components section of the application.
3) The pdf document created as a result of this process contains a report ran in the called 'Report Query'.
4) The styling and layout of the pdf document is set up via a valid named column (XSL-FO) Report Layout.

DECLARE
l_id number;
l_document BLOB;
BEGIN
l_document := APEX_UTIL.GET_PRINT_DOCUMENT
(
p_application_id=>'124',
p_report_query_name=>'DVR_Detail_3',
p_report_layout_name=>'New_REPO_2',
p_report_layout_type=>'xsl-fo',
p_document_format=>'pdf'
);
l_id := APEX_MAIL.SEND
(
p_to => '********@gmail.com',
p_from => '********@gmail.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'
);

END;


Note:  To enable the APEX_UTIL print APIs for the APEX Listener:


1) Edit the default.xml file found in your APEX Listener config folder and add the following to default.xml:
<entry key="misc.enableOldFOP">true</entry>
2) Restart the APEX Listener.
See related document - Apex Listener 2.0 FOP Gives 404 Error When Called from APEX_UTIL.GET_PRINT_DOCUMENT [Doc ID 1554090.1]


Also, ensure networking services have been enabled on that database, so that outgoing util_htp requests are allowed.



Cause

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms