all,
I'm having issues when editing my Jasper report in Jaspersoft Studio, the following exception is shown.
Could not initialize class
com.jaspersoft.studio.preferences.fonts.utils.FontUtils
In order to cause the error all I have to do is try to edit any text field or static text.
Below is my report and the fonts.xml in the project's fonts.jar file. The font I'm trying to use is Roboto and is included in the preference section of JasperSoft and I have include al ttf necessary.
This happens on all reports on the project, here a sample.
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.12.2.final using JasperReports Library version 6.12.2-75c5e90a222ab406e416cbf590a5397028a52de3 -->
<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="Charges" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="98e6c42b-ce3b-4d93-b73d-e17368a5f94a">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="DataAdapterDummyJSON.xml"/>
<queryString language="jsonql">
<![CDATA[data.charges]]>
</queryString>
<field name="chargeName" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="chargeName"/>
<property name="net.sf.jasperreports.json.field.expression" value="chargeName"/>
<fieldDescription><![CDATA[chargeName]]></fieldDescription>
</field>
<field name="chargeAmount" class="java.math.BigDecimal">
<property name="net.sf.jasperreports.jsonql.field.expression" value="chargeAmount"/>
<property name="net.sf.jasperreports.json.field.expression" value="chargeAmount"/>
<fieldDescription><![CDATA[chargeAmount]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<detail>
<band height="24">
<textField>
<reportElement x="70" y="0" width="174" height="20" uuid="0b113029-609b-42fc-8269-384d8af6921d">
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font fontName="Roboto" size="15"/>
</textElement>
<textFieldExpression><![CDATA[$F{chargeName}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="310" y="2" width="132" height="20" uuid="78b92d3d-4a53-4976-a8e8-e0dab507ce6a">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font fontName="Roboto" size="15" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["$"+ new DecimalFormat("0.00").format($F{chargeAmount})]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
Project's fonts.jar
<?xml version="1.0" encoding="UTF-8"?>
<fontFamilies>
<fontFamily name="DejaVu Sans">
<normal>net/sf/jasperreports/fonts/dejavu/DejaVuSans.ttf</normal>
<bold>net/sf/jasperreports/fonts/dejavu/DejaVuSans-Bold.ttf</bold>
<italic>net/sf/jasperreports/fonts/dejavu/DejaVuSans-Oblique.ttf</italic>
<boldItalic>net/sf/jasperreports/fonts/dejavu/DejaVuSans-BoldOblique.ttf</boldItalic>
<pdfEncoding>Identity-H</pdfEncoding>
<pdfEmbedded>true</pdfEmbedded>
<exportFonts>
<export key="net.sf.jasperreports.html">'DejaVu Sans', Arial, Helvetica, sans-serif</export>
</exportFonts>
<!--
<locales>
<locale>en_US</locale>
<locale>de_DE</locale>
</locales>
-->
</fontFamily>
<fontFamily name="DejaVu Serif">
<normal>net/sf/jasperreports/fonts/dejavu/DejaVuSerif.ttf</normal>
<bold>net/sf/jasperreports/fonts/dejavu/DejaVuSerif-Bold.ttf</bold>
<italic>net/sf/jasperreports/fonts/dejavu/DejaVuSerif-Italic.ttf</italic>
<boldItalic>net/sf/jasperreports/fonts/dejavu/DejaVuSerif-BoldItalic.ttf</boldItalic>
<pdfEncoding>Identity-H</pdfEncoding>
<pdfEmbedded>true</pdfEmbedded>
<exportFonts>
<export key="net.sf.jasperreports.html">'DejaVu Serif', 'Times New Roman', Times, serif</export>
</exportFonts>
</fontFamily>
<fontFamily name="DejaVu Sans Mono">
<normal>net/sf/jasperreports/fonts/dejavu/DejaVuSansMono.ttf</normal>
<bold>net/sf/jasperreports/fonts/dejavu/DejaVuSansMono-Bold.ttf</bold>
<italic>net/sf/jasperreports/fonts/dejavu/DejaVuSansMono-Oblique.ttf</italic>
<boldItalic>net/sf/jasperreports/fonts/dejavu/DejaVuSansMono-BoldOblique.ttf</boldItalic>
<pdfEncoding>Identity-H</pdfEncoding>
<pdfEmbedded>true</pdfEmbedded>
<exportFonts>
<export key="net.sf.jasperreports.html">'DejaVu Sans Mono', 'Courier New', Courier, monospace</export>
</exportFonts>
</fontFamily>
<!--
Mapping Java logical fonts, for the sake of HTML export only.
-->
<fontFamily name="SansSerif">
<exportFonts>
<export key="net.sf.jasperreports.html">'DejaVu Sans', Arial, Helvetica, sans-serif</export>
</exportFonts>
</fontFamily>
<fontFamily name="Serif">
<exportFonts>
<export key="net.sf.jasperreports.html">'DejaVu Serif', 'Times New Roman', Times, serif</export>
</exportFonts>
</fontFamily>
<fontFamily name="Monospaced">
<exportFonts>
<export key="net.sf.jasperreports.html">'DejaVu Sans Mono', 'Courier New', Courier, monospace</export>
</exportFonts>
</fontFamily>
</fontFamilies>
Error is occurred due to non available Font.
Studio giving me same error. Problem got solved.
I have never get this while working on ireport 5.0 or ireport 5.6 may be because java version which i am using or already some where font path is already configured.
jasper studio windows -> preference -> Jaspser studio -> fonts
Here add the path of fonts i have given "C:/windwos"
or you can also try this below option some will work for you
1. Switched from Open JDK to Sun JDK
2. Installed MS Core Fonts
3. Packaged JasperReport font library jar with the application
Main cause of problem is occurring due to font
Related
I have a two models Customer and Order as follow:
class Customer{
private String customerName;
private List<Order> orders;
}
class Order{
private String orderName;
}
I am creating a pdf that lists all the customer name vertically and its corresponding orders horizontally which look like below:
customer1 order1 order2
customer2 order3 order4
.
.
.
where order1 and order2 belong to customer1 and order3 and order4 belong to customer2.
What I did is for each customer object, i will print the customer name and pass the orders list to another subreport and inside this subreport, i will print all of the element in this orders list but horizontally instead of vertically.
Here is my jrxml code:
My main report:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.0 -->
<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="epicsReport" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="98e422a6-47f1-4bf1-9436-b6cbfdc8c904">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<parameter name="ordersSubReport" class="net.sf.jasperreports.engine.JasperReport"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="customerName" class="java.lang.String"/>
<field name="orders" class="java.util.List"/>
<background>
<band splitType="Stretch"/>
</background>
<detail>
<band height="25" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="270" height="25" uuid="26bf39b4-9072-4edc-a846-3141bff7da16">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="8d2c2571-e603-4eba-8048-3053e3282a99"/>
</reportElement>
<textFieldExpression><![CDATA[$F{customerName}]]></textFieldExpression>
</textField>
<subreport>
<reportElement x="312" y="0" width="200" height="25" uuid="b2675578-87cc-4a7b-8b5a-2c8af0fbde73"/>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{orders})]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{ordersSubReport}]]></subreportExpression>
</subreport>
</band>
</detail>
</jasperReport>
My subreport:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.0 -->
<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="skillsDataReport" columnCount="10" printOrder="Horizontal" pageWidth="595" pageHeight="842" columnWidth="55" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="c6d95fd0-d8af-4727-999c-9804a17721e4">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<property name="com.jaspersoft.studio.unit." value="pixel"/>
<property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="orderName" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<detail>
<band height="25" splitType="Stretch">
<textField>
<reportElement x="9" y="0" width="100" height="25" uuid="1ac7d520-9918-4106-b4ad-1b446da6a01f"/>
<textFieldExpression><![CDATA[$F{orderName}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
As data source for main report I pass a list of customers to it: new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{customers})
And as data source for my subreport, for each customer object I pass a list of orders to it: new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{orders})
The codes were compiled successfully but the orders list were not shown as I expected. I see only the list of customerName are printed but not the orders list.
What did I do wrong here? Any help will be a big glue for me :)
I am trying to do something really simple yet after searching for the past few days I could not find an answer, I need some help on this one.
What I am trying to do:
I have multiple reports so A4 portrait some landscape, some with just static text some with tables, some with tables and variables and I want to put merge them together.
They work 100% individually.
Tried to make a master report with subreports did not work, tried the book approach did not work, I always get Document is empty, or if I try to manipulate the data query I get all kind of weird stuff.
Now I will try to make this example as simple as possible.
JSON data: (New data Adapter)
{
"name": "Sample Name",
"people":[
{
"who": "Person 1"
},
{
"who": "Person 2"
},
{
"who": "Person 3"
}
]
}
Book master report:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.0 -->
<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="Empty_Book" pageWidth="595" pageHeight="842" sectionType="Part" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="30" bottomMargin="30" uuid="d2716064-8ae4-40cf-a575-33afba400e3a">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="New Data Adapter "/>
<property name="net.sf.jasperreports.print.create.bookmarks" value="true"/>
<queryString language="json">
<![CDATA[]]>
</queryString>
<detail>
<part uuid="69d6ca13-26f6-425f-bff9-395c5b9c183b">
<p:subreportPart xmlns:p="http://jasperreports.sourceforge.net/jasperreports/parts" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/parts http://jasperreports.sourceforge.net/xsd/parts.xsd">
<subreportParameter name="REPORT_CONNECTION">
<subreportParameterExpression><![CDATA[$P{REPORT_CONNECTION}]]></subreportParameterExpression>
</subreportParameter>
<subreportExpression><![CDATA["Blank_A4_2.jasper"]]></subreportExpression>
</p:subreportPart>
</part>
<part uuid="055c9f89-88b4-4270-b6ef-addb2eac3e56">
<p:subreportPart xmlns:p="http://jasperreports.sourceforge.net/jasperreports/parts" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/parts http://jasperreports.sourceforge.net/xsd/parts.xsd">
<subreportParameter name="REPORT_CONNECTION">
<subreportParameterExpression><![CDATA[$P{REPORT_CONNECTION}]]></subreportParameterExpression>
</subreportParameter>
<subreportExpression><![CDATA["Blank_A4_Landscape_1.jasper"]]></subreportExpression>
</p:subreportPart>
</part>
</detail>
</jasperReport>
Blank_A4_2.jrxml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.0 -->
<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="Blank_A4_2" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="bd2bd70c-5a0d-4c3f-b81d-4d5d7731153d">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="New Data Adapter "/>
<queryString language="json">
<![CDATA[]]>
</queryString>
<field name="name" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="name"/>
<fieldDescription><![CDATA[name]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<detail>
<band height="125" splitType="Stretch">
<textField>
<reportElement x="150" y="30" width="100" height="30" uuid="eef5f1dc-3d96-4008-8321-ef0be92d42d4"/>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="50" y="30" width="100" height="30" uuid="cbe6173f-5399-45ec-926b-ff6f48b4fb0c"/>
<text><![CDATA[name]]></text>
</staticText>
</band>
</detail>
</jasperReport>
Blank_A4_Landscape_1.jrxml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.0 -->
<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="Blank_A4_Landscape_1" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="62f06d09-42b5-4471-baa5-5aed60cc5fc4">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="New Data Adapter "/>
<subDataset name="Dataset1" uuid="eb54ec0d-0c60-44af-8476-e44f40560dee">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="New Data Adapter "/>
<queryString language="json">
<![CDATA[people]]>
</queryString>
<field name="who" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="who"/>
<fieldDescription><![CDATA[who]]></fieldDescription>
</field>
</subDataset>
<queryString language="JSON">
<![CDATA[]]>
</queryString>
<field name="name" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="name"/>
<fieldDescription><![CDATA[name]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<columnHeader>
<band height="175">
<textField>
<reportElement x="132" y="81" width="100" height="30" uuid="5cce1f44-2a8b-42ad-a03d-4c294f02d31c"/>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
</band>
</columnHeader>
<detail>
<band height="140" splitType="Stretch">
<componentElement>
<reportElement x="110" y="45" width="200" height="40" uuid="75a06812-f9a0-4b0f-9a08-efec60d0b555"/>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="Dataset1" uuid="acd62160-c07c-4c00-b6b4-9ef001d1585d">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("people")]]></dataSourceExpression>
</datasetRun>
<jr:column width="200" uuid="253a610c-a780-4690-8cce-8a03597ef016">
<jr:detailCell height="30">
<textField>
<reportElement x="0" y="0" width="200" height="30" uuid="910a7e24-c02b-4b21-8c9d-6a3dfda21794"/>
<textFieldExpression><![CDATA[$F{who}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>
</jasperReport>
Tested all files before posting, individually they work, I have no params to send to the subreports, I tried looping over the array and still nothing I always get document is Empty no matter what I do.
Passing the REPORT_CONNECTION to each subreport part has no effect. It's value will be non-null for JDBC connections only. So there's no reason to pass it.
You could have your setup running by tying each subreport to the Data Adapter file:
Export the Data Adapter to a file, say JSON_DA.xml, on the same level with your reports.
Add this property to each of the subreports:
<property name="net.sf.jasperreports.data.adapter" value="JSON_DA.xml"/>
(This could also be done by setting the Default Data Adapter in the Report Properties tab)
Recompile each subreport then preview the Master report again.
All this is necessary because JasperSoft Studio does not inject the Data Adapter into each subreport at runtime. It only injects it when each report is individually run(previewed) by automatically setting the com.jaspersoft.studio.data.defaultdataadapter property.
I am using jasper report with Spring MVC. I have generated font.jar from jaspersoft studio 6.6.0 and add it to my application classpath. I am trying to use vrinda.ttf and sutonnyOMJ.ttf.
While the report is rendered properly in jasper studio, when I am using it from my application no unicode fonts are showing for PDF export. For excel export all values are showing properly but pdf is not working.
Font Family from my custom font.jar
<?xml version="1.0" encoding="UTF-8"?>
<fontFamilies>
<fontFamily name="vrinda">
<normal><![CDATA[fonts/vrinda/vrinda.ttf]]></normal>
<pdfEncoding><![CDATA[Identity-H]]></pdfEncoding>
<pdfEmbedded><![CDATA[true]]></pdfEmbedded>
<exportFonts>
<export key="net.sf.jasperreports.html">vrinda</export>
<export key="net.sf.jasperreports.xhtml">vrinda</export>
</exportFonts>
</fontFamily>
<fontFamily name="sutonny">
<normal><![CDATA[fonts/sutonny/SutonnyOMJ.ttf]]></normal>
<bold><![CDATA[fonts/sutonny/SutonnyMJ-Bold.ttf]]></bold>
<italic><![CDATA[fonts/sutonny/SutonnyMJ-Italic.ttf]]></italic>
<boldItalic><![CDATA[fonts/sutonny/SutonnyMJ-BoldItalic.ttf]]></boldItalic>
<pdfEncoding><![CDATA[Identity-H]]></pdfEncoding>
<pdfEmbedded><![CDATA[true]]></pdfEmbedded>
<exportFonts>
<export key="net.sf.jasperreports.html">SutonnyOMJ</export>
<export key="net.sf.jasperreports.xhtml">SutonnyOMJ</export>
</exportFonts>
</fontFamily>
</fontFamilies>
JRXML:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.0 -->
<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="myName" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="a43ee182-4df8-4ea4-b26f-b8b21078c9d1">
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="dbname"/>
<queryString language="SQL">
<![CDATA[Query]]>
</queryString>
<field name="ClientName" class="java.lang.String">
<property name="com.jaspersoft.studio.field.label" value="ClientName"/>
<property name="com.jaspersoft.studio.field.tree.path" value="Table"/>
</field>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="35" splitType="Stretch">
<textField>
<reportElement x="20" y="5" width="500" height="30" uuid="f4900f30-da32-4cec-9142-10b111debcf3"/>
<textElement>
<font fontName="Vrinda" size="26"/>
</textElement>
<textFieldExpression><![CDATA["\u09AA\u09CD\u09B0\u09A4\u09BF\u09AC\u09C7\u09A6\u09A8"]]></textFieldExpression>
</textField>
</band>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch">
<staticText>
<reportElement x="82" y="0" width="100" height="30" uuid="b35f8d0e-5c47-46c7-b71c-c63dd7706724">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="9609ebcc-b3ae-4997-92b2-9aa48843434a"/>
</reportElement>
<textElement>
<font size="26"/>
</textElement>
<text><![CDATA[ClientName]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="125" splitType="Stretch">
<textField>
<reportElement x="82" y="64" width="308" height="30" uuid="ba9cab6a-2688-4601-bedb-3b62913a2cfb">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="9609ebcc-b3ae-4997-92b2-9aa48843434a"/>
</reportElement>
<textElement>
<font fontName="Vrinda" size="26"/>
</textElement>
<textFieldExpression><![CDATA[$F{ClientName}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
Java Code:
JasperReport jasperReport = JasperCompileManager.compileReport(reportSourceFile);
JasperPrint print = JasperFillManager.fillReport(jasperReport, params, reportRequestDTO.getConnection());
JRPdfExporter exporter = new JRPdfExporter();
ExporterInput exporterInput = new SimpleExporterInput(print);
exporter.setExporterInput(exporterInput);
OutputStreamExporterOutput exporterOutput = new SimpleOutputStreamExporterOutput(path);
exporter.setExporterOutput(exporterOutput);
SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
exporter.setConfiguration(configuration);
exporter.exportReport();
pom.xml
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>6.5.1</version>
</dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports-fonts</artifactId>
<version>6.0.0</version>
</dependency>
Excel Image for header unicode (Which is not showing in PDF)
Is it possible to add a button in the report, which any action will be fixed?
Example: Button "View", which will show more detailed statistic.
Comment:
I do not absolutely understand how it is possible to make a button of a text element
To create a button, create a textField with hyperlinkType="Reference" and a hyperlinkReferenceExpression
Example
<?xml version="1.0" encoding="UTF-8"?>
<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="JddButton" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="2a88eaae-fbef-4a3d-b8bf-0b12bafc985b">
<title>
<band height="80" splitType="Stretch">
<textField hyperlinkType="Reference" hyperlinkTarget="Blank">
<reportElement mode="Opaque" x="150" y="20" width="200" height="40" forecolor="#FFFFFF" backcolor="#009900" uuid="822deecb-059b-4921-bfb7-07ee7cbde26a">
<property name="net.sf.jasperreports.export.html.class" value="btn"/>
<property name="net.sf.jasperreports.export.html.id" value="idBtn"/>
</reportElement>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="24"/>
</textElement>
<textFieldExpression><![CDATA["VIEW"]]></textFieldExpression>
<anchorNameExpression><![CDATA["myButton"]]></anchorNameExpression>
<hyperlinkReferenceExpression><![CDATA["https://stackoverflow.com/users/5292302/petter-friberg"]]></hyperlinkReferenceExpression>
<hyperlinkTooltipExpression><![CDATA["Click to view"]]></hyperlinkTooltipExpression>
</textField>
</band>
</title>
</jasperReport>
Will generate
when clicked it will direct you to the value of the hyperlinkReferenceExpression, in example I have also set hyperlinkTarget="Blank" so it opens in a new page.
For additional information on the attributes see JRHyperLink API
Hey I want my button to change color when I pass over it....
No problem, (as long as export is html, in pdf you need to do some tricks with annotation but I will leave this out..).
I have added some css tags on the textElement see the property under the reportElement
So some simple css.
<style type="text/css">
a {text-decoration: none}
td.btn:hover {
background-color: yellow !Important;
}
</style>
Finally, how do I put this css in the output file?
Export custom HTML template
How to add css to jasper report server
I have the following data to be printed in the PDF,
101 HARRIER WAY<br>OMVILLE<br>BELLSHIRE<br>OM1 1HA<br>
It needs to be displayed in the following way,
101 HARRIER WAY
OMVILLE
BELLSHIRE
OM1 1HA
But is is printing like the following,
UPDATE:
When I use other text in the place of OMVILLE say
101 HARRIER WAY<br>HELLO WORLD BANGALORE<br>BELLSHIRE<br>OM1 1HA<br>
it works well. I don't have any idea why it is not working when I give OMVILLE
Code:
<?xml version="1.0" encoding="UTF-8"?>
<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="accountStatement" pageWidth="720" pageHeight="1008" columnWidth="680" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isTitleNewPage="true">
<parameter name="address" class="java.lang.String"/>
<queryString>
<![CDATA[]]>
</queryString>
<title>
<band height="914" splitType="Stretch">
<textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true">
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="117" y="141" width="297" height="105" isRemoveLineWhenBlank="true"/>
<textElement markup="html">
<font size="9" isBold="false" pdfFontName="Helvetica"/>
<paragraph lineSpacing="Single" tabStopWidth="60"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$P{address}]]></textFieldExpression>
</textField>
</band>
</title>
</jasperReport>
I am running this code using iReport 4.0.2 and my JasperReports version is 4.
For running the above code use all the input parameters as default values and for address parameter give below one as input.
101 HARRIER WAY<br>OMVILLE<br>BELLSHIRE<br>OM1 1HA<br>
P.S: I am generating the jrxml in PDF format.
Your sample works fine with this versions of JasperReports API: 4.0.1 and 4.1.1, but I've faced the same problem as you with 4.0.2 version.
What is difference?
We can compare two versions of implementation of JRPdfExporter, for example the 4.1.1 and 4.0.2 versions.
As you can see the source code of PdfTextRenderer is different for this two versions, for example the method draw is changed. This method draw() contains the calling of ColumnText.go() method of iText framework. This method is using for drawing text in pdf document.
Possible solutions:
You can upgrade your vestion of JasperReports library. The last one is 5.2.0 and your sample works with it. Your sample works well even with 4.1.1 as I mentioned before
You can fix the source code of PdfTextRenderer class if you can not upgrade the version of JR library.
About testing your issue
I've wrote a small sample for testing your issue. I've used the Maven project - for simple switching between JR libraries versions.
The source code of Java class for testing issue:
public static void testReport() throws JRException {
Map<String, Object> params = new HashMap<String, Object>();
params.put("address", "101 HARRIER WAT<br/>OMVILLE<br/>BELLSHIRE<br/>OM1 1HA<br/>");
JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, new JREmptyDataSource());
JasperExportManager.exportReportToPdfFile(jasperPrint, outputFileName);
}
And the "slim" test jrxml file was:
<?xml version="1.0" encoding="UTF-8"?>
<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="accountStatement" pageWidth="720" pageHeight="1008" columnWidth="680" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isTitleNewPage="true">
<parameter name="address" class="java.lang.String"/>
<queryString>
<![CDATA[]]>
</queryString>
<title>
<band height="914" splitType="Stretch">
<textField>
<reportElement x="117" y="141" width="297" height="105"/>
<textElement markup="html">
<font size="9" isBold="false" pdfFontName="Helvetica"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$P{address}]]></textFieldExpression>
</textField>
</band>
</title>
</jasperReport>