Hi,
I am trying to implement apex_export_data to download a document as pdf.
What I need to export is HTML content. For this, I have an item "P1_NEW" which is a rich text editor with html data.
And the process I am using is:
----
DECLARE
l_context apex_exec.t_context;
l_export apex_data_export.t_export;
BEGIN
l_context := apex_exec.open_query_context(
p_location => apex_exec.c_location_local_db,
p_sql_query => 'select ''' || :P1_NEW || ''' as thedata from dual'
);
l_export := apex_data_export.export (
p_context => l_context,
p_format => apex_data_export.c_format_pdf,
p_pdf_accessible => true,
p_page_header => 'selected header <span style="color: green;">green green</span>',
p_page_footer => 'selected footer <span style="color: red;">red red</span>',
p_file_name => 'info-data-export' );
apex_exec.close( l_context );
apex_data_export.download(
p_export => l_export
);
EXCEPTION
when others THEN
apex_exec.close( l_context );
raise_application_error (-20101, DBMS_UTILITY.FORMAT_ERROR_BACKTRACE);
END;
-----
The idea is to use the rich text element, to set as the produced html content I would like to export as pdf.
For this, I attempted using it as a DA, with the pl/sql code, but this produces an error "Error: parsererror - SyntaxError: Unexpected token % in JSON at position 0". Is it possible to use it in a DA or not? No matter the format I would use, always throws an error.
So my next step was to use it as a "before header process", this does produce a result, but a weird one.
If I export this as an HTML I can see a result, though it contains the column name, and highlight (which I very much would like to get rid of, I just want it to export as a "html content", in a pdf file).
But if I use the c_format_pdf attribute, all I get is a page with symbols (with adobe data), that if I "save as" from Chrome to a file, it produces a file that cannot opened, as if there is an error in the format in the supposed .pdf file.
I need help with this to make it work, anyone can hint me to the right direction?
The goal: Have an HTML content, to be exported as a PDF file, with APEX and using NATIVE functionality. That would be all.
Thanks!
Edit:
I feel like I should also provide another solution I attempted:
DECLARE
l_export apex_data_export.t_export;
l_region_id number;
BEGIN
SELECT region_id into l_region_id
FROM apex_application_page_regions
WHERE application_id = 300
and page_id = 1
and static_id = 'mytryoutreport';
l_export := apex_region.export_data (
p_format => apex_data_export.c_format_pdf,
p_page_id => 1,
p_region_id => l_region_id );
apex_data_export.download( l_export );
END;
This depends on a classic report (already tried with normal regions, but that produces an error, it seems it is expecting a "select" type of query), in my classic report, the HTML is considered, and the produced result does containg HTML content which looks good in page.
If I use the export as c_format_html, it still downloads a file (.html) which has this html content set appropriately.
However, when using the c_format_pdf, though it DOES download a .pdf file that can be opened by the browser, the issue I have is that is a plain text with no html format in it, which is a problem, because it is not producing the data as expected (while my initial process in this post, only produces an error).
I hope someone can help me on this.
Thanks!!