daust / JasperReportsIntegration

JasperReportsIntegration provides an interface to use the JasperReports reporting engine in an Oracle database application, specifically with Oracle Application Express (Oracle APEX).
BSD 3-Clause "New" or "Revised" License
55 stars 23 forks source link

Charts in HTML #132

Open DavidGhedini opened 1 year ago

DavidGhedini commented 1 year ago

Hi - Charts in HTML do not render when exported. In all other formats (PDF, rtf, etc...) the chart image is simply embedded in the document and renders. Is there any option for exporting the image so it can be referenced in html (maybe similar to "Save File on Server" option)?

daust commented 11 months ago

Hi @DavidGhedini,

sorry for the super late response 🙈.

Do you still have this issue?

Could you please provide a simple test report (based on user_objects or dual so that I don't have to install any db objects) that I can use with a simple chart? I will include it into the demos and my testing routine for each release.

Thank you ~Dietmar.

DavidGhedini commented 11 months ago

Hi - Welcome back! Attached is a report with one field and one pie chart. select 4 as "four" from dual If I export to PDF, it works fine. If I export to HTML, the char vanishes. Best, David charts.zip

daust commented 11 months ago

Yes, I am back :). Sorry for long delay.

Well, I have tested it and cannot really reproduce the issue.

Could also be that the images are rendered by Tomcat on the fly and not accessible by the additional requests from your apex page.

When you look at page 14 of the sample application, you will see the following code:

declare
  l_proc varchar2(100) := 'show report';
  l_demo xlib_jasperreports_demos%rowtype;
BEGIN
  select *
    into l_demo
    from xlib_jasperreports_demos
   where demo_code=:p14_demo_code;

  /*
   using use_images_no_tunnel will allow you to call the images directly from the J2EE application server 
   and not through the database. Anyhow, this is secured through the java session (cookie JSESSIONID) which 
   was established by calling the J2ee server through the database via UTL_HTTP. 

   When both ORDS and JRI are running on the same J2EE server, you then can call 
       xlib_jasperreports.use_images_no_tunnel();
   in order to access the generated images from the report directly. This is a lot faster than tunneling each image. 

   Developers might face the rare case where ORDS is running on the local machine but JRI is spawned in a separate
   application server (Jetty or Tomcat) on the same machine as well but using a different port. 
   Thus, they would pass the server uri and cookie path as well: 
       xlib_jasperreports.use_images_no_tunnel(p_server_uri => 'http://localhost:8099', p_cookie_path => '/jri');
  */ 

  --xlib_jasperreports.use_images_no_tunnel();
  xlib_jasperreports.show_report (p_rep_name => apex_util.url_encode(l_demo.demo_report_name),
          p_rep_format          => apex_util.url_encode(l_demo.demo_report_format),
          p_data_source         => apex_util.url_encode(l_demo.demo_data_source),
          p_out_filename        => apex_util.url_encode(l_demo.demo_out_filename),                        
          p_rep_locale          => apex_util.url_encode(l_demo.demo_report_locale),
          p_rep_encoding        => apex_util.url_encode(l_demo.demo_report_encoding),
          p_additional_params   => '&'  || apex_util.url_encode(l_demo.demo_param1_label)
                                   ||'='|| apex_util.url_encode(l_demo.demo_param1_value)
--                                   ||'='|| utl_url.escape(l_demo.demo_param1_value,true,'UTF-8')
                                   ||'&'|| apex_util.url_encode(l_demo.demo_param2_label)
                                   ||'='|| apex_util.url_encode(l_demo.demo_param2_value)
                                   ||'&'|| apex_util.url_encode(l_demo.demo_param3_label)
                                   ||'='|| apex_util.url_encode(l_demo.demo_param3_value),
          p_rep_time_zone       => apex_util.url_encode(l_demo.demo_report_time_zone)
          );

  -- this was used before apex 4.1
  --apex_application.g_unrecoverable_error := true;
  apex_application.stop_apex_engine();

exception
  when apex_application.e_stop_apex_engine then
    null; -- ok, stop engine raises exception, we can ignore that
  when others then 
    xlog(l_proc, substr(dbms_utility.format_error_backtrace,1,3500), 'ERROR');
    raise;
end;  

You can play a bit with the use_images_no_tunnel procedure, so that the cookies can be tunneled to the Tomcat. Then the images should be shown properly.

My setup might be different from yours.

Also, are you using the most current version of JRI .. ALSO the database packages?

Good luck and let me know how it works out.

DavidGhedini commented 11 months ago

Hi Thanks for above. Yes, it's the latest issue with db packages installed. I think the issue is that PDF embeds image and HTML uses relative url. If I call as PDF from a remote server, the image is embedded in the pdf on the server and it works fine. If called via HTML from remote server, it renders with relative url (report_image?image=img_0_0_2.png below), so the image is not embedded in the html. Is there a way around this?

<img src="report_image?image=img_0_0_2.png&amp;uuid=895faf1c-9da6-4744-a324-768fb85cfe22" style="height: 200px" alt=""/></td>