Hitachi Vantara Pentaho Community Forums
Results 1 to 8 of 8

Thread: Page number and Footer

  1. #1
    Join Date
    Apr 2003
    Posts
    6

    Default Page number and Footer

    Hi!

    I have an application and I do not want to use any XMLs. I want to be able to display a footer like this: Page currentPage of totalNumberOfPages. Can this be done without the use of XMLs? I managed to add all the functionality I needed without using XMLs so far.
    Some sample code regarding this would be very usefull.

    Thanks a lot!

    Regards,
    Loss

  2. #2
    Join Date
    Mar 2003
    Posts
    4,947

    Default

    I too am trying to do this:

    I create a page function, then a page total function, then a text format expresison which links the two.

    If i reference the text format expression, I get a big error - ie the WHOLE thing does not display correctly...

    i basically copied the xml and translated it into api calls..

    anyone?

  3. #3
    Join Date
    Mar 2003
    Posts
    4,947

    Default

    here is some basic code

    Code:
    PageFunction pf = new PageFunction();
    pf.setName("pf");
    pf.setProperty("reportProperty", "erport.pagenumber");
    
    PageTotalFunction pt = new PageTotalFunction();
    pt.setName("pt");
    
    TextFormatExpression tf = new TextFormatExpression();
    tf.setName("tf");
    tf.setProperty("pattern","Page {X} of {Y}");
    tf.setProperty("X","pf");
    tf.setProperty("Y","pt");
    
    
    Then I add them to the functioncollection...
    
    then wehn i want to use them... I go:
    
    footer.addElement&#40;new StringElement&#40;..,..,...,etc,etc, "<null>", "tf"&#41; &#41;;

  4. #4
    Join Date
    Apr 2003
    Posts
    6

    Default Looks interesting but I must be missing something

    Hi thanks for the reply.

    I think that my problem is a little more complex or I am not doing what you said right.
    I added the functions but if I get it right then in the tablemodel there should also be a column X?

    Here is what I want to do:
    I want to dinamically display texts. on three columns. On one column there should be an index, on the second column there is the text whose height might vary and on the third column there is one picture (the same for all questions). So I do not know whether text 10 will be on page x or page x+1 or how many pages there will be while I create the report definition.
    Also while I create a report definition :
    com.jrefinery.report.TextElement textelement =
    ItemFactory.createStringElement(
    "T2",
    new java.awt.geom.Rectangle2D.Double(20D, 10.0D, 210D, 100D),
    Color.black,
    ElementAlignment.LEFT.getOldAlignment(),
    ElementAlignment.TOP.getOldAlignment(),
    fontSmall,
    "",
    "Text");
    jfreereport.getItemBand().addElement(textelement);

    is it possible to make the rectangle's height adjust as needed because there is no way of knowing how long the text will be.

    If you have an idea, any idea...

    Thanks.

  5. #5
    Join Date
    Mar 2003
    Posts
    8,085

    Default

    Hi,

    Code:
    PageFunction pf = new PageFunction&#40;&#41;;
    pf.setName&#40;"pf"&#41;;
    pf.setProperty&#40;"reportProperty", "erport.pagenumber"&#41;;
    The PageFunction does not need the "reportProperty" property, this is a leftover from previous versions.

    TextFormatExpression tf = new TextFormatExpression();
    tf.setName("tf");
    tf.setProperty("pattern","Page {X} of {Y}");
    tf.setProperty("X","pf");
    tf.setProperty("Y","pt");
    This was almost correct, just one small mistake
    The TextFormatExpression expects its values in the format {0}, {1} ... {n} and the property names for that expression have to be formed that way:

    Code:
    tf.setProperty&#40;"pattern","Page &#123;0&#125; of &#123;1&#125;"&#41;;
    tf.setProperty&#40;"0","pf"&#41;;
    tf.setProperty&#40;"1","pt"&#41;;
    This will read the values from the expressions "pf" and "pt", put them into the expression and as result you'll get the desired string.


    To your second problem:

    You don't have to care where your elements get printed, trust in JFreeReport, we place it right
    Just create the itemband with the 3 elements as usual, and then set the text element to dynamic:

    Code:
    textElement.getStyle&#40;&#41;.setStyleProperty &#40;ElementStyleSheet.Dynamic, Boolean.TRUE&#41;;
    When defining an element to be dynamic, its height get adjusted to fit the contained text. If you specify an height for the element (100 in your case), then this height is considered a minimum-height.

    Have more fun,
    said Thomas

  6. #6
    Join Date
    Apr 2003
    Posts
    6

    Default Half way there

    Great!

    The footer now works. Thank you very much Thomas.
    The dynamic issue still stands.

    I tried
    textelement2.getStyle().setStyleProperty(
    com.jrefinery.report.targets.style.ElementStyleSheet.Dynamic,
    Boolean.TRUE);

    but I do not know why there is no Dynamic value for the styleSheet. I am using jfreereport-0.8.1_02 and there is no such dynamic key. Any ideas why that is? Am I not using the good version of jfreereport? I downloaded this version from this site and I am guessing it is the latest version.

    Thank you again.
    JFreeReport is really great!

  7. #7
    Join Date
    Apr 2003
    Posts
    6

    Default Did it

    Ok. I did it.
    I downloaded the latest version 0.8.2 and now your code works. There is something with dynamic_height or something. Anyway - problem solved. Thanks again.
    Best of luck!

    Regards,
    Loss

  8. #8
    Join Date
    Mar 2003
    Posts
    8,085

    Default

    Hi,

    ah, yes. The dynamic key was located in a different class in 0.8.1 ... it then moved to the ElementStyleSheet class as this location is more logical.

    Have more fun,
    said Thomas

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.