Dynamic Images

Made it back from Nashville with a pile of requests for blog entries, I'll try and cover them over the next few weeks ... top of the list of requests was how to handle dynamic images in a layout template. There are several ways to tackle this depending on where your images are going to be at runtime. The scenario is, that I have three organizations in my company and they each have their own logo; at runtime, based on the organization I am generating a report for the output should show their logo. Lets assume we have the following XML data for all of these examples:


<INVOICELIST>
 <IMG_DIR>/images</IMG_DIR>
 <IMG_SERVER>http://xdo.us.oracle.com</IMG_SERVER>
 <IMG_DIR_PATH>c:temp</IMG_DIR_PATH>
 <G_VENDOR_NAME>
  <ORG>1</ORG>
  <IMGFILE>Org1.gif</IMGFILE>
  <VENDOR_NAME>Nuts and Bolts Limited</VENDOR_NAME>
  <ADDRESS>1 El Camino Real, Redwood City, CA 94065</ADDRESS>
   <G_INVOICE_NUM>
    <SET_OF_BOOKS_ID>124</SET_OF_BOOKS_ID>
    <GL_DATE>10-NOV-04</GL_DATE>
    ...
 </G_VENDOR_NAME>
 <G_VENDOR_NAME>
  <ORG>2</ORG>
  <IMGFILE>Org2.gif</IMGFILE>
  <VENDOR_NAME>Tick Tock Clocks</VENDOR_NAME>
  ...
</INVOICELIST>


So our XML references an image directory(IMG_DIR) on our server(IMG_SERVER) and the full path to the image directory (IMG_DIR_PATH) on our server, then each invoice has the organization ID and the image name to be used. So we can tackle this one of three ways:
1. Embed the three logos into the template directly
2. Reference the images on the disk and use a dynamic image
3. Reference the images via a URL


Embedding in the template


This is the simplest method, if we have three images, one for each organization we can add them all to the template and wrap them in conditional statements to show/hide them. 

DynImg1:

The simplest method is to use three 'if' statements, you could equally use a 'choose' statement to get the same effect. See DynamicImg1.rtf template here. If you have alot of images and/or need dynamic images in multiple templates; you could put a template function either else where in the template or ina completely separate template altogether and then call it from the main templates. See DynamicImg2.rtf for an example in the zip file


Using dynamic images


We can also just add a single dummy image to the template and at runtime point to the correct image file either on the file system or via a URL. We can build the file location of the image quite easily using the XSL concat() function.  Note at runtime the incoming image will be resized (if necessary) to fit the same dimensions as the dummy image.
So in the Web tab of the image properties we have:

DynImg2:

File System: url:{concat(../IMG_DIR_PATH,'/',IMGFILE)} See DynamicImg3.rtf
URL: url:{concat(../IMG_SERVER,'/',../IMG_DIR,'/',IMGFILE)} See DynamicImg4.rtf


Notice we use '../' to get a level up from the G_VENDOR_NAME level for the root level values we need to construct the path or URL i.e. ../IMG_DIR_PATH.


If you are an E Business Suite user you can also make use of the OA_MEDIA directory. XML Publisher will resolve this value at runtime. So for an image in the OA_MEDIA directory you could use:


url:{?${OA_MEDIA}/IMGFILE?}


You can get all the examples and XML data here.
So thats dynamic images, of course you can use it for any image and you can build much more complex conditional formatting rules around the images. Have a good day ...

Comments:

Hi Justin
Check the user guide it covers how to use parameters to pass a URL reference of an image to a template.
Regards, Tim

Posted by Tim Dexter on December 07, 2006 at 08:03 AM MST #

Very useful tip here Tim, and I suspect we'll be using a combination of all of them here at some point. Thanks!

Posted by Greg Partenach on November 20, 2007 at 02:19 AM MST #

Hi all, I want to use OA_MEDIA directory. In my xml i have a tag IMAGE which will give the image name available in OA_MEDIA directory. and in rtf i am inserting a dummy image. And writing the following syntex in web section: url:('${OA_MEDIA}','/',IMAGE) But now also i am not getting image in the PDF Output. But if i give complete path in my xml file under IMAGE tag and in rtf i write url:(IMAGE) i am getting images. Please can anybody help me in this case. It would be better if provide me one sample rdf and rtf with OA_MEDIA directory example. Thanks Abhishek paliwal

Posted by abhishek paliwal on August 21, 2008 at 10:43 PM MDT #

Abhishek This is better asked on the Publisher forum on OTN

Posted by Tim on August 22, 2008 at 02:35 AM MDT #

Hi, I want to include a .svg-picture from a xml-source, the xml tag is: <Q14_ADRESSE> http://server/picture.svg?par_1=51859&par2=&par3=1&par4=1&par5=407749 </Q14_ADRESSE> so I have many different pictures generated from another programm and I have only this tag. I woud prefer to do this with MSword, so I need a funktion. Another problem is, that MSword can't do .svg ... so I'm in trouble can someone help me? thanks

Posted by Tommy on March 30, 2009 at 07:00 PM MDT #

Hi all, Before I start, many thanks for your deserving tutorial about dynamic image. I am very new on Xml Publisher and for a week, I have tried adding dynamic image in my reports. According to your statement that means Reference the images via a URL. I have created a XML element and put my image location in that tags, after that I've created an dummy image in my rtf file and changed this web alternative text properties according to format you mention above and also I have give full path in only one xml element but unfortunately the image doesnt appear im my output file.But when I ve used first method "Embedding image in the template", the image appears. Also I ve tried your examples data but the image again doesnt appears if I used Reference the images via a URL technique. Can you or anyone help me ? thank

Posted by Guney on May 07, 2009 at 05:36 PM MDT #

Hi, The article is great but i just had to sturggle in MS Word 2007 to find the format picture/Alignment text. Here is the navigation for MS-Word 2007 On The Insert Tab Click on Picture Insert any dummy picture Right Click on the picture and select Size (NOT Format Picture). Select Alt Text and enter the info as mentioned in the Format Picture Dialog above in the blog Thanks Charandeep Hora

Posted by Charandeep Hora on January 13, 2010 at 07:36 AM MST #

Tim I was wondering if there are any special tags that have to be defined in the XSD file to make the dynamic images work correctly. I have a set up much like yours however, when I attempt to pull in a different image I only get the the first image in the program no matter how I define the location and picture name. Also, the header on your report changes based on the ORG that is entered however you never appear to tell it to be part of the for loops. How is this being accomplished?

Posted by Brent on January 29, 2010 at 05:42 AM MST #

Hi Brent Can you mail me the data and data? Tim

Posted by Tim dexter on January 29, 2010 at 06:18 AM MST #

Hi All, Is there a way to specify the size of the image dynamically? To explain in detail, suppose I have an image to be placed in my report and it is a dynamic one. I use "url:{ROOT\IMAGE}" command in the web tab of the image properties to use the url I pass in the XML file to render the image. Now, let's say the dummy image I placed on the rtf template is of size 50X50 and the actual image that is coming from the URL is of size 100X150. The image gets distorted. Is there a way to pass the height and width in the XML along with the image url? I am looking for a way to specify my xml in such a way that http://mysystem/image.jpg 100 150 and use these parameters in the rtf template so that my image rendered from the url is displayed in its actual size i.e. 100X150 rather than the dummy image's size 50X50 which would look distorted. Thanks in advance for your help! Sajith

Posted by Sajith on February 16, 2010 at 11:37 PM MST #

I am using WORD 2007 with BI Publisher and trying to create a chart in the RTF document. I added a dummy image using Insert Picture -> Link to File, Right click on the picture and select size and then alt text to add the code for the chart but I only get the picture in the image. I have a very simple XML data file for this. I am also trying to use the CHART object Bi Publisher in word but the Preview and Ok button are always disabled. I am using the same XML dat file. Any ideas? Thanks for any help. Beena

Posted by Beena on March 24, 2010 at 03:55 PM MDT #

Thank you so much for giving these many options. It really worked for me.

Posted by Siva Kumar on June 29, 2010 at 01:15 AM MDT #

information at its best

Posted by tomas on August 06, 2010 at 10:39 AM MDT #

Thanks for this post

Posted by kläder on August 18, 2010 at 05:18 AM MDT #

What's up with your header masking the navigation menu? Shouldn't it be towards the top?

Posted by missoula dentist on September 21, 2010 at 06:16 PM MDT #

There'll invariably be someone doing some thing exclusively for the surprise worth of it. Gal Gaga claims she would not want to affront vegetarians and that she wasn’t a joint of beef.....in fact what was the woman's idea?....what will we have now experienced with the assertion this girl was trying to make? I will explain to you..zero. All many of us do not forget is the "meat" dress costume. Ask yourself how long the lady stays up nights thinking up tricks to keep us discussing her.

Posted by Barbara Bach on September 24, 2010 at 11:50 PM MDT #

Hi Tim,

I'm very new to XML. Your tutorial gave me a fair idea on how to implement dynamic images. But unfortunately, I'm not able to access the example files at http://blogs.oracle.com/leslieStuddard/resource/gems/DynImages.zip Could you please mail me a sample RTF.

Thanks and Regards,
Archana

Posted by archana on March 07, 2012 at 05:11 AM MST #

HI Tim,

Thanks for your detailed info, I am not able to download the sample files form the above. could you please send the zip files to my email mleninbabu@gmail.com

Thanks,
Lenin

Posted by Lenin on April 19, 2012 at 03:53 AM MDT #

I have updated the link, should be OK now

https://blogs.oracle.com/xmlpublisher/resource/files/DynImages.zip

Tim

Posted by Tim on April 20, 2012 at 06:24 AM MDT #

Hi Richard
Sorry, but I do not have access to Word 2010 so I can not test. 2010 is a supported app so please log an SR with Oracel support for some help
Tim

Posted by Tim on March 05, 2013 at 09:24 AM MST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Follow bipublisher on Twitter Find Us on Facebook BI Publisher Youtube ChannelDiscussion Forum

Join our BI Publisher community to get the most and keep updated with the latest news, How-to, Solutions! Share your feedback and let us hear your voice @bipublisher on Twitter, on our official Facebook page, and Youtube!

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today