Jump to content
We've recently updated our Privacy Statement, available here ×
  • Sample of Custom Ad Hoc Template to Display Logo - v.5.5+


    asimkin
    • Features: Ad Hoc Version: v7, v6, v5.6, v5.5 Product: JasperReports® Server

    The main purpose of this article is to provide a sample of custom ad-hoc template to display logo/image in generated ad-hoc report in JasperReports Server v.5.5 + 

    As mentioned in JasperReports Server Admin guide, JasperReports Server5.5 introduced Ad Hoc templates and report generators. Ad Hoc templates are JRXML files in the repository that define the format for reports generated from Ad Hoc views:

    http://community.jaspersoft.com/documentation/jasperreports-server-administration-guide/v550/configuring-ad-hoc#Templates_and_Generators

    Attached are 2 custom ad-hoc templates based on 'Actual Size' template (/public/templates/actual_size.510.jrxml) which shipes with JasperReports Server.

    The first custom template (logo_in_title.jrxml) displays an image from repository in report Title band. The following code added to the end of the template:

    <title>
       <band height="51">
          <image>
             <reportElement x="0" y="0" width="551" height="51"/>
             <imageExpression>
                <![CDATA["repo:/public/Samples/Resources/Images/Jaspersoft_logo.png"]]>
             </imageExpression>
          </image>
       </band>
    </title>
    

    With this template, Title band definition 'overrides' the default one and as a result, ad-hoc Title defined in ad-hoc designer is lost

    logo_in_title_template.png.b8156e085d5aa8c468f23af6679edc99.png

    If you need to display ad-hoc view title in the report, the logo can de displayed in report's pageHeader band as implemented in the second template (logo_in_pageHeader.jrxml):

    <pageHeader>
       <band height="51">
          <image>
             <reportElement x="0" y="0" width="551" height="51"/>
             <imageExpression>
                <![CDATA["repo:/public/Samples/Resources/Images/Jaspersoft_logo.png"]]>
             </imageExpression>
          </image>
       </band>
    </pageHeader>
    

    Below is the template applying result:

    logo_in_pageHeader_template.png.7b7f3b375b73c3af5a126a3c161e2c7f.png

    In order to use the custom templates, they have to be upload to JasperReports Server repository, Public > Templates folder.


    UPDATE:  in case of using Ad Hoc View with Chart, additonal steps should be done, please review the article below:

    How to Change the Default Band Used for Ad Hoc Chart Reports from 'Title' to 'Summary'?

    CS #62621

    logo_in_title_template.png.abf5ffd14f3d07c55e6ec479a6ed2b34.png

    logo_in_title.jrxml

    logo_in_pageheader.jrxml


    User Feedback

    Recommended Comments

    There are no comments to display.



    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

×
×
  • Create New...