Reputation: 379
I am trying to display greek letters in PDF generated by jasperreport. First I create XML, then xml datasource and pass it to jaspper. XML:
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
....
Element analysisElement = doc.createElement("Analysis");
//text value is from the database
Text analysisText = doc.createTextNode(anayisisObject.getName());
analysisElement.appendChild(analysisText);
Datasource:
JRXmlDataSource xmlDataSource = new JRXmlDataSource(doc,"/ReportFailedAnalysis");
JRXML textField:
<textField isStretchWithOverflow="true">
<reportElement style="obicni" positionType="Float" x="0" y="0" width="203" height="12"/>
<textElement markup="styled">
<font fontName="Arial" size="9" pdfEncoding="Cp1250"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{Analysis}]]>
</textFieldExpression>
</textField>
Database encoding is Cp1250 if that is important and greek letters are saved as html encoding for example Γ. If I just pass that value, xml probably alter & to &, and i get Γ in my pdf. If I replace it with utf character \u03C6, I get "?" in my PDF. I know there is a way to display that field becaise when I export XML to file, change character from &#x393; back to Γ , import it as a datasource in iReport, I get the letter I wantad.
Upvotes: 3
Views: 1653
Reputation: 379
After some reasearch I have discovered that PDF fonts are the cause of the problem. I have been using version 3.6, so i switched to version 3.7, to be able to embed fonts in PDF and used the method described on the blog: Link. I have used solution number 2(the easy way), but be sure to check solution number 1 in order to chose right fonts for bold, italic etc. Arial font was quite enough for me.
Upvotes: 1