I need to enable the reports with 3 types of the page headers: "first page header", "middle pages header" and "last page header". All of these headers can have different number of report elements and on different positions. Same goes for the footers.
NOTE: The report must support the report elements like jr:table or jr:list in its Detail band. These element must be supplied with the data via xml datasources.
I was able to simulate first page header by using Title band, but I'm having problems enabling "middle pages header" and "last page header". This is what I'm trying to do:
<pageHeader>
<band height="100" splitType="Stretch">
<frame>
<reportElement x="0" y="0" height="100" width="555" uuid="f788c74b-6853-4bc7-8ed7-5e3d538287c9" isRemoveLineWhenBlank="true">
<printWhenExpression>
<![CDATA[new Boolean($V{PAGE_NUMBER} == $V{PAGE_COUNT})]]>
</printWhenExpression>
</reportElement>
<staticText>
<reportElement x="1" y="1" width="100" height="20" uuid="9777208b-5323-4045-aa49-a849d5c00c89"/>
<text><![CDATA[LAST PAGE HEADER TEXT 1]]></text>
</staticText>
<staticText>
<reportElement x="50" y="10" width="200" height="50" uuid="15313676-09e6-4d17-ac75-2df99f61bfee"/>
<text><![CDATA[LAST PAGE HEADER TEXT 2]]></text>
</staticText>
</frame>
<frame>
<reportElement x="0" y="0" height="100" width="555" uuid="65577abd-8717-477a-f27e-c70e9eba46af" isRemoveLineWhenBlank="true">
<printWhenExpression>
<![CDATA[new Boolean($V{PAGE_NUMBER} != 1) && new Boolean($V{PAGE_NUMBER} != $V{PAGE_COUNT})]]>
</printWhenExpression>
</reportElement>
<staticText>
<reportElement x="70" y="0" width="300" height="100" uuid="0a866eb3-85cf-4376-d6a4-21b534d36df0"/>
<text><![CDATA[MIDDLE PAGE HEADER TEXT 1]]></text>
</staticText>
</frame>
</band>
</pageHeader>
I'm using frame blocks along with printWhenExpression. Depending on the printWhenExpression condition, only one of two frame blocks should be printed (with all of its content). First frame block should render "last page header", and second one should render "middle pages header".
The problem lies within the first frame ("last page header") printWhenExpression:
<printWhenExpression>
<![CDATA[new Boolean($V{PAGE_NUMBER} == $V{PAGE_COUNT})]]>
</printWhenExpression>
In this case, $V{PAGE_NUMBER} always equals $V{PAGE_COUNT} because of the evaluation time.
Is there any way to check if the current page is the last page? Also, is there any other way to enable "middle pages" and "last page" headers?
NOTE: I was able to implement similar logic for the footers by using the frames and Last Page Footer band!
First of all: $V{PAGE_COUNT} is
the number of records that were processed when generating the current page. Hence the number of records you have in the page, not a page number count...
In pageFooter and lastPageFooter the reportElement can have negative Y coordinates (if IDE does not allow this then you need to edit manually the jrxml) es. y="-700", which allows you to put information in pageHeader and last pageHeader...
FIRST PAGE
in frame use:
<printWhenExpression><![CDATA[new Boolean($V{PAGE_NUMBER}.intValue()==1)]]></printWhenExpression>
pageHeader use title band or put frame in pageFooter and use negative y coordinate.
pageFooter, use pageFooter band
MIDDLE PAGE
on frame use:
<printWhenExpression><![CDATA[new Boolean($V{PAGE_NUMBER}.intValue()>1)]]></printWhenExpression>
pageHeader put frame in pageFooter and use negative y coordinate.
pageFooter, use pageFooter band.
LAST PAGE
pageHeader, put frame in lastPageFooter and use negative y coordinate.
pageFooter, use lastPageFooter band
NOTE: To generate space for this virtual pageHeader include an empty pageHeader with desired band height
Have Fun!
Related
I want to know how to change font size in field expression. it's mean I have a two db fields. then now I want to merge those two fields using expression.
example :
$F{type1} + " Balance is SLR : " + $F{type2}
I write this simple code in field expression.
but now problem is i want to set 10px font size to $F{type1} field and
12px font size to $F{type2} field.
Thank You
Use styled text:
<textField>
<reportElement width="300" y="0" x="0" height="200"/>
<textElement markup="styled"/>
<textFieldExpression><![CDATA["<style size=\"10\">" + $F{type1} + "</style> Balance is SLR : <style size=\"12\">" + $F{type2} + "</style>"]]></textFieldExpression>
</textField>
See some details about the feature here.
I have a report with position type float for all elements and stretch type Relative to Band Height and no stretch for different element. For one particular case I want my textField to completely vanish depending upon Print when expression, so I have Remove Line When Blank checked. But the problem is, there is small gap between element above and below it when it is gone.
This is what I expect.
This is what I get
Following is my textField
<textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true">
<reportElement positionType="Float" stretchType="RelativeToBandHeight" mode="Opaque" x="0" y="617" width="278" height="10" isRemoveLineWhenBlank="true" forecolor="#000000" backcolor="#00FFFF" uuid="b8a09e5a-b3ff-4ddf-b833-3cf854f1108e">
<printWhenExpression><![CDATA[($F{SOME_VALUE}!=null)]]></printWhenExpression>
</reportElement>
<textElement textAlignment="Justified" verticalAlignment="Middle">
<font fontName="Arial" size="4" isBold="true" isItalic="false" pdfFontName="Helvetica-Bold"/>
<paragraph leftIndent="1" rightIndent="1"/>
</textElement>
<textFieldExpression><![CDATA[$F{SOME_VALUE}]]></textFieldExpression>
</textField>
If the stretch type is No stretch it works as expected and no gap between elements, but it is not working for Relative to Band Height. How do I solve this issue?
EDIT
I tried keeping elements inside the frame but result is the same (Like I have said, it works when stretch type is No Stretch, but there is gap for Relative to Band Height).
LAST EDIT
I had to keep the Middle dynamic element on it's own band to make that work.My detail band was really complicated and there were other dynamic elements which might have resulted on growth of space on the band.
I need to enable the reports with 3 types of the page headers: "first page header", "middle pages header" and "last page header". All of these headers can have different number of report elements and on different positions. Same goes for the footers.
NOTE: The report must support the report elements like jr:table or jr:list in its Detail band. These element must be supplied with the data via xml datasources.
I was able to simulate first page header by using Title band, but I'm having problems enabling "middle pages header" and "last page header". This is what I'm trying to do:
<pageHeader>
<band height="100" splitType="Stretch">
<frame>
<reportElement x="0" y="0" height="100" width="555" uuid="f788c74b-6853-4bc7-8ed7-5e3d538287c9" isRemoveLineWhenBlank="true">
<printWhenExpression>
<![CDATA[new Boolean($V{PAGE_NUMBER} == $V{PAGE_COUNT})]]>
</printWhenExpression>
</reportElement>
<staticText>
<reportElement x="1" y="1" width="100" height="20" uuid="9777208b-5323-4045-aa49-a849d5c00c89"/>
<text><![CDATA[LAST PAGE HEADER TEXT 1]]></text>
</staticText>
<staticText>
<reportElement x="50" y="10" width="200" height="50" uuid="15313676-09e6-4d17-ac75-2df99f61bfee"/>
<text><![CDATA[LAST PAGE HEADER TEXT 2]]></text>
</staticText>
</frame>
<frame>
<reportElement x="0" y="0" height="100" width="555" uuid="65577abd-8717-477a-f27e-c70e9eba46af" isRemoveLineWhenBlank="true">
<printWhenExpression>
<![CDATA[new Boolean($V{PAGE_NUMBER} != 1) && new Boolean($V{PAGE_NUMBER} != $V{PAGE_COUNT})]]>
</printWhenExpression>
</reportElement>
<staticText>
<reportElement x="70" y="0" width="300" height="100" uuid="0a866eb3-85cf-4376-d6a4-21b534d36df0"/>
<text><![CDATA[MIDDLE PAGE HEADER TEXT 1]]></text>
</staticText>
</frame>
</band>
</pageHeader>
I'm using frame blocks along with printWhenExpression. Depending on the printWhenExpression condition, only one of two frame blocks should be printed (with all of its content). First frame block should render "last page header", and second one should render "middle pages header".
The problem lies within the first frame ("last page header") printWhenExpression:
<printWhenExpression>
<![CDATA[new Boolean($V{PAGE_NUMBER} == $V{PAGE_COUNT})]]>
</printWhenExpression>
In this case, $V{PAGE_NUMBER} always equals $V{PAGE_COUNT} because of the evaluation time.
Is there any way to check if the current page is the last page? Also, is there any other way to enable "middle pages" and "last page" headers?
NOTE: I was able to implement similar logic for the footers by using the frames and Last Page Footer band!
First of all: $V{PAGE_COUNT} is
the number of records that were processed when generating the current page. Hence the number of records you have in the page, not a page number count...
In pageFooter and lastPageFooter the reportElement can have negative Y coordinates (if IDE does not allow this then you need to edit manually the jrxml) es. y="-700", which allows you to put information in pageHeader and last pageHeader...
FIRST PAGE
in frame use:
<printWhenExpression><![CDATA[new Boolean($V{PAGE_NUMBER}.intValue()==1)]]></printWhenExpression>
pageHeader use title band or put frame in pageFooter and use negative y coordinate.
pageFooter, use pageFooter band
MIDDLE PAGE
on frame use:
<printWhenExpression><![CDATA[new Boolean($V{PAGE_NUMBER}.intValue()>1)]]></printWhenExpression>
pageHeader put frame in pageFooter and use negative y coordinate.
pageFooter, use pageFooter band.
LAST PAGE
pageHeader, put frame in lastPageFooter and use negative y coordinate.
pageFooter, use lastPageFooter band
NOTE: To generate space for this virtual pageHeader include an empty pageHeader with desired band height
Have Fun!
I'm trying to add a barcode to my report template, its' an EAN13 barcode here's the code :
<componentElement>
<reportElement uuid="af782895-f1d3-4e1d-b200-1f2ecf18b4fa" x="67" y="17" width="478" height="81"/>
<jr:barbecue xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" type="EAN13" drawText="true" checksumRequired="false" barWidth="3" barHeight="10">
<jr:codeExpression><![CDATA[142155363254]]></jr:codeExpression>
</jr:barbecue>
</componentElement>
When i generate the report i on ly get the code expression , no barcode drawed
Here's the template design :
I think that the EAN13 is not installed with IReport.
So How can i add it to IReport?.
the solution is to use the Barcode4J library instead of the Barbecue library to print the barcode.
barHeight is too low, try something like 50 or don't specify any bar height.
I'm working on a PDF in which I'm trying to have a checkbox in front of each line of a "list" JR component.
I already have some editable fields (text and radio) in my report, in the 'Title' section; everything goes well.
To do that, I use "generic elements" and have some handlers written in Java who generate for example iText TextField in a rectangle (com.lowagie.text.Rectangle.Rectangle), defined like this ('element' is the current generic element, of type JRGenericPrintElement):
element.getX(),
exporterContext.getExportedReport().getPageHeight() - element.getY(),
element.getX() + element.getWidth(),
exporterContext.getExportedReport().getPageHeight() - element.getY() - element.getHeight()
The 'generic element' is defined like this in my .jrxml :
<genericElement>
<reportElement uuid="ec205c41-afe2-44fd-a8b3-03e2d4b07ce6" x="72" y="132" width="143" height="25"/>
<genericElementType namespace="http://namespace" name="simpleEditableTf"/>
<genericElementParameter name="name">
<valueExpression><![CDATA["matricule"]]></valueExpression>
</genericElementParameter>
</genericElement>
I would like to use the same code to define the position of my list checkboxes, but it seems that in the case the generic element is used into a list, the element.getX() and element.getY() methods return the coordinates relatively to the list component.
So rather to have the coordinates of the element in the page (eg. X=50,Y=200) I have these relative to the list component itself (X=4,Y=7); so it's impossible to set the element correctly.
Here is the code of the list element, including the generic element.
<componentElement>
<reportElement uuid="0aa17cac-d5e2-4592-ba0d-ab8e25cc989b" x="10" y="10" width="476" height="23" forecolor="#366798"/>
<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="item_ab" uuid="3c25ec33-3a70-497f-b234-0d5ea64cabcf">
<dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}.subDataSource("//item_ab")]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="23" width="476">
<textField isStretchWithOverflow="true">
<reportElement uuid="0158660b-3ab1-4149-8599-77824c64082f" x="20" y="1" width="420" height="20"/>
<textElement verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{libelle_ab}]]></textFieldExpression>
</textField>
<genericElement>
<reportElement uuid="12c64be4-27dd-4aa2-8d50-f412e25d9805" x="4" y="7" width="9" height="9"/>
<genericElementType namespace="http://namespace" name="checkBox"/>
</genericElement>
</jr:listContents>
</jr:list>
</componentElement>
Could someone tell me if I did something wrong? Is it a bug?
In your generic element handler, add JRPdfExporterContext.getOffsetX()/Y to the position of the element, that is use element.getX() + exporterContext.getOffsetX() everywhere instead of element.getX().