I use iReport 5.5.0. How to center align a barcode component?
Relevant fragment of my jrxml is below.
<componentElement>
<reportElement x="0" y="9" width="113" height="36" uuid="a11badb4-7c31-4011-83ae-f287b457939a"/>
<jr:Code128 xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" textPosition="bottom">
<jr:codeExpression><![CDATA[$F{number}]]></jr:codeExpression>
</jr:Code128>
</componentElement>
Create a style, let's call it "Barcode", like:
<style name="Barcode" fontName="Helvetica" fontSize="10" hAlign="Center" vAlign="Middle"/>
and set the style property of your barcode element to "Barcode".
Related
We need a help to execute the maps in jasper report
We have used below command which is working fine in 6.2.0 (10/6/2018).
Now it is stop to display map and getting error. Hence we added map.key to resolve and also experimented with latest map component, but not able get map as previously.
Could you please help us to resolve this issue.
Thank you
Map key data
<property name="net.sf.jasperreports.components.map.key" value="AIzaSy**********5w"/>
<property name="net.sf.jasperreports.components.map.version" value="3"/>
map component added in summary
<componentElement>
<reportElement x="0" y="0" width="572" height="680" uuid="d66b99c0-0651-47f0-954f-90fc23b4a344">
<printWhenExpression><![CDATA[$F{row_num}!= null]]></printWhenExpression>
</reportElement>
<c:map xmlns:c="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" evaluationTime="Band" mapType="hybrid">
<c:latitudeExpression><![CDATA[Float.parseFloat($F{center_lat})]]></c:latitudeExpression>
<c:longitudeExpression><![CDATA[Float.parseFloat($F{center_lng})]]></c:longitudeExpression>
<c:zoomExpression><![CDATA[Integer.parseInt($P{ZOOM})]]></c:zoomExpression>
<c:markerData>
<dataset/>
<c:item>
<c:itemProperty name="latitude">
<valueExpression><![CDATA[Float.parseFloat($F{latitude})]]></valueExpression>
</c:itemProperty>
<c:itemProperty name="longitude">
<valueExpression><![CDATA[Float.parseFloat($F{longitude})]]></valueExpression>
</c:itemProperty>
<c:itemProperty name="label">
<valueExpression><![CDATA[$F{row_num}]]></valueExpression>
</c:itemProperty>
</c:item>
</c:markerData>
</c:map>
</componentElement>
In my JasperReport's report only the first row of my collection gets displayed. Here is the relevant code.
The entity
public class LegendEntity implements Serializable{
private String label;
private Image bufferedImage;
public LegendEntity() {
}
public LegendEntity(String label) {
this.label = label;
}
public LegendEntity(String label,Image bufferedImage) {
this.label = label;
this.bufferedImage = bufferedImage;
}
//getters-setters
Preparing the datasource:
List<MyEntity> myEntitiesList = new ArrayList<>();
//filling the list
JRBeanCollectionDataSource entityDS= new JRBeanCollectionDataSource(myEntitiesList ,false);
report.getReportParameters().put("ENTITY_DATASOURCE", entityDS);
The jrxml:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport ... name="SampleReport" printOrder="Horizontal" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="595" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">
<subDataset name="LegendDataset" uuid="e0d72aca-6fd5-4935-b57f-ff5a436f2afb">
<field name="label" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="bufferedImage" class="java.awt.Image"/>
</subDataset>
<parameter name="P_MAP_SCALE_STR" class="java.lang.String"/>
<parameter name="ENTITY_DATASOURCE" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
<detail>
<band height="842" splitType="Stretch">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.FreeLayout"/>
<frame>
<reportElement x="298" y="635" width="298" height="206" uuid="e807b35a-857c-43ba-a080-13f422eb1456"/>
<componentElement>
<reportElement x="11" y="11" width="275" height="186" uuid="d6f579d3-75de-4745-8f94-c974d2e697a0"/>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
<datasetRun subDataset="LegendDataset" uuid="ee194811-e7e5-4102-83ff-b150901d73c9">
<dataSourceExpression><![CDATA[$P{ENTITY_DATASOURCE}]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="186" width="275">
<staticText>
<reportElement x="10" y="10" width="130" height="20" uuid="4260f10d-ee62-4cf6-8023-d0dc2266f4dd"/>
<textElement textAlignment="Center"/>
<text><![CDATA[ENTITY LABEL]]></text>
</staticText>
<staticText>
<reportElement x="150" y="10" width="100" height="20" uuid="88135c50-3c17-4b0f-b7e5-b05987f98b02"/>
<textElement textAlignment="Center"/>
<text><![CDATA[ENTITY SYMBOL]]></text>
</staticText>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="10" y="31" width="130" height="18" uuid="30885d06-38db-4b1c-a312-616a60ee1c42"/>
<textFieldExpression><![CDATA[$F{label}]]></textFieldExpression>
</textField>
<image>
<reportElement x="150" y="31" width="100" height="18" uuid="0020adca-acad-4915-9f0d-88d75e4897c7"/>
<imageExpression><![CDATA[$F{bufferedImage}]]></imageExpression>
</image>
</jr:listContents>
</jr:list>
</componentElement>
</frame>
<staticText>
<reportElement x="30" y="600" width="80" height="18" uuid="6c1afd65-a8d4-4e3f-9a56-d09abe7ec904"/>
<textElement textAlignment="Right">
<font fontName="DejaVu Sans" size="9" isBold="true"/>
</textElement>
<text><![CDATA[Ölçek: 1/]]></text>
</staticText>
<textField>
<reportElement positionType="Float" x="110" y="600" width="100" height="18" uuid="6360a545-63af-48cc-987d-d828c24a3b2a"/>
<textElement>
<font fontName="DejaVu Sans" size="9" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$P{P_MAP_SCALE_STR}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
And on the report only the first entity's label and symbol is displayed. What am I missing?
Debugging already done and I am sure that 1+ entities are present in the list.
The whole JRXML here .
You can try to put variables in white zone in table. Not in blue/header zone.
It works for me.
I have noticed at least 2 problems in your main JRXML:
Setting printOrder="Horizontal" at the report level may prevent proper elements overflow. Try reverting to printOrder="Vertical" or remove the attribute completely.
There is too much whitespace inside the list element that would force overflow. You should not have white space after the last elements.
I would like to have a footer appear only on the first page of jasper reports.
After searching the forums, I have seen this question asked and improperly answered several times here. As many have suggested I have tried putting a print when expression on the footer band to prevent it from printing when it isn't the first page like:
new Boolean($V{PAGE_NUMBER}.intValue() == 1)
This does not work though. The result is that none of the attributes of the page footer print, but the footer block still prints and takes up space preventing the detail from using the whole page. Effectively, you have a footer with data on the first page and a footer with no data on every following page.
Does anyone know a trick how to actually make this work?
Definitely there does not seem to be a direct way of achieving it, at least with current version of Jasper libraries available. However here's a very crude workaround that worked for us in a similar requirement. I separated out only the footer management part of the code into a sample project this morning and it works fine.
Notes:
Not sure if this works with complex reports (especially if column-footer needs to be printed, as we manually modify the columnFooterOffsetY value). We had to generate a simple report with only title, detail and footer bands.
Importantly, i do not recommend using this solution for complex requirements as it may induce maintainability issues in long run (especially if you migrate to a later version of jasperreports library in future which might have modified the report-filling logic).
I have used JasperReports library version 5.0.0 for the testing.
How the example is built:
Created JRXML with iReport, with a printwhenexpression, new Boolean($V{PAGE_NUMBER}.intValue() == 1, for the page-footer band.
Created a Custom report-filler instance, extending the JRVerticalFiller class.
Sample source XML used: (add additional lines to the XML so that the report wraps to multiple pages)
<?xml version="1.0" encoding="UTF-8"?>
<employees>
<employee id="1001" name="AAA" email="aaa#somecorp.com" salary="20500.125"/>
<employee id="1002" name="BBB" email="bbb#somecorp.com" salary="10000.500"/>
<employee id="1003" name="CCC" email="ccc#somecorp.com" salary="12275.750"/>
<employee id="1004" name="DDD" email="ddd#somecorp.com" salary="10750.750"/>
</employees>
JRXML created with iReport (with a printwhenexpression for the footer band):
<?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="jr_footer_display_test" pageWidth="792" pageHeight="288" orientation="Landscape" columnWidth="752" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="27ac3ae2-27da-484b-b088-b4d79aa973cc">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString language="xPath">
<![CDATA[//employee]]>
</queryString>
<field name="email" class="java.lang.String">
<fieldDescription><![CDATA[./#email]]></fieldDescription>
</field>
<field name="id" class="java.lang.String">
<fieldDescription><![CDATA[./#id]]></fieldDescription>
</field>
<field name="name" class="java.lang.String">
<fieldDescription><![CDATA[./#name]]></fieldDescription>
</field>
<field name="salary" class="java.lang.String">
<fieldDescription><![CDATA[./#salary]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<columnHeader>
<band height="50">
<staticText>
<reportElement uuid="c3d42e71-672e-402f-9fbb-4889be2a269b" x="29" y="2" width="100" height="20"/>
<textElement/>
<text><![CDATA[ID]]></text>
</staticText>
<staticText>
<reportElement uuid="a4c42dc4-4276-485a-b5a6-b4e6bd2bc217" x="136" y="2" width="100" height="20"/>
<textElement/>
<text><![CDATA[Name]]></text>
</staticText>
<staticText>
<reportElement uuid="157e527b-7ad5-46bf-a06d-2fa0a2686b1e" x="253" y="2" width="100" height="20"/>
<textElement/>
<text><![CDATA[Email]]></text>
</staticText>
<staticText>
<reportElement uuid="4d87c542-7057-4bc1-9a7e-fbd6a554f33a" x="386" y="2" width="100" height="20"/>
<textElement/>
<text><![CDATA[Salary]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="21" splitType="Stretch">
<textField>
<reportElement uuid="31d09543-a128-469a-be38-3d8987ba781b" x="29" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="ce5c11f8-68da-4efd-93fa-e1f1b5ce407f" x="136" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="300dcc3b-8a2a-489d-8518-7283c95b2f88" x="253" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{email}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="a37f2df9-2459-446d-bc47-488a336aa60e" x="386" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{salary}]]></textFieldExpression>
</textField>
</band>
</detail>
<pageFooter>
<band height="40" splitType="Stretch">
<printWhenExpression><![CDATA[new Boolean($V{PAGE_NUMBER}.intValue() == 1)]]></printWhenExpression>
<textField>
<reportElement uuid="3d9beff7-69b8-44d9-af80-2962b9262368" x="29" y="12" width="80" height="20"/>
<textElement textAlignment="Left"/>
<textFieldExpression><![CDATA["Page: "+$V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
</band>
</pageFooter>
</jasperReport>
Custom report-filler implementation: (this handles the height resetting logic to ensure detail band stretches longer from page 2 onwards)
public class CustomVerticalFiller extends JRVerticalFiller {
private JRFillBand detailBand = null;
private int pageNumber = -1;
protected CustomVerticalFiller(JasperReportsContext jasperReportsContext, JasperReport jasperReport) throws JRException {
super(jasperReportsContext, jasperReport);
detailBand = detailSection.getFillBands()[0];
}
// this method gets called after each detail band row is filled
protected void resolveBandBoundElements(JRFillBand band, byte evaluation) throws JRException {
if(band == detailBand) {
if((detailBand.getBreakHeight() > columnFooterOffsetY - offsetY) && (columnIndex == columnCount - 1)) {
// we have reached end of a page
pageNumber++;
// we reset the offset when we are at the end of page 2, so that jasper continues to fill data
if(pageNumber == 1) {
columnFooterOffsetY += pageFooter.getHeight();
}
}
}
}
}
And the Java code that actually uses the custom filler to export a PDF:
InputStream inputStream = new FileInputStream(new File(<my jrxml file path>));
JRDataSource dataSource = new JRXmlDataSource(new File(<my source xml file path>), "//employee");
Map parameters = new HashMap();
JasperDesign jasperDesign = JRXmlLoader.load(inputStream);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
CustomVerticalFiller customVerticalFiller = new CustomVerticalFiller(DefaultJasperReportsContext.getInstance(), jasperReport);
JasperPrint jasperPrint = customVerticalFiller.fill(parameters, dataSource);
JasperExportManager.exportReportToPdfFile(jasperPrint, <target pdf file path>);
You should put this code on Band Properties Print when expression of PageFooter
new Boolean( $V{PAGE_NUMBER}.intValue() == 1 )
Unfortunately #emecheon answer doesn't work with current jasper version ( I use 6.7.0), but cure is pretty much the same.
I change columnFooterOffsetY after first page.
This way you can have footer of different size for each page.
public class CustomVerticalFiller extends JRVerticalFiller {
private int pageNumber = 0;
public CustomVerticalFiller(JasperReportsContext jasperReportsContext, JasperReport jasperReport) throws JRException {
super(jasperReportsContext, jasperReport);
}
#Override
protected void addPage(JRPrintPage page) {
super.addPage(page);
pageNumber++;
if (pageNumber == 2) {
columnFooterOffsetY += pageFooter.getHeight();
}
}
}
The expression I use to print a footer only on the first page is the following:
In the Print When Expression field
IF($V{PAGE_NUMBER}.intValue()==1,TRUE( ),FALSE( ))
It checks whether this is the first page and if so it returns true and prints the band. If not, it does not print anything.
If you would like to print one footer on the first page and a different one on the following pages. I use this code as the expression for the subreport properties. (not print when expression)
IF($V{PAGE_NUMBER}.intValue()==1,"subreportFooter1.jasper","subreportFooter2.jasper")
The code of my servlet:
JasperCompileManager.compileReportToFile(jrxmlSourcePathMain,
jrxmlDestPathMain);
InputStream isRef = new FileInputStream(new File(jrxmlDestPathMain));
ServletOutputStream sosRef = response.getOutputStream();
response.setContentType("application/pdf");
JasperRunManager.runReportToPdfStream(isRef, sosRef, new HashMap(),
new JRBeanCollectionDataSource(buyBookInfoList));
sosRef.flush();
sosRef.close();
The snippet of jrxml file:
<summary>
<band height="265" splitType="Stretch">
<pieChart>
<chart isShowLegend="true" renderType="svg" theme="default">
<reportElement uuid="c6a09cc9-bd15-4b09-8657-05868a148f18" x="0" y="0" width="554" height="265"/>
<chartTitle position="Top" color="#FF0000">
<font fontName="宋体" size="18" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
<titleExpression><![CDATA["报表演示"]]></titleExpression>
</chartTitle>
<chartSubtitle color="#0000FF">
<font fontName="宋体" size="14" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
<subtitleExpression><![CDATA["子标题"]]></subtitleExpression>
</chartSubtitle>
<chartLegend textColor="#33FF33" backgroundColor="#6666FF" position="Right">
<font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
</chartLegend>
</chart>
<pieDataset>
<keyExpression><![CDATA[$F{username}]]></keyExpression>
<valueExpression><![CDATA[$F{buyBookNum}]]></valueExpression>
</pieDataset>
<piePlot isShowLabels="true" isCircular="false" labelFormat="姓名为:{0}">
<plot orientation="Horizontal" labelRotation="180.0"/>
<itemLabel/>
</piePlot>
</pieChart>
</band>
</summary>
I set Increment Type property for PieChart value with different values: none, report, page. But I did not notice any difference in generated reports.
So my question is how to use the PieChart's Increment Type property?
What is a purpose of this property?
The increment type allows you to tell the pie chart when to select values to use. For example, if you want to create a pie chart that shows sales in the USA, Canada, and Mexico, you might increment over a "country" group.
Problem
I have to display an object as an image inside a list component based on a particular count (intNote). While using an image path from specific location the images are displayed.
Question
How can I display an object as an image inside a list component?
Source
The JRXML:
<subDataset name="Q2">
<field name="strVert" class="java.awt.Image"/>
</subDataset>
<field name="intNote" class="java.lang.Integer"/>
<componentElement>
<reportElement x="130" y="72" width="25" height="35"/>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Horizontal" ignoreWidth="true">
<datasetRun subDataset="Q2">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource($F{intNote})]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="35" width="25">
<image isUsingCache="false">
<reportElement x="3" y="10" width="16" height="17" forecolor="#FFFFFF"/>
<graphicElement>
<pen lineWidth="1.25"/>
</graphicElement>
<imageExpression class="java.awt.Image"><![CDATA[$F{strVert}]]></imageExpression>
</image>
</jr:listContents>
</jr:list>
</componentElement>
Thank you.
In jasper you can display images by putting the current image location instead of the varible intNote.it is the only possible way to get the image in the output.
Try to make $F{strVert} class as java.io.InputStream