I have a .rpt file. I want to read it programatically in java and save it in pdf file. I followed the solution multithread pdf conversion My source code provided below
final String rpt = "/Users/florapc/Desktop/Report/AcStatement.rpt";
final String sFilePath = "/Users/florapc/Desktop/Report/";
final String sFileName = "pdfreport";
final Object[] data = new Object[1];
for (int i = 0; i < data.length; i++) {
// run();
Engine eng = new Engine(Engine.EXPORT_PDF);
eng.setReportFile(rpt); //rpt is the report name
System.out.println(" After set connection");
eng.setPrompt(data[i], 0);
ReportProperties repprop = eng.getReportProperties();
// repprop.setPaperOrient(ReportProperties.DEFAULT_PAPER_ORIENTATION, ReportProperties.PAPER_FANFOLD_US);
eng.execute();
System.out.println(" After excecute");
FileOutputStream fos = null;
try {
String FileName = sFileName + "_" + i;
File file = new File(sFilePath + FileName + ".pdf");
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
if (!file.exists()) {
file.createNewFile();
}
fos = new FileOutputStream(file);
for (int k = 1; k <= eng.getPageCount(); k++) {
fos.write(eng.getPageData(k));
}
fos.flush();
fos.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
fos = null;
}
}
}
After running my code I am unable to read the .rpt file and my pdf file becomes empty. Please help me out.
Finally I get a solution using iTextPdf library.
I hope it will be helpfull to all .