Here's the approach I use locally...

1.  Extend ItextTableWriter and override writeCaption.
2.  writeCaption obtains the the content of the caption tag from TableModel.
    Its content is written at the top of the document, before the table body.
    In the jsp, there's a caption meant only for use when exporting.  It contains
    simple xml marking up caption parts like title, subtitle, and date.
    For example,
        <display:caption media="pdf">
          <caption>
            <title>My Report Title</title>
            <subtitle>My Report Subtitle</subtitle>
            <date>01/01/2006</date>
          </caption>
        </display:caption>
3.  writeCaption parses the content and writes to the pdf, formatting as needed.
  /**
   * Write the table's caption to an iText document.
   * @see org.displaytag.tags.TableWriterTemplate#writeCaption(org.displaytag.model.TableModel)
   */
  protected void writeCaption(TableModel model) throws Exception {
    Document document = this.getDocument();
    String caption  = model.getCaption();
    Font font = FontFactory.getFont(FontFactory.HELVETICA, 17, Font.BOLD, new Color(0, 0, 0));
    Paragraph title    = new Paragraph(new Chunk(ExportUtil.getNodeValue(caption, "title"), font));
    title.setAlignment(Paragraph.ALIGN_CENTER);
    Paragraph subtitle = new Paragraph(ExportUtil.getNodeValue(caption, "subtitle"));
    subtitle.setAlignment(Paragraph.ALIGN_CENTER);
    Paragraph date     = new Paragraph(ExportUtil.getNodeValue(caption, "date"));
    date.setAlignment(Paragraph.ALIGN_RIGHT);
    document.add(date);
    document.add(title);
    document.add(subtitle);
  }

4.  Extend DefaultPdfExportView to create an export view that uses your
     new table writer, with the overriden writeCaption method, to do the export work.
public class MyPdfExportView extends DefaultPdfExportView {
 
  /**
   * Return an <code>ItextTableWriter</code> that writes to a PDF file.
   *
   * @param table iText representation of the table.
   * @param document iText document to which the table is written.
   */
  protected ItextTableWriter getItextTableWriter(Table table, Document document) {
    return new MyItextTableWriter(table, document);
  }
 
}

5.  Lastly, configure yor new export view, either globally or locally, to handle your pdf export.

-Jorge

Chris Newell <[EMAIL PROTECTED]> wrote:
Hello all..
 
I’m using an exportView class to handle my PDF exporting. To do so I started with a copy of the example at http://displaytag.sourceforge.net/11/displaytag/xref/org/displaytag/export/PdfView.html and have made minor changes.
 
My problem is that I want to communicate a few strings to the exportView class that isn’t in the table but will be included in the report (ie – a report title, criteria that defined the report, the date for which the data is pertinent, etc). The class will be used to produce PDFs for a number of different reports so, though I could write a custom class for each report it’s not really an effective solution.
 
Initially I saw TableProperties.setProperty(String, String) and I assumed that I was in the clear… until I wanted to get a property… there is no corresponding getProperty(String). In my next experiment I thought I could work with the table decorators – making the data I need available in there – either implicitly or by getting hold of my HttpSession and using a session variable, but despite the fact that I’m setting a decorator in the <display:table> tag of the JSP, my exportView class is passed a TableModel in which the tableDecorator property is null.
 
I would think that this had been addressed before now but I couldn’t find anything in the archives of this list. This leads me to believe I must be missing something obvious. Anyone out there kind enough to point out the obvious?
 
Thanks!
Chris
 
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642_______________________________________________
displaytag-user mailing list
displaytag-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/displaytag-user


Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail.
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
displaytag-user mailing list
displaytag-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/displaytag-user

Reply via email to