Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » Inserting Background Image Problem(Background image not showing when using onCreate script.)
Inserting Background Image Problem [message #775511] Fri, 06 January 2012 01:06 Go to next message
JB . is currently offline JB .
Messages: 9
Registered: November 2011
Junior Member
I am trying to insert a background image using a script but cannot get it to work.

I have a grid on which I have attached the following onCreate script:
this.getParent().getStyle().backgroundImage = "DRAFT-Watermark.JPG";

The image does not show and there is no error in the debug window. I also had the full path included and it did not make a difference.

I am new to BIRT and especially new to the scripting part of the program so I may not be attaching this to the right area.

I am using BIRT 3.7 in Eclipse and I view the report as PDF directly from the designer.

The test report using the sample database and the image I am trying to insert is attached.

Thank you for any assistance,
JB
Re: Inserting Background Image Problem [message #775795 is a reply to message #775511] Fri, 06 January 2012 12:26 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

You need to size the grid to fit the image. I modified your example to
put your grid in another grid and moved the script to onRender. Also
make sure the image is in the resource folder or in the same directory
as the report.

See attached.

You may also want to look over these posts:
http://birtworld.blogspot.com/2010/12/birt-backgroundwatermark-images.html
http://birtworld.blogspot.com/2010/09/birt-image-report-item.html

Jason

On 1/6/2012 1:06 AM, JB . wrote:
> I am trying to insert a background image using a script but cannot get it to work.
>
> I have a grid on which I have attached the following onCreate script:
> this.getParent().getStyle().backgroundImage = "DRAFT-Watermark.JPG";
>
> The image does not show and there is no error in the debug window. I also had the full path included and it did not make a difference.
>
> I am new to BIRT and especially new to the scripting part of the program so I may not be attaching this to the right area.
>
> I am using BIRT 3.7 in Eclipse and I view the report as PDF directly from the designer.
>
> The test report using the sample database and the image I am trying to insert is attached.
>
> Thank you for any assistance,
> JB
  • Attachment: draft.zip
    (Size: 1.87KB, Downloaded 136 times)
Re: Inserting Background Image Problem [message #775820 is a reply to message #775795] Fri, 06 January 2012 13:19 Go to previous messageGo to next message
JB . is currently offline JB .
Messages: 9
Registered: November 2011
Junior Member
Thank you Jason. I can get it to work for me now.

I did not realize that I couldn't supply a path to the image.

I also did not realize that BIRT will not resize the grid to accommodate
the image.

I originally had the image as a background in a style but could not figure
out how to use a script to either add or remove the image from that style
or to change styles. What scripts do you need for that?

Thanks,
JB

On Fri, 06 Jan 2012 12:26:21 -0500, Jason Weathersby wrote:

> You need to size the grid to fit the image. I modified your example to
> put your grid in another grid and moved the script to onRender. Also
> make sure the image is in the resource folder or in the same directory
> as the report.
>
> See attached.
>
> You may also want to look over these posts:
> http://birtworld.blogspot.com/2010/12/birt-backgroundwatermark-
images.html
> http://birtworld.blogspot.com/2010/09/birt-image-report-item.html
>
> Jason
>
Re: Inserting Background Image Problem [message #775830 is a reply to message #775820] Fri, 06 January 2012 13:38 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

Styles can only be changed in the beforeFactory, so that is probably to
early if you want to changed based on data. It is not to late if you
want to change based on parameter. To drop the image from the grid you
could always use this.getStyle().backgroundImage = ""; in the onRender
script.

Jason

On 1/6/2012 1:19 PM, JB wrote:
> Thank you Jason. I can get it to work for me now.
>
> I did not realize that I couldn't supply a path to the image.
>
> I also did not realize that BIRT will not resize the grid to accommodate
> the image.
>
> I originally had the image as a background in a style but could not figure
> out how to use a script to either add or remove the image from that style
> or to change styles. What scripts do you need for that?
>
> Thanks,
> JB
>
> On Fri, 06 Jan 2012 12:26:21 -0500, Jason Weathersby wrote:
>
>> You need to size the grid to fit the image. I modified your example to
>> put your grid in another grid and moved the script to onRender. Also
>> make sure the image is in the resource folder or in the same directory
>> as the report.
>>
>> See attached.
>>
>> You may also want to look over these posts:
>> http://birtworld.blogspot.com/2010/12/birt-backgroundwatermark-
> images.html
>> http://birtworld.blogspot.com/2010/09/birt-image-report-item.html
>>
>> Jason
>>
>
Re: Inserting Background Image Problem [message #775839 is a reply to message #775830] Fri, 06 January 2012 14:01 Go to previous messageGo to next message
JB . is currently offline JB .
Messages: 9
Registered: November 2011
Junior Member
I am changing the background based on parameters so beforeFactory would
actually work. Your solution of setting the backgroundImage to "" is a
good fit for my report.

One of the things that I am struggling with in learning the scripting side
of things is the actual keywords and options for an object.

For example, what would the code be to change a background in a style?

I am spending hours every day just combing through websites and forums
looking for the small snippet of code that will work for me every time I
try to do something new. Overall though, I like the BIRT and am finding
the support very helpful.

Thanks,
JB

On Fri, 06 Jan 2012 13:38:08 -0500, Jason Weathersby wrote:

> Styles can only be changed in the beforeFactory, so that is probably to
> early if you want to changed based on data. It is not to late if you
> want to change based on parameter. To drop the image from the grid you
> could always use this.getStyle().backgroundImage = ""; in the onRender
> script.
>
> Jason
>
> On 1/6/2012 1:19 PM, JB wrote:
Re: Inserting Background Image Problem [message #775845 is a reply to message #775839] Fri, 06 January 2012 14:17 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

We have a small primer on scripting at:
http://www.eclipse.org/birt/phoenix/deploy/reportScripting.php
We need to expand this.

When you change styles in the before factory you are using the DE API
and we have a lot of examples and even a webinar on this api at
BIRT-exchange.org. Here is an example

//beforeFactory
importPackage(Packages.org.eclipse.birt.report.model.api);
importPackage(Packages.org.eclipse.birt.report.model.api.elements);

reportContext.getDesignHandle().findStyle("report").setProperty(StyleHandle.FONT_FAMILY_PROP,
"Arial");
reportContext.getDesignHandle().findStyle("report").setProperty(
StyleHandle.COLOR_PROP, "#009B9B" );
reportContext.getDesignHandle().findStyle("report").setProperty(
StyleHandle.FONT_WEIGHT_PROP, DesignChoiceConstants.FONT_WEIGHT_BOLD );
//background image
reportContext.getDesignHandle().findStyle("NewStyle").setBackgroundImage( ""
);
//or use
reportContext.getDesignHandle().findStyle("report").setProperty(
StyleHandle.BACKGROUND_IMAGE_TYPE_PROP, "" );

Jason
On 1/6/2012 2:01 PM, JB wrote:
> I am changing the background based on parameters so beforeFactory would
> actually work. Your solution of setting the backgroundImage to "" is a
> good fit for my report.
>
> One of the things that I am struggling with in learning the scripting side
> of things is the actual keywords and options for an object.
>
> For example, what would the code be to change a background in a style?
>
> I am spending hours every day just combing through websites and forums
> looking for the small snippet of code that will work for me every time I
> try to do something new. Overall though, I like the BIRT and am finding
> the support very helpful.
>
> Thanks,
> JB
>
> On Fri, 06 Jan 2012 13:38:08 -0500, Jason Weathersby wrote:
>
>> Styles can only be changed in the beforeFactory, so that is probably to
>> early if you want to changed based on data. It is not to late if you
>> want to change based on parameter. To drop the image from the grid you
>> could always use this.getStyle().backgroundImage = ""; in the onRender
>> script.
>>
>> Jason
>>
>> On 1/6/2012 1:19 PM, JB wrote:
Re: Inserting Background Image Problem [message #775850 is a reply to message #775845] Fri, 06 January 2012 14:37 Go to previous message
JB . is currently offline JB .
Messages: 9
Registered: November 2011
Junior Member
Thank you very much.
I will review these references.
JB


On Fri, 06 Jan 2012 14:17:13 -0500, Jason Weathersby wrote:

> We have a small primer on scripting at:
> http://www.eclipse.org/birt/phoenix/deploy/reportScripting.php We need
> to expand this.
>
> When you change styles in the before factory you are using the DE API
> and we have a lot of examples and even a webinar on this api at
> BIRT-exchange.org. Here is an example
>
> //beforeFactory
> importPackage(Packages.org.eclipse.birt.report.model.api);
> importPackage(Packages.org.eclipse.birt.report.model.api.elements);
>
> reportContext.getDesignHandle().findStyle("report").setProperty
(StyleHandle.FONT_FAMILY_PROP,
> "Arial");
> reportContext.getDesignHandle().findStyle("report").setProperty(
> StyleHandle.COLOR_PROP, "#009B9B" );
> reportContext.getDesignHandle().findStyle("report").setProperty(
> StyleHandle.FONT_WEIGHT_PROP, DesignChoiceConstants.FONT_WEIGHT_BOLD );
> //background image
> reportContext.getDesignHandle().findStyle("NewStyle").setBackgroundImage(
> ""
> );
> //or use
> reportContext.getDesignHandle().findStyle("report").setProperty(
> StyleHandle.BACKGROUND_IMAGE_TYPE_PROP, "" );
>
> Jason On 1/6/2012 2:01 PM, JB wrote:
Previous Topic:Graphic appears on some PCs, but not in others
Next Topic:Page numbering by master page
Goto Forum:
  


Current Time: Tue Jul 22 13:38:29 EDT 2014

Powered by FUDForum. Page generated in 0.02452 seconds