Japanese characters not printing in pdf [duplicate] - jasper-reports

I've hardcoded a Text field with the value
":$£Ω€απ⅔:"
to test if these characters will show in PDF
But it only prints as
:$£€:
I've tried changing the font to "Symbol" but that does not do the trick.
Note: I'm using iReport 5.5

I tried your characters using font-extensions in iReport, These are the steps that I took
Download (or use one on your pc) your desired ttf font (it need to support the characters), I used dejavu-serif.
Install the font in iReport or in Jasper soft studio (click links to understand how)
I used iReport 5.6 and did set the PDF-Encoding: Idenity-H (unicode with horizontal writing) and embedded the font in pdf. This was the code of my textField
<textField>
<reportElement x="8" y="15" width="100" height="20" uuid="41dc1200-091f-4799-a1d2-4622f88a0e84"/>
<textElement>
<font fontName="DejaVu Serif" size="13"/>
</textElement>
<textFieldExpression><![CDATA[":$£Ω€απ⅔:"]]></textFieldExpression>
</textField>
Export the font extension (this creates a .jar)
Add the jar to your classpath.
Export to pdf and enjoy the result.
This is an example of how to use any arbitrary font, if you like to
use DejaVu Sans or DejaVu Serif you can just include the jasper
report fonts library in classpath, hence these font are already included and mapped in library

I had posted a similar question and the above technique solved my problem, until one fine day I restarted the JasperServer context. I was now getting "PDF encoding not found" error when I tried to export the report to pdf.
To solve this problem I had to copy the iText-Asian.jar and Font-extension.jar in the lib folder of the jasperserver context.
"jasperserver/WEB-INF/lib". Once done restart the context and problem solved.
Hope it helps someone.

Related

Jasper Reports Polish characters [duplicate]

I am trying to export jasper as pdf but It does not show the cyrillic values. When I export it as excel it does show and the output is fine, but when I try to export is as PDF it does not export the cyrillic values. The cyrillic values are not written in cyrillic font, they are written as cyrillic keyboard.
The code I use to export is:
JRExporter e = new JRPdfExporter();
e.setParameter(JRPdfExporterParameter.JASPER_PRINT, jasperPrint);
e.setParameter(JRPdfExporterParameter.OUTPUT_STREAM, outStream);
e.setParameter(JRPdfExporterParameter.OUTPUT_FILE_NAME, NAME);
I even tried to specift the parameter below:
e.setParameter(JRPdfExporterParameter.CHARACTER_ENCODING, "UTF-8");
but did not succeed. Any suggestions?
Jasper report uses iText and always when a char is not rendered in pdf this should be the checklist:
Is my actual .tff supported (OpenType) and can the font actually render the character. Not all fonts render
all characters in UTF-8, see How can I test if my font is rendered correctly in pdf?
Do I pass correct encoding to iText. In doubts (or in general) use the encoding Identity-H this is recommend for newer PDF standards and gives you the ability to mix different encoding.
Is my font embedded so that if I share the pdf also computers not having this font can display the content?
How can I ensure this is JasperReport?
The deprecated method was to set attributes on the textElement
<textElement>
<font pdfFontName="Helvetica" pdfEncoding="Identity-H" isPdfEmbedded="true"/>
<paragraph lineSpacing="Single"/>
</textElement>
The current non deprecated method v 3-6, is to add Font Extensions and this is easily achieved by using tools like iReport or JasperSoft Studio that can generate a .jar of your font extension so that you can include it in your classpath directly.
How to generate font extension .jar using iReport or JasperSoft Studio.
EDIT: The problem of OP was 1 on checklist (.ttf font could not render), but surely he should consider both 2 and 3 using non deprecated method.

Detail's text field seems to have a characters limit and stops stretching

I have four reports that are basically different formats of the same report and the following problem happens with three of them. I have a text field in the Detail's band that is marked as Stretch with Overflow. The problem is that it seems that it has some kind of characters limit, because with the following text (110 characters):
MAD.ESP.TAUARI(COURATARI GUIANENSIS AUBL.)SERRADA EM RIPA.KD.FAS.FSC 100% MED.19,1MMX38,1MMX2438,4MM DE COMP.
It's only printing:
MAD.ESP.TAUARI(COURATARI GUIANENSIS AUBL.)SERRADA EM RIPA.KD.FAS.FSC 100% MED.19,1MMX38,1MMX2438,4MM DE
As shown in the screen shots:
It's woth noting that when using the "preview" of the JasperStudio, the whole text appears normally for all of them.
Here's the text field's code of one of them. They're basically the same, changing the width, height and position.
<textField isStretchWithOverflow="true">
<reportElement x="26" y="0" width="76" height="10">
</reportElement>
<textElement textAlignment="Center" verticalAlignment="Top">
<font fontName="Arial" size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{descricaoProduto}]]></textFieldExpression>
</textField>
I'm using the 6.2.2 version of JasperReports.
EDIT:
I created a gist with a minimal version of the report that the problem happens:
Sample
I'm exporting it to PDF and using Arial as the font (I added a JAR with the Arial font).
Set the net.sf.jasperreports.export.pdf.force.linebreak.policy property to true (in jasperreports.properties or programmatically). See http://jasperreports.sourceforge.net/config.reference.html#net.sf.jasperreports.export.pdf.force.linebreak.policy
The property instructs the PDF exporter to use java.text.BreakIterator to determine where line breaks can occur in texts, which ensures that the line breaks at PDF export time match the breaks uses when the text was measured at report fill time. As a note, this might come with some impact on PDF exporting performance, but it shouldn't be dramatic.

Jasper Report truncates text before filling the whole text field

I'm having a problem with my PDF report where a String in a text field is truncated before filling the text field. The amount of missing characters (5-6) would not be enough to go over the end of the textField.
I added the text.truncate.at.char property to the report element but the String is still truncated (after displaying some more characters than before).
I also checked if there are other report elements blocking the end of the text field, but there are none.
Lastly I tried a potential fix I found and added "\n" to the end of the line, but that also did not help.
In iReport Designer the whole String is displayed.
PDF report
iReport Designer Preview
Does anyone know how to make Jasper Reports use the whole space in the text field?
PS: Allowing the text to overflow to the next line is not possible due to customer wishes.
I'm using Jasper Reports 5.5.2.
Edit:
The textField is part of a detail band in a subreport. I'm not allowed to share the whole .jrxml, but this is the code for the textField:
<textField>
<reportElement style="Unicode" mode="Opaque" x="0" y="2" width="467" height="17" forecolor="#FFFFFF" backcolor="#00007F" uuid="e810d7a4-6802-4620-af2f-4c385a9e80a6">
<property name="net.sf.jasperreports.text.truncate.at.char" value="true"/>
</reportElement>
<textElement verticalAlignment="Middle" markup="none">
<font size="10" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[" More Details - "+$F{Description} + " ("+$F{Id}+")"]]></textFieldExpression>
</textField>
The description is of variable length, the Id is a GUID. In this case there should still be more than enough space in the textField to display the whole GUID.
Here is another screenshot with isStretchWithOverflow="true":
The text is now displayed completely in the first line but the textField is larger which is not accepted by the customer.
Why is it different in pdf and iReport designer?
This is because iText (the library creating your pdf) is doing its "best effort" to render the font you have indicated in jrxml and its not good enough (it is using another font that is bigger...).
To avoid these problems you need to use font extensions and check your settings on style and textElement
Checklist to rendered font correctly in pdf
How to add font extension using iReport
OP solved as in comment:
Font extension installed, removing isBold="true" on textElement, since the style set to textElement had isBold="false"

How can I display "$£Ω€απ⅔" in Jasperserver PDF using iReport?

I've hardcoded a Text field with the value
":$£Ω€απ⅔:"
to test if these characters will show in PDF
But it only prints as
:$£€:
I've tried changing the font to "Symbol" but that does not do the trick.
Note: I'm using iReport 5.5
I tried your characters using font-extensions in iReport, These are the steps that I took
Download (or use one on your pc) your desired ttf font (it need to support the characters), I used dejavu-serif.
Install the font in iReport or in Jasper soft studio (click links to understand how)
I used iReport 5.6 and did set the PDF-Encoding: Idenity-H (unicode with horizontal writing) and embedded the font in pdf. This was the code of my textField
<textField>
<reportElement x="8" y="15" width="100" height="20" uuid="41dc1200-091f-4799-a1d2-4622f88a0e84"/>
<textElement>
<font fontName="DejaVu Serif" size="13"/>
</textElement>
<textFieldExpression><![CDATA[":$£Ω€απ⅔:"]]></textFieldExpression>
</textField>
Export the font extension (this creates a .jar)
Add the jar to your classpath.
Export to pdf and enjoy the result.
This is an example of how to use any arbitrary font, if you like to
use DejaVu Sans or DejaVu Serif you can just include the jasper
report fonts library in classpath, hence these font are already included and mapped in library
I had posted a similar question and the above technique solved my problem, until one fine day I restarted the JasperServer context. I was now getting "PDF encoding not found" error when I tried to export the report to pdf.
To solve this problem I had to copy the iText-Asian.jar and Font-extension.jar in the lib folder of the jasperserver context.
"jasperserver/WEB-INF/lib". Once done restart the context and problem solved.
Hope it helps someone.

Jasper report exported to excel format is not displaying the background colour

I am using jasper reports-4.5.0 . Using this I am generating the reports properly and exporting to different formats like pdf,csv,xls,html. All are working fine except the .xls format. When I export my report to .xls it is not displaying the background colour to the pageheader band. The code I am using is as below. Inside the page header band
<image>
<reportElement mode="Opaque" x="0" y="0" width="236" height="57" backcolor="#E6E6E6"/>
<imageExpression><![CDATA[new File($P{Image}, "images/flower-logo.png")]]></imageExpression>
</image>
To the flower image I am applying the background colour. It is coming in all the other formats except the .xls format. What could be the problem with excel format.
JasperReports XLS exporters only support the standard Excel color palette. I think you can see the color list here. http://dmcritchie.mvps.org/excel/colors.htm