Hitachi Vantara Pentaho Community Forums
Results 1 to 4 of 4

Thread: How to create watermark backgroud in Java

  1. #1
    Join Date
    Dec 2007
    Posts
    3

    Question How to create watermark backgroud in Java

    Dear,
    I would like to create a background watermark image on my report through java without using XML, however I couldn't get it to show on my background. Here is my code:

    Code:
    Watermark watermark = report.getWatermark();
    StaticImageElementFactory img1 = new StaticImageElementFactory();
    try {
       DefaultImageReference dir = new DefaultImageReference(getClass().getResource("earth.png"));
        img1.setImageContainer(dir);
    } catch (Exception e) {
        e.printStackTrace();
    }
    
    img1.setPreferredSize(new FloatDimension(500, 500));
    img1.setAbsolutePosition(new Point2D.Float(0, 0));
    img1.setScale(Boolean.TRUE);
    watermark.addElement(img1.createElement());
    Using following XML code, works perfect, but I really want to it in pure Java.
    Code:
      <watermark name="watermark-area">
        <imageref name="watermark-image" x="10%" y="10%" width="80%" height="80%" src="earth.png" keepAspectRatio="true" scale="true"/>
      </watermark>
    And using following code, I am able to see my watermark text as well.
    Code:
    LabelElementFactory labelFactory = new LabelElementFactory();
    labelFactory.setText("Test watermark display");
    labelFactory.setMinimumSize(new FloatDimension(100, 100));
    labelFactory.setHorizontalAlignment(ElementAlignment.LEFT);
    labelFactory.setVerticalAlignment(ElementAlignment.MIDDLE);
    watermark.addElement(labelFactory.createElement());
    Does anyone know where I did wrong in Java way? Why only the image not able to show? Do I need to setup something? This stops me for a day already. Any help is highly appreciated.

    kind regards,
    Qian

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

    Default

    Set the MinimumSize for your Image-Element and it will appear.

    The preferred and maximum-dimension settings only have a sensible meaning for dynamic elements. The holy grail of backward compatibility forced us to apply a couple of strange .. hacks .. inside the engine to make sure that these properties behave exactly as buggy as in the original versions. If we would behave strictly as defined, a lot of existing (ill-defined) reports would break.
    Get the latest news and tips and tricks for Pentaho Reporting at the Pentaho Reporting Blog.

  3. #3
    Join Date
    Dec 2007
    Posts
    3

    Thumbs up

    Thanks a lot. It works now perfect now. Didn't think the reason is something like that.

    Do you know if we can set percentage value with setMinimumSize function in java?

    e.g.
    Code:
     <imageref name="watermark-image" x="10%" y="10%" width="80%" height="80%" src="earth.png" keepAspectRatio="true" scale="true"/>

  4. #4
    Join Date
    Dec 2007
    Posts
    3

    Default

    Code:
    setMinimumSize(new FloatDimension(-50.0f, -50.0f) );
    will set the size as percentage, e.g. 50%

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.