0

I need to get base64 result in Jasperreport. Its working for me. For this i am using 2 steps.

  1. Save pdf in disc.
  2. Get base64 from saved pdf.

My problem is i want get the base64 result without write in desc.(need to skip step1 from the above).

This is my code

JasperReport jasperReport = JasperCompileManager.compileReport("D://PremWorkSpace/PdfCreation/myreport.jrxml");
HashMap reportMap = new HashMap<String, Object>();
reportMap.put("name", "Premkumar Manipillai");
JRDataSource dataSource = new JREmptyDataSource();

JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, reportMap, dataSource);

File outDir = new File("D:/PremWorkSpace/PdfCreation/");
outDir.mkdirs();
JasperExportManager.exportReportToPdfFile(jasperPrint, "D:/PremWorkSpace/PdfCreation/" + "Topup_Nach.pdf");
System.out.println("Report Saved!");

String base64ImageString = encoder("D:/PremWorkSpace/PdfCreation/" + "Topup_Nach.pdf");
m.v.n.kalyani
  • 760
  • 7
  • 20
  • With help of *OutputStreamExporterOutput* you can configure output you want. You should use [*JRExporter*](http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/JRExporter.html) from JR API. There are tons of sample at SO and at other sites. For example you can check this post: [JasperReports 5.6: JRXlsExporter.setParameter is deprecated](https://stackoverflow.com/q/24117878/876298) – Alex K Aug 04 '18 at 09:32
  • Use the answers for the general "writing to outputstream" question, but wrap your outputstream in a Base64-outputstream like -for example- the the one in apache commons https://commons.apache.org/proper/commons-codec/apidocs/org/apache/commons/codec/binary/Base64OutputStream.html#Base64OutputStream-java.io.OutputStream- – pakopa Oct 17 '18 at 13:59

0 Answers0