Sure no problem . I will go ahead and try to explain with examples
what I did and how I did it.
I basically ended up writing two objects namely ItextPdfView and
ItextPdfViewExporter. In ItextPdfView object I ended up creating two
methods namely getTableCaption that returns a Paragraph object and
render method that returns a PdfPTable object. Here is how they look.
public Paragraph getTableCaption() throws Exception {
Paragraph p = new Paragraph(this.table.getCaption(),
FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLDITALIC,
this.captionFontColor));
p.setAlignment(this.captionAlignment);
return p;
}
public PdfPTable render() {
PdfPTable table = new
PdfPTable(this.table.getRow().getColumns().size());
HtmlRow row = this.table.getRow();
List<Column> columns = row.getColumns();
// build table headers
for (Iterator<Column> iter = columns.iterator();
iter.hasNext();) {
HtmlColumn column = (HtmlColumn) iter.next();
PdfPCell cell = new PdfPCell(new
Paragraph(column.getTitle(),
FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL,
this.headerFontColor)));
cell.setPadding(3.0f);
cell.setBackgroundColor(this.headerBackgroundColor);
table.addCell(cell);
}
// build table body
Collection<?> items = coreContext.getPageItems();
int rowcount = 0;
for (Object item : items) {
rowcount++;
row = this.table.getRow();
columns = row.getColumns();
for (Iterator<Column> iter = columns.iterator();
iter.hasNext();) {
HtmlColumn column = (HtmlColumn) iter.next();
String property = column.getProperty();
Object value =
column.getCellRenderer().getCellEditor().getValue(item, property,
rowcount);
PdfPCell cell = new PdfPCell(new
Paragraph(value.toString(), FontFactory.getFont(FontFactory.HELVETICA,
12, Font.NORMAL)));
cell.setPadding(3.0f);
if ((rowcount % 2) == 0) {
// even color
cell.setBackgroundColor(this.evenCellBackgroundColor);
}
else {
// odd color
cell.setBackgroundColor(this.oddCellBackgroundColor);
}
table.addCell(cell);
}
}
// add results to the table
PdfPCell cell = new PdfPCell(new
Paragraph(snippets.statusBarText(),
FontFactory.getFont(FontFactory.HELVETICA, 12, Font.ITALIC)));
table.addCell(cell);
table.setSpacingBefore(5.0f);
return table;
}
In the getTableCaption function I just use the Jmesa table object to
get the caption, decorate it with some fonts and stick it into the
Paragraph object.
In the render method, I basically ended up using Jmesa objects to get
headers, body and the status bar information. Once I had the
information, I created PdfPCell objects and added the cell objects to
the PdfPTable object. During this process, as you can see above, the
cells were decorated with color, font, etc.
Once I had the PdfPTable object build, the ItextPdfViewExporter
basically did the following in the export method.
com.lowagie.text.Document document = new
com.lowagie.text.Document();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfWriter.getInstance(document, baos);
document.open();
document.add(((PdfView) view).getTableCaption());
document.add(((PdfView) view).render());
document.close();
this.responseHeaders(baos.toByteArray(), response);
ServletOutputStream out = response.getOutputStream();
baos.writeTo(out);
out.flush();
I obviously ended up calling the export method myself instead of using
the render method in TableFacade object. I did not think I needed to
overwrite TableFacadeImp.
Hope this helps!
On May 23, 3:11 pm, "Jeff Johnston" <
extremecompone...@gmail.com>
wrote:
> I would be interested in seeing what you did. If nothing else I could put it
> on the wiki as an example of how to customize various things in JMesa. If
> you want you can either post your code here, or send it to me at *
> extremecompone...@gmail.com.*
>
> I also would be interested in hearing about how difficult it was to figure
> out how to modify what you did. You know, things that could be documented
> better, etc...
>
> -Jeff Johnston
>