Hitachi Vantara Pentaho Community Forums
Results 1 to 4 of 4

Thread: Image to image-field from a file

  1. #1

    Default Image to image-field from a file

    Hi all,

    I need to show a pictures of products in pentaho report (prpt file). Data source provides a path to a picture file.

    I.e.
    "product_name";"product_picture"
    "Product1";"C:\products\product1.jpg"
    "Product2";"C:\products\product2.jpg"

    Unfortunately the image-field expects a file object, so I tried to use following BSHExpression and add it to Attributes>field

    getValue() {
    File sourceimage = new File("PRODUCT_PICTURE");
    Image image = ImageIO.read(sourceimage);
    return image;
    }

    When I open the report, pictures are missing and no error is displayed. Does anybody have an idea?

    Thank you
    Magdalena

    P.S. - I have almost no knowledge of Java programming, so please be forgiving.

  2. #2
    Join Date
    Aug 2016
    Posts
    142

    Default

    I have only used a header image in my reports and it was a static image

    Is your report dynamic? I am asking because if the report is static you could probably just use the "image" type as opposed to the "image-field" type and just put in the path of the file

    In my case the image is stored on the office network in a folder where all users have access but you can embed them into the report itself when you use the "image" type

  3. #3
    Join Date
    Aug 2016
    Posts
    142

    Default

    Just thinking, if you need the image to change depending on the output of the report you could use a formula to define the path

    1. Put an image in the report (not image-field)
    2. In attributes/value select the "+" icon
    3. You could then use a formula something like this

    =IF([product_name]="Product1";"path_to_file_1";"path_to_file_2")

    If you have multiple then you can use a nested formula so something like this

    =IF([product_name]="Product1";"path_to_file_1";IF([product_name]="Product2";"path_to_file_2";IF([product_name]="Product3";"path_to_file_3"; "path_to_file_1")))

    If using this approach just be careful of a few things

    1. The formula editor will only accept it if it is in a continuous string so no line breaks or paragraphs
    2. Make sure to include a final option so in my example above if none of the conditions are satisfied it will default to file 1
    3. For closing parenthesis have as many as IF statements. In mine above I have 3 parenthesis at the end as I have 3 IF statements

    Hope that helps!
    Last edited by Deanicus; 09-06-2016 at 06:50 AM.

  4. #4

    Default

    Thank you for your ideas, it works now.

    Best regards
    Magdalena

Tags for this Thread

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.