Generate odt and rtf format problem

0

Hi , 

I made my template with i report, and i try to generate report in PDF, ODT, RTF , i use jrxml files in my java program like sources, when i generate PDF it work perfect and everything is in good place, with i export to ODT or RTF files and open it , it show everything malformed , some tables i see only half of it and many problems , 

public void PDFprint() throws IOException {
  try {   Class.forName("com.mysql.jdbc.Driver"); con = DriverManager.getConnection("jdbc:mysql://localhost:3306/pasteur_db?useSSL=false", "root", "");
   init
   Map<String, Object> map = new HashMap<String, Object>();   init(debut, fin, map);
   InputStream template = this.getClass().getClassLoader().getResourceAsStream("jasper.jrxml/MasterReport.jrxml");   JasperReport report = JasperCompileManager.compileReport(template);
 
   JasperPrint print = JasperFillManager.fillReport(report, map, con);
 
   HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();   httpServletResponse.addHeader("Content-disposition", "attachment; filename=report.pdf");   ServletOutputStream servletOutputStream = httpServletResponse.getOutputStream();   JRPdfExporter exporter = new JRPdfExporter();   exporter.setExporterInput(new SimpleExporterInput(print));   exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(servletOutputStream));  exporter.exportReport();   FacesContext.getCurrentInstance().responseComplete();
   con.close();  } catch (ClassNotFoundException | SQLException | JRException ex) {   ex.printStackTrace();  } }
 
public void RTFprint() throws IOException {  try {      Class.forName("com.mysql.jdbc.Driver");   con = DriverManager.getConnection("jdbc:mysql://localhost:3306/pasteur_db?useSSL=false", "root", "");
 
   Map<String, Object> map = new HashMap<String, Object>();   init(debut, fin, map);
   InputStream template = this.getClass().getClassLoader()     .getResourceAsStream("jasper.jrxml/MasterReport.jrxml");   JasperReport report = JasperCompileManager.compileReport(template);
 
   JasperPrint print = JasperFillManager.fillReport(report, map, con);
 
   HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext.getCurrentInstance()     .getExternalContext().getResponse();   httpServletResponse.addHeader("Content-disposition", "attachment; filename=report.rtf");   ServletOutputStream servletOutputStream = httpServletResponse.getOutputStream();   JRRtfExporter exporter = new JRRtfExporter();   exporter.setExporterInput(new SimpleExporterInput(print));   exporter.setExporterOutput(new SimpleWriterExporterOutput(servletOutputStream));   exporter.exportReport();   FacesContext.getCurrentInstance().responseComplete();
   con.close();  } catch (ClassNotFoundException | SQLException | JRException ex) {   ex.printStackTrace();  } }
 
public void ODTprint() throws IOException {  try {     Class.forName("com.mysql.jdbc.Driver");   con = DriverManager.getConnection("jdbc:mysql://localhost:3306/pasteur_db?useSSL=false", "root", "");
 
   Map<String, Object> map = new HashMap<String, Object>();   init(debut, fin, map);
     InputStream template = this.getClass().getClassLoader()     .getResourceAsStream("jasper.jrxml/MasterReport.jrxml");   JasperReport report = JasperCompileManager.compileReport(template);
 
   JasperPrint print = JasperFillManager.fillReport(report, map, con);
 
   HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext.getCurrentInstance()     .getExternalContext().getResponse();   httpServletResponse.addHeader("Content-disposition", "attachment; filename=report.odt");   ServletOutputStream servletOutputStream = httpServletResponse.getOutputStream();   JROdtExporter exporter = new JROdtExporter();   exporter.setExporterInput(new SimpleExporterInput(print));   exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(servletOutputStream));   exporter.exportReport();   FacesContext.getCurrentInstance().responseComplete();
   con.close();  } catch (ClassNotFoundException | SQLException | JRException ex) {   ex.printStackTrace();  } }
whwassim's picture
Joined: Jan 23 2017 - 2:57am
Last seen: 3 years 3 months ago

0 Answers:

No answers yet
Feedback