Modify Report after fill


i need to create two o more copy of a report  where for each copy i need to change the value of  a "label"

accordingly some rules from the final user. Currently I added a parameter to the report and i pass the desired value.

For example  i need to put only the following text: "Copy for me", "Copy for XXX YYY", ecc...

and due the great quantity of data/processing time involved during the fill i need to wait for a long time for each fill.

Is possible to change the value without re-fill the entire report?


thank for you help


estepra's picture
Joined: Jun 12 2008 - 12:18am
Last seen: 10 years 9 months ago

1 Answer:



yes it is.... we do so when numbering our copies (e.g. Copy X of Y) withour regenerating the whole printout.

So try the way we do (and this is working fine for at least 3 years) :-)

- create a textfield where you later want to insert your copytext

- set the textfield expression to " " so just a space character

- make sure that the text you'll insert later will fit into the field (make it wide enough)

- set the anchorname-expression to something like "COPYFIELD" (perhaps you can also use the element-key attribute, this should be readable also in JasperPrint-Object (when we started it wasn't, that's why the way via the HyperLinkAnchorNameExpression)

- set the "RemoveLineWhenBlank" to FALSE (important!!!)

now if you have your JasperPrint you just need to parse that object and set the text .. see my method below.




public static JasperPrint setCopyTextOnJasperPrint(JasperPrint jrPrint, 
                                                     String copyText, 
                                                     int currentCopy,
                                                     int totalCopy) throws Exception {
    if (jrPrint != null && jrPrint.getPages() != null && jrPrint.getPages().size() > 0 && copyText != null) {
      java.util.List<JRPrintPage> pageList = jrPrint.getPages();
      for (int i = 0; i < pageList.size(); i++) {
        JRPrintPage page = pageList.get(i);
        java.util.List<JRPrintElement> elemList = page.getElements();
        for (int j = 0; j < elemList.size(); j++) {
          if (elemList.get(j) instanceof JRBasePrintText) {
            JRBasePrintText elem = (JRBasePrintText) elemList.get(j);
            if ("SYSTEM_KopieFeld".equalsIgnoreCase(elem.getAnchorName())) {
            else if ("SYSTEM_KopieX".equalsIgnoreCase(elem.getAnchorName())) {
            else if ("SYSTEM_KopieY".equalsIgnoreCase(elem.getAnchorName())) {
      return jrPrint;
    else {
      throw new IllegalArgumentException("Ungültiges PrintObjekt und/oder KopieText übergeben!");
C-Box's picture
Joined: Jul 19 2006 - 5:58pm
Last seen: 1 month 6 days ago