I'm trying to
use
RtfHeaderFooterGroup
here is my
code
Worksheet worksheet1 = new Worksheet();
Document document
= new Document(PageSize.A4.rotate());
//ByteArrayOutputStream ba = new ByteArrayOutputStream();
try{
FileOutputStream ba = new
FileOutputStream("C:\\edp.rtf");
RtfWriter2 pdfW =
RtfWriter2.getInstance(document, ba);
document.setHeader(worksheet1.createPageHeaderGroup());
document.open();
Table
headerTable = new Table(1);
Cell picCell = new
Cell();
picCell.setBorder(Rectangle.NO_BORDER);
picCell.add(new
Phrase("TEST",
new Font(Font.TIMES_ROMAN, 7, Font.NORMAL)));
picCell.setHorizontalAlignment(Element.ALIGN_LEFT);
headerTable.addCell(picCell, new Point(0, 0));
document.add(headerTable);
document.newPage();
document.add(headerTable);
document.close();
}catch(Exception
e){
System.out.println(e.toString());
}
}
private Table createHeader(String header) throws
Exception{
String strImagePath =
"C:\\sc_Restricted.png";
Image png =
Image.getInstance(strImagePath);
Table
headerTable = new Table(2);
Cell
picCell = new Cell();
picCell.setBorder(Rectangle.NO_BORDER);
picCell.add(new
Phrase(header +
"\t\t\t\t\t\t\t\t\t",
new Font(Font.TIMES_ROMAN, 7, Font.NORMAL)));
picCell.setHorizontalAlignment(Element.ALIGN_CENTER);
headerTable.addCell(picCell, new Point(0, 0));
picCell = new Cell();
picCell.setBorder(Rectangle.NO_BORDER);
picCell.add(png);
picCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
headerTable.addCell(picCell, new
Point(0,1));
return headerTable;
}
private RtfHeaderFooterGroup
createPageHeaderGroup() throws
Exception{
RtfHeaderFooterGroup header = new RtfHeaderFooterGroup();
header.setHeaderFooter(
new
RtfHeaderFooter(createHeader("EMPLOYEE COMPETANCY
PROFILE")),
com.lowagie.text.rtf.headerfooter.RtfHeaderFooter.DISPLAY_FIRST_PAGE);
header.setHeaderFooter(
new RtfHeaderFooter(createHeader("EMPLOYEE DEVELOPMENT
WORKSHEET")),
com.lowagie.text.rtf.headerfooter.RtfHeaderFooter.DISPLAY_LEFT_PAGES);
header.setHeaderFooter(
new RtfHeaderFooter(createHeader("EMPLOYEE DEVELOPMENT
WORKSHEET")),
com.lowagie.text.rtf.headerfooter.RtfHeaderFooter.DISPLAY_RIGHT_PAGES);
return header;
}