How to print ADF Gantt Chart
1- : download oracle bi publisher add-on for MS word and install it
2- copy these libraries from the lib folder and add it to your project
3- bind the Gantt chart to a managed bean attribute
4- create an actionListener for the Gantt chart
4- Write this code
public void vacationPlanAllEmp(GanttActionEvent evt) {
ServletOutputStream _sos = null;
java.util.Date startDate = new java.util.Date();
java.util.Date endDate = new java.util.Date();
Calendar c = Calendar.getInstance();
c.setTime(endDate);
c.add(Calendar.DATE, 365);
endDate = c.getTime();
if (GanttActionEvent.PRINT == evt.getActionType()) {
FacesContext _context = FacesContext.getCurrentInstance();
ServletResponse _response = (ServletResponse)
_context.getExternalContext().getResponse();
_response.setContentType("application/pdf;charset=windows-1256");
//_response.setContentType("application/msword");
try {
_sos = _response.getOutputStream();
} catch (IOException e) {
e.printStackTrace();
}
GanttPrinter _printer = new GanttPrinter(this.allGrantt);
_printer.setColumnVisible(0, false);
_printer.setColumnVisible(1, false);
_printer.setColumnVisible(2, false);
_printer.setColumnVisible(3, false);
_printer.setStartTime(startDate);
_printer.setEndTime(endDate);
_printer.setMargin(10,10,30,30);
_printer.setPageSize(900, 1400);
File _file = null;;
OutputStream _out =null;
try {
_file = File.createTempFile("vacationPlan", "tarek",new File("c:\\temp"));
_out = new FileOutputStream(_file);
_printer.print(_out);
FOProcessor _processor = new FOProcessor();
InputStream is = new FileInputStream(_file);
_processor.setData(is);
_processor.setOutputFormat(FOProcessor.FORMAT_PDF);
// _processor.setOutputFormat(FOProcessor.FORMAT_DOCX);
_processor.setOutput(_sos);
_processor.generate();
_context.responseComplete();
} catch (IOException e) {
e.printStackTrace();
} catch (XDOException e) {
e.printStackTrace();
} finally{
try {
_out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
2- copy these libraries from the lib folder and add it to your project
3- bind the Gantt chart to a managed bean attribute
4- create an actionListener for the Gantt chart
4- Write this code
public void vacationPlanAllEmp(GanttActionEvent evt) {
ServletOutputStream _sos = null;
java.util.Date startDate = new java.util.Date();
java.util.Date endDate = new java.util.Date();
Calendar c = Calendar.getInstance();
c.setTime(endDate);
c.add(Calendar.DATE, 365);
endDate = c.getTime();
if (GanttActionEvent.PRINT == evt.getActionType()) {
FacesContext _context = FacesContext.getCurrentInstance();
ServletResponse _response = (ServletResponse)
_context.getExternalContext().getResponse();
_response.setContentType("application/pdf;charset=windows-1256");
//_response.setContentType("application/msword");
try {
_sos = _response.getOutputStream();
} catch (IOException e) {
e.printStackTrace();
}
GanttPrinter _printer = new GanttPrinter(this.allGrantt);
_printer.setColumnVisible(0, false);
_printer.setColumnVisible(1, false);
_printer.setColumnVisible(2, false);
_printer.setColumnVisible(3, false);
_printer.setStartTime(startDate);
_printer.setEndTime(endDate);
_printer.setMargin(10,10,30,30);
_printer.setPageSize(900, 1400);
File _file = null;;
OutputStream _out =null;
try {
_file = File.createTempFile("vacationPlan", "tarek",new File("c:\\temp"));
_out = new FileOutputStream(_file);
_printer.print(_out);
FOProcessor _processor = new FOProcessor();
InputStream is = new FileInputStream(_file);
_processor.setData(is);
_processor.setOutputFormat(FOProcessor.FORMAT_PDF);
// _processor.setOutputFormat(FOProcessor.FORMAT_DOCX);
_processor.setOutput(_sos);
_processor.generate();
_context.responseComplete();
} catch (IOException e) {
e.printStackTrace();
} catch (XDOException e) {
e.printStackTrace();
} finally{
try {
_out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Comments