This question already has an answer here:
How to I display images next to each other in jasper reports in jaspersoft studio in the detail view without the pages multiplying?
(1 answer)
Closed 2 years ago.
I have a issue where the same picture displays when trying to display three seperate images from a "job card" in this case..
but there are actually three different images on the db
this is my SQL:
select distinct job_card.job_card_name,
job_card.job_number,
job_card.job_type,
job_card.job_card_name,
client_account.account_name,
job_card.punchlist_comments,
"user".name,
job_card.customer_name,
job_card.created_at,
job_card.customer_signature_blob,
job_card.technician_signature_blob,
photograph.photo_blob
from $P!{schemaName}.job_card
left join $P!{schemaName}.photograph on $P!{schemaName}.job_card."_id_" = $P!{schemaName}.photograph.job_cards_fk
left join $P!{schemaName}."user" on $P!{schemaName}."user"."_id_" = $P!{schemaName}.job_card.technicians_fk
left join $P!{schemaName}.asset on $P!{schemaName}.asset."_id_" = $P!{schemaName}.job_card.assets_fk
left join $P!{schemaName}.client_account on $P!{schemaName}.client_account."_id_" = $P!{schemaName}.asset.clientaccounts_fk
where job_card._id_ = $P{job_cardUUID}::uuid
"photograph.photo_blob" being the variable
and this is the jasper elements:
<textElement verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<text><![CDATA[ Installation pictures ]]></text>
</staticText>
<image>
<reportElement x="0" y="180" width="200" height="124" uuid="8bf21ae9-eec4-4c39-b4c1-4c174ec59aab"/>
<box>
<pen lineWidth="0.25"/>
</box>
<imageExpression><![CDATA[$F{photo_blob}]]></imageExpression>
</image>
<image>
<reportElement x="200" y="180" width="200" height="124" uuid="aa9d55fb-184f-4098-95f8-9de17530c99b"/>
<box>
<pen lineWidth="0.25"/>
</box>
<imageExpression><![CDATA[$F{photo_blob}]]></imageExpression>
</image>
<image>
<reportElement x="400" y="180" width="150" height="124" uuid="64df2d59-4154-4b26-a3d1-3f54f1b54eca"/>
<box>
<pen lineWidth="0.25"/>
</box>
<imageExpression><![CDATA[$F{photo_blob}]]></imageExpression>
</image>
I tried putting this box in the detail band but the page just multiplies by the amount of pictures
You have three repeated pictures because you are using three image elements in the same band at the same time, sharing the same expression i.e $F{photo_blob}.
If you have tree or more different pictures for every job_card._id_ you must create a group, say job_card, and in the group header you put
<text><![CDATA[ Installation pictures ]]></text>
And in the detail band you put
<image>
<reportElement x="0" y="180" width="200" height="124" uuid="8bf21ae9-eec4-4c39-b4c1-4c174ec59aab"/>
<box>
<pen lineWidth="0.25"/>
</box>
<imageExpression><![CDATA[$F{photo_blob}]]></imageExpression>
</image>
Related
Im making a report using JasperReports and iReport, and since im not using a table, what i'm doing now to give it some sort of table like border, is giving the left and right border of each textfield a dotted style.
But, i won't always have the same data in each box, and this is causing the borders to be of different height.
I also would like for the borders to meet each other, but no matter what i change or move, there's always a space in between each box.
But for now, the most important thing is for each box to have the same height.
This is a picture of my report:
This is what each box looks like, they're all similar so i just pasted one the xml of one box:
<textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true">
<reportElement key="textField-1" mode="Transparent" x="7" y="0" width="177" height="0" isRemoveLineWhenBlank="true" forecolor="#000000" backcolor="#FFFFFF">
<printWhenExpression><![CDATA[$F{RESULTMICRO1}!=null]]></printWhenExpression>
</reportElement>
<box leftPadding="1">
<pen lineWidth="0.0"/>
<topPen lineWidth="0.5" lineStyle="Dashed"/>
<leftPen lineWidth="0.5" lineStyle="Dashed"/>
<bottomPen lineWidth="0.5" lineStyle="Dashed"/>
<rightPen lineWidth="0.5" lineStyle="Dashed"/>
</box>
<textElement textAlignment="Left" verticalAlignment="Top" rotation="None">
<font fontName="Courier New" size="9" isBold="false" isItalic="true" isUnderline="false" isStrikeThrough="false" pdfFontName="Courier-Bold" pdfEncoding="Cp1252" isPdfEmbedded="true"/>
<paragraph lineSpacing="Single"/>
</textElement>
<textFieldExpression><![CDATA[$F{RESULTMICRO1}]]></textFieldExpression>
If anyone could help me, i'd appreciate it.
I have a main report and in the main report a sub report called this:
<detail>
<band height="50">
<subreport>
<reportElement x="0" y="1" width="802" height="49" isPrintInFirstWholeBand="true" isPrintWhenDetailOverflows="true"/>
<subreportParameter name="project_id">
<subreportParameterExpression><![CDATA[$P{project_id}]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA["subs/Project_planned.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
There is a problem in the subreport because text fields in the detail band are split up on multiple pages what doesn't look very nice. Is there an option to prevent text fields from splitting up to multiple pages when using the property isStretchWithOverflow
Current code of a text field
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement stretchType="RelativeToBandHeight" x="555" y="0" width="99" height="21" isPrintInFirstWholeBand="true" forecolor="#000000"/>
<box leftPadding="2">
<topPen lineWidth="1.0" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineColor="#000000"/>
</box>
<textElement verticalAlignment="Middle">
<paragraph lineSpacing="Single"/>
</textElement>
<textFieldExpression><![CDATA[$F{logic}]]></textFieldExpression>
</textField>
Example on how it looks (sorry for the missing data):
Yes there is, but not on the text field. For the band the text field is in, you can set the Split Type to Prevent. if you set that on the Detail Band and the row needs to overflow to next page, it will move the entire row to the next page.
When the last entry in a page is too long, It will show in next page, when it show all the table line is missing.
This is the result:
How do I move the last record (no.26) to the next page, or how I can show the line?
You can put the staticText element without text behind the textField element. You should set stretchType property with RelativeToTallestObject value and isPrintWhenDetailOverflows property with true value.
The sample:
<detail>
<band height="20" splitType="Stretch">
<staticText>
<reportElement stretchType="RelativeToTallestObject" x="0" y="0" width="100" height="20" isPrintWhenDetailOverflows="true"/>
<box>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<text><![CDATA[]]></text>
</staticText>
<textField>
<reportElement stretchType="RelativeToTallestObject" x="0" y="0" width="100" height="20"/>
<box>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>
</textField>
As result you will get the vertical border at the second page.
The result before adding the second staticText was (the vertical border at the second page is absent):
Better way is to ensure, that new items in Detail band (or any band) will be generated on next page by setting, but not on the text field. For the band the text field is in, you can set the Split Type to Prevent. if you set that on the Detail Band and the row needs to overflow to next page, it will move the entire row to the next page.
I've written jasper specification to generate PDF from a table data source. This is working fine. Now i have to add few more columns and the report is now not looking good. I'm now thinking if I can squeeze in the column names in multiple lines like the one below
Maintenance Date
to
Maintenance
Date
Is it possible to achieve this in Jasper?
Regards,
Paul
Are your column names hard-coded? Do you just need to change "Maintenance Date" to "Maintenance\nDate" to have a carriage return?
Note: you cannot add a "\n" character to a Static Text element. You need to use a Text Field. Fortunately, you can just right-click on a Static Text element in iReport and transform it to a Text Field.
I guess that might solve it. If not, then you may need to make the question clearer.
If you are using JasperReports API you can use this sample:
//Detail
band = new JRDesignBand();
band.setHeight(40);
JRDesignStaticText staticText = new JRDesignStaticText();
staticText.setX(0);
staticText.setY(0);
staticText.setWidth(60);
staticText.setHeight(20);
staticText.setMode(ModeEnum.OPAQUE);
staticText.setHorizontalAlignment(HorizontalAlignEnum.LEFT);
staticText.setStyle(boldStyle);
staticText.setText("ID: ");
staticText.getLineBox().getLeftPen().setLineWidth(1);
staticText.getLineBox().getTopPen().setLineWidth(1);
staticText.getLineBox().setLeftPadding(10);
band.addElement(staticText);
textField = new JRDesignTextField();
textField.setX(60);
textField.setY(0);
textField.setWidth(200);
textField.setHeight(20);
textField.setHorizontalAlignment(HorizontalAlignEnum.LEFT);
textField.setStyle(normalStyle);
expression = new JRDesignExpression();
expression.setValueClass(java.lang.Integer.class);
expression.setText("$F{Id}");
textField.setExpression(expression);
textField.getLineBox().getTopPen().setLineWidth(1);
textField.getLineBox().getRightPen().setLineWidth(1);
textField.getLineBox().setLeftPadding(10);
band.addElement(textField);
staticText = new JRDesignStaticText();
staticText.setX(0);
staticText.setY(20);
staticText.setWidth(60);
staticText.setHeight(20);
staticText.setMode(ModeEnum.OPAQUE);
staticText.setHorizontalAlignment(HorizontalAlignEnum.LEFT);
staticText.setStyle(boldStyle);
staticText.setText("Name: ");
staticText.getLineBox().getLeftPen().setLineWidth(1);
staticText.getLineBox().getBottomPen().setLineWidth(1);
staticText.getLineBox().setLeftPadding(10);
band.addElement(staticText);
textField = new JRDesignTextField();
textField.setStretchWithOverflow(true);
textField.setX(60);
textField.setY(20);
textField.setWidth(200);
textField.setHeight(20);
textField.setPositionType(PositionTypeEnum.FLOAT);
textField.setStyle(normalStyle);
expression = new JRDesignExpression();
expression.setValueClass(java.lang.String.class);
expression.setText("$F{FirstName} + \" \" + $F{LastName}");
textField.setExpression(expression);
textField.getLineBox().getRightPen().setLineWidth(1);
textField.getLineBox().getBottomPen().setLineWidth(1);
textField.getLineBox().setLeftPadding(10);
band.addElement(textField);
((JRDesignSection) jasperDesign.getDetailSection()).addBand(band);
The result will be:
This is almost identical to this snippet of jrxml file:
<detail>
<band height="40" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="60" height="20"/>
<box leftPadding="10">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
</box>
<textElement/>
<text><![CDATA[ID: ]]></text>
</staticText>
<textField>
<reportElement x="60" y="0" width="200" height="20"/>
<box leftPadding="10">
<topPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{Id}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="0" y="20" width="60" height="20"/>
<box leftPadding="10">
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
</box>
<textElement/>
<text><![CDATA[Name: ]]></text>
</staticText>
<textField>
<reportElement x="60" y="20" width="200" height="20"/>
<box leftPadding="10">
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{FirstName} + " " + $F{LastName}]]></textFieldExpression>
</textField>
</band>
</detail>
This picture shows a sample of what my columns look like in my crosstab (I have two column groups - in this case a date and status). The date should be centered across the 5 columns and I have set the horizontal to be centered. However, it's only centering it based on the size I have set in iReport. I've tried adjusting the various settings but have been unable to center that first row. I'm using JasperReports 4.0.1.
I know it's a little late, but this is how yo do it:
when you declare the columnGroup element, set the headerPosition attribute to "Stretch". Example:
<columnGroup name="month" height="20" headerPosition="Stretch">
<bucket>
<bucketExpression class="java.lang.String"><![CDATA[$F{month}]]></bucketExpression>
</bucket>
<crosstabColumnHeader>
<cellContents backcolor="#999999" mode="Opaque">
<box>
<pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField>
<reportElement style="Crosstab Data Text" x="0" y="0" width="16" height="20"/>
<textElement verticalAlignment="Middle"/>
<textFieldExpression class="java.lang.String"><![CDATA[$V{month}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabColumnHeader>
<crosstabTotalColumnHeader>
<cellContents/>
</crosstabTotalColumnHeader>
Regards,
Damian