Skip to main content

Post 5: iReport: Inserting a company logo in the title of your report



Inserting a company logo in the title of your report
JasperReports allows you to place your company logo anywhere in your report. You may even use your logo as a background image or a watermark in a report.

This post shows you how you can place, position, and size your company logo within the title of a business report.

How to do it...
1. Create the ASimpleTitleWithLogo.jrxml file as the Designer tab of iReport shows an empty report with a title (iTwine Technologies) as shown in the following screenshot:


2. Use the palette of components available on the right of your iReport main window to drag an Image component into the Title section of your report. 
Now you can browse to your image file that contains your company logo. JasperReports supports the rendering of all popular image formats such as JPG, GIF, BMP, PNG, and so on. 

3. Once you have selected the image file, click on Open. Your image will be placed in the Title section of your report, as follows:

4. The logo shown here does not fit and looks a bit too big or small . You need to adjust the size of the image. Click on the logo; its properties will appear in the Properties window just below the Palette of components. Look for the Width property and change its value to 180. Similarly, look for the height property and change it to 80. 

Now it looks quite normal, but still its placement in the Title section looks inappropriate, as shown in the following screenshot:

 5. Click on the logo and then use the mouse or arrow keys to place it in the top-right corner of the Title section, as shown in the following screenshot:
6. Switch to the Preview tab; you will see the preview of your report as shown here:

How it works...
Switch to the XML tab and you will see the following JRXML code:

1:  <?xml version="1.0" encoding="UTF-8"?>  
2:  <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="ASimpleTitleWithLogo" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="6ce0ff76-e37a-410f-8a2c-7c91aedf3dc5">  
3:       <property name="ireport.zoom" value="1.0"/>  
4:       <property name="ireport.x" value="0"/>  
5:       <property name="ireport.y" value="0"/>  
6:       <background>  
7:            <band splitType="Stretch"/>  
8:       </background>  
9:       <title>  
10:            <band height="89" splitType="Stretch">  
11:                 <staticText>  
12:                      <reportElement uuid="653401f7-e727-457c-a191-10332e94034d" x="0" y="19" width="373" height="34"/>  
13:                      <textElement>  
14:                           <font fontName="Verdana" size="24"/>  
15:                      </textElement>  
16:                      <text><![CDATA[iTwine Technologies]]></text>  
17:                 </staticText>  
18:                 <staticText>  
19:                      <reportElement uuid="35f19b2c-b8d1-4a52-af9f-7710c6146ece" x="0" y="56" width="207" height="20"/>  
20:                      <textElement>  
21:                           <font fontName="Verdana" size="13"/>  
22:                      </textElement>  
23:                      <text><![CDATA[Because Resources are Finite!]]></text>  
24:                 </staticText>  
25:                 <image>  
26:                      <reportElement uuid="41135236-92a2-432d-98e2-553d71354715" x="375" y="9" width="180" height="80"/>  
27:                      <imageExpression><![CDATA["C:\\Documents and Settings\\Revan\\Desktop\\iTwine Technogis Logo.jpeg"]]></imageExpression>  
28:                 </image>  
29:            </band>  
30:       </title>  
31:       <pageHeader>  
32:            <band height="35" splitType="Stretch"/>  
33:       </pageHeader>  
34:       <columnHeader>  
35:            <band height="61" splitType="Stretch"/>  
36:       </columnHeader>  
37:       <detail>  
38:            <band height="125" splitType="Stretch"/>  
39:       </detail>  
40:       <columnFooter>  
41:            <band height="45" splitType="Stretch"/>  
42:       </columnFooter>  
43:       <pageFooter>  
44:            <band height="54" splitType="Stretch"/>  
45:       </pageFooter>  
46:       <summary>  
47:            <band height="42" splitType="Stretch"/>  
48:       </summary>  
49:  </jasperReport>

Notice the <image> tag, shown highlighted in the preceding code. This <image> tag represents the logo you inserted into the Title section.
The <image> tag has a child named <imageExpression>, which specifies the <image> that you want to insert. The <imageExpression> tag provides two important bits of information:
The class attribute of the <imageExpression> tag specifies what type of image you want to use. In this case, you just want to provide the URL of the image. So it is a Java string. Another possibility can be that you want to pass a Java file object to JasperReports. In that case, the value of the class attribute will be java.io.File. The content of the <imageExpression> tag specifies the actual URL.


Note:Add images to source folders and check the images with code.
Also, try to avoid spaces in image filenames.

 

Comments

Popular posts from this blog

TIME TABLE: VTU BE/B.Tech June/July 2016 Exam Time table Draft Layout

Semester-wise June-July 2016 Exam time table (Draft Layout) Are You Using updated Kwikstudy App?

Walkins Bangalore: 01st-Oct-2016

1. UTC Aerospace : GET – S&IS-Software Team hiring Electronics & CSE / IT Freshers ! Walkin on 1st OCT | BE/BTECH - 2015 & 2016 both batch can try Selection Process : Written Test Group Discussion Technical & HR Interviews How To Apply : It is a walk-in drive for 2016 batch eligible freshers on 1 Oct 2016 at Bangalore location. Interested and eligible candidates can walk-in to the following venue on 1 Oct 2016 Date of Drive : 01 Oct 2016 Reporting Time : 8:00 AM to 11:30 AM Venue : UTC Aerospace Systems – Site 1, Sy. Nos. 14/1 & 15/1, Maruthi Industrial State, Phase 2, Hoody Village, Whitefield Road, K R Puram Hobli, Bangalore – 560048 ______________________________________ 2. HP : Software Eng/ Software Tester (Call based ,less chance of getting entry , try at your own risk) Event Date : 1-October-2016 Event Time : 8 : 00 am Job Location : Bangalore / Chennai Job Description: Software Engineer /

How to get VTU Provisional Degree Certificate (PDC) ?

Here is the procedure to get the Provisional Degree Certificate from the VTU by passed out candidates. You can get the certificate through post by sending the required documents to VTU. Documents and things required: 1. Provisional Degree Certificate (PDC) application form 2. DD of specified fees amount or print copy of receipt if you paid the fees online 3. A letter to the VTU registrar 4. A4 size envelope Step 1: Fill the PDC application You can download the PDC application form from the VTU website. Click below link for application download. PDC application form download     After downloading the application take a print of it and properly fill the form. Step 2: Make a DD of specified amount as the fees of PDC: Go to the bank and make the DD of prescribed fee amount for the PDC. The fee amount is specified in the above link from where you downloaded the application. Make the DD in favor of " Finance Officer, VTU Belgaum ".   Wr