0

I'm using jasper 0.6.0 version and itext 1.0.1. I'm using MS Mincho jar file and itextasian and itextasiancmaps jar file. it is printing japanese characetrs as ??? in PDF

Later i upgraded the Jasper version to 6.0.0 and itext version to 5.50 still it is printing as ???

i've attached the Java Source code and jrxml. is there a problem with my jrxml or do i need some other jars to support these characters on PDF

    <?xml version="1.0" encoding="UTF-8"?>
    // for 0.6.0 version Doctype
    <!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD Report Design//EN" "http://www.jasperreports.com/dtds/jasperreport.dtd">
    // for 6.0.0 version Doctype
    <!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">

    <jasperReport name="Roster" columnCount="1" printOrder="Vertical" pageWidth="635" pageHeight="842" columnWidth="270" columnSpacing="15" leftMargin="20" rightMargin="20" topMargin="30" bottomMargin="30" isTitleNewPage="false" isSummaryNewPage="false">
    <reportFont name="Arial_Normal" isDefault="true" fontName="Arial" size="10" pdfFontName="Helvetica" pdfEncoding="UTF-8" isPdfEmbedded="true"/>
    <reportFont name="Arial_Bold" isDefault="true" fontName="Arial" size="10" pdfFontName="Helvetica" pdfEncoding="UTF-8" isPdfEmbedded="true" isBold="true"/>
    <parameter name="TestDate" class="java.lang.String"/>
    <parameter name="TestCenter" class="java.lang.String"/>
    <parameter name="Session" class="java.lang.String"/>
    <parameter name="SessionId" class="java.lang.Integer"/>
    <parameter name="ProctorName" class="java.lang.String"/>
    <field name="ID" class="java.lang.String"/>
    <field name="CandidateName" class="java.lang.String"/>
    <field name="TestPortion" class="java.lang.String"/>
    <field name="SeatNo" class="java.lang.String"/>
    <field name="TestForm" class="java.lang.String"/>
    <field name="PaperAndPencil" class="java.lang.String"/>
    <field name="ExtendedTime" class="java.lang.Integer"/>
    <field name="CreditCardNumberString" class="java.lang.String"/>
    <field name="AmountPaidAndDateOfPaymentString" class="java.lang.String"/>
    <field name="AllCreditsFinalMessageString" class="java.lang.String"/>
    <field name="IAgreeToPayMessageString" class="java.lang.String"/>
    <field name="SessionId" class="java.lang.Integer"/>
    <variable name="ExamPortionsStr" class="java.lang.String" resetType="None" calculation="Nothing">
        <variableExpression>"Exam Portion(s)"</variableExpression>
        <initialValueExpression>"Exam Portion(s)"      </initialValueExpression>
    </variable>

    <group name="Candidate" minHeightToStartNewPage="200">
        <groupExpression>121</groupExpression>
        <groupHeader>
            <band/>
        </groupHeader>
        <groupFooter>
            <band height="125">
                <line>
                    <reportElement x="0" y="110" width="595" height="0" forecolor="#999999" positionType="Float"/>
                    <graphicElement stretchType="NoStretch" pen="Thin"/>
                </line>
            </band>
        </groupFooter>
    </group>
    <title>
        <band height="43">
            <staticText>
                <reportElement x="0" y="0" width="595" height="23"/>
                <textElement textAlignment="Center">
                    <font reportFont="Arial_Bold" size="15"/>
                </textElement>
                <text>PSI EXAMINATION SERVICES</text>
            </staticText>
            <staticText>
                <reportElement x="0" y="25" width="595" height="15"/>
                <textElement textAlignment="Center">
                    <font reportFont="Arial_Normal" size="10"/>
                </textElement>
                <text>Examination Roster</text>
            </staticText>
            <line>
                <reportElement x="0" y="40" width="595" height="0" forecolor="#000000"/>
                <graphicElement stretchType="NoStretch"/>
            </line>
        </band>
    </title>
    <pageHeader>
        <band height="40">
            <textField>
                <reportElement x="0" y="0" width="200" height="12"/>
                <textElement textAlignment="Left">
                    <font size="10"/>
                </textElement>
                <textFieldExpression class="java.lang.String">"Test Date : 05/04/2016" </textFieldExpression>
            </textField>
            <textField>
                <reportElement x="390" y="0" width="200" height="12"/>
                <textElement textAlignment="Right">
                    <font size="10"/>
                </textElement>
                <textFieldExpression class="java.lang.String">"Proctor : Ganesh "</textFieldExpression>
            </textField>
            <textField>
                <reportElement x="0" y="17" width="200" height="12"/>
                <textElement textAlignment="Left">
                    <font size="10"/>
                </textElement>
                <textFieldExpression class="java.lang.String">"Session : Morning "</textFieldExpression>
            </textField>
            <textField>
                <reportElement x="200" y="17" width="200" height="12"/>
                <textElement textAlignment="Left">
                    <font size="10"/>
                </textElement>
                <textFieldExpression class="java.lang.String">"Session # : 1 " </textFieldExpression>
            </textField>            
            <textField>
                <reportElement x="390" y="17" width="200" height="12"/>
                <textElement textAlignment="Right">
                    <font size="10"/>
                </textElement>
                <textFieldExpression class="java.lang.String">"Test Center : Akron " </textFieldExpression>
            </textField>
        </band>
    </pageHeader>
    <columnHeader>
        <band height="20">
            <rectangle>
                <reportElement x="0" y="0" width="595" height="15" backcolor="#555555"/>
                <graphicElement stretchType="NoStretch"/>
            </rectangle>
            <staticText>
                <reportElement x="0" y="2" width="50" height="15" forecolor="#FFFFFF"/>
                <textElement textAlignment="Center">
                    <font reportFont="Arial_Normal" size="10"/>
                </textElement>
                <text>ID</text>
            </staticText>
            <staticText>
                <reportElement x="55" y="0" width="100" height="15" forecolor="#FFFFFF"/>
                <textElement textAlignment="Center">
                    <font reportFont="Arial_Normal" size="10"/>
                </textElement>
                <text>Candidate Name</text>
            </staticText>
            <staticText>
                <reportElement x="325" y="0" width="50" height="15" forecolor="#FFFFFF"/>
                <textElement textAlignment="Center">
                    <font reportFont="Arial_Normal" size="10"/>
                </textElement>
                <text>Seat</text>
            </staticText>
            <staticText>
                <reportElement x="380" y="0" width="50" height="15" forecolor="#FFFFFF"/>
                <textElement textAlignment="Center">
                    <font reportFont="Arial_Normal" size="10"/>
                </textElement>
                <text>Test Form</text>
            </staticText>
            <staticText>
                <reportElement x="435" y="0" width="70" height="15" forecolor="#FFFFFF"/>
                <textElement textAlignment="Center">
                    <font reportFont="Arial_Normal" size="10"/>
                </textElement>
                <text>Test Mode</text>
            </staticText>
            <staticText>
                <reportElement x="510" y="0" width="85" height="15" forecolor="#FFFFFF"/>
                <textElement textAlignment="Left">
                    <font reportFont="Arial_Normal" size="10"/>
                </textElement>
                <text>Extended Time</text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="13">
            <textField isStretchWithOverflow="true">
                <reportElement x="0" y="0" width="65" height="10"/>
                <textElement textAlignment="Center"/>
                <textFieldExpression class="java.lang.String">
                   <![CDATA["1"]]>
                </textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true">
                <reportElement x="70" y="0" width="260" height="10" />
                <textElement textAlignment="Left">
                    <font fontName="MS Mincho"/>
                </textElement>
                <textFieldExpression class="java.lang.String">
                    <![CDATA["ガネーシュ"]]>
                </textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true">
                <reportElement x="0" y="12" width="90" height="10" positionType="Float"/>
                <textElement textAlignment="Left">
                    <font reportFont="Arial_Bold"/>
                </textElement>
                <textFieldExpression class="java.lang.String">
                   <![CDATA["Nothing"]]>
                </textFieldExpression>
            </textField>          
            <textField isStretchWithOverflow="true">
                <reportElement x="110" y="12" width="485" height="10" positionType="Float"/>
                <textElement textAlignment="Left">
                    <font reportFont="Arial_Bold"/>
                </textElement>
                <textFieldExpression class="java.lang.String">
                    <![CDATA["Nothing"]]>
                </textFieldExpression>
            </textField>
            <textField isBlankWhenNull="true" isStretchWithOverflow="true">
                <reportElement x="325" y="0" width="50" height="10"/>
                <textElement textAlignment="Left">
                    <font reportFont="Arial_Bold"/>
                </textElement>
                <textFieldExpression class="java.lang.String">
                    <![CDATA["10"]]>
                </textFieldExpression>
            </textField>
            <textField isBlankWhenNull="true" isStretchWithOverflow="true">
                <reportElement x="380" y="0" width="50" height="10"/>
                <textElement textAlignment="Center">
                    <font reportFont="Arial_Bold"/>
                </textElement>
                <textFieldExpression class="java.lang.String">
                    <![CDATA["Good"]]>
                </textFieldExpression>
            </textField>
            <textField isBlankWhenNull="true" isStretchWithOverflow="true">
                <reportElement x="435" y="0" width="70" height="10"/>
                <textElement textAlignment="Center">
                    <font reportFont="Arial_Bold"/>
                </textElement>
                <textFieldExpression class="java.lang.String">
                    <![CDATA["Nothing"]]>
                </textFieldExpression>
            </textField>
            <textField isBlankWhenNull="true" isStretchWithOverflow="true">
                <reportElement x="510" y="0" width="85" height="10"/>
                <textElement textAlignment="Left"/>
                <textFieldExpression class="java.lang.Integer">
                   <![CDATA[10]]>
                </textFieldExpression>
            </textField>
            <textField isBlankWhenNull="true" isStretchWithOverflow="true">
                <reportElement x="0" y="50" width="180" height="10"/>
                <textElement textAlignment="Left"/>
                <textFieldExpression class="java.lang.String">
                    <![CDATA["Nothing"]]>
                </textFieldExpression>
            </textField>
            <textField isBlankWhenNull="true" isStretchWithOverflow="true">
                <reportElement x="0" y="65" width="300" height="10"/>
                <textElement textAlignment="Left"/>
                <textFieldExpression class="java.lang.String">
                    <![CDATA["Nothing"]]>
                </textFieldExpression>
            </textField>
            <textField isBlankWhenNull="true" isStretchWithOverflow="true">
                <reportElement x="0" y="80" width="300" height="10"/>
                <textElement textAlignment="Left"/>
                <textFieldExpression class="java.lang.String">
                    <![CDATA["Nothing"]]>
                </textFieldExpression>
            </textField>
            <textField isBlankWhenNull="true" isStretchWithOverflow="true">
                <reportElement x="0" y="95" width="400" height="10"/>
                <textElement textAlignment="Left"/>
                <textFieldExpression class="java.lang.String">
                    <![CDATA["Nothing"]]>
                </textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="350" y="35" width="250" height="12"/>
                <textElement textAlignment="Right">
                    <font reportFont="Arial_Normal" size="9"/>
                </textElement>
                <text>Examinee Signature:________________________</text>
            </staticText>            
            <staticText>
                <reportElement x="350" y="65" width="250" height="12"/>
                <textElement textAlignment="Right">
                    <font reportFont="Arial_Normal" size="9"/>
                </textElement>
                <text>Narrative/Fact Sheet:________________________</text>
            </staticText>
            <staticText>
                <reportElement x="350" y="95" width="250" height="12"/>
                <textElement textAlignment="Right">
                    <font reportFont="Arial_Normal" size="9"/>
                </textElement>
                <text>Proctor Verification:________________________</text>
            </staticText>            
    </band>
    </detail>
    <columnFooter>
        <band/>
    </columnFooter>
    <pageFooter>
        <band/>
    </pageFooter>
    <summary>
        <band/>
    </summary>
</jasperReport>

and Java code,

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;


public class PdfFromXmlFile {
  public static void main(String[] args) throws JRException, IOException {
     JasperReport jasperReport =JasperCompileManager.compileReport("C:\\Users\\gbhagavath\\Downloads\\StyledTextReport/StyledTextReport2.jrxml");
   // Parameters for report
   Map<String, Object> parameters = new HashMap<String, Object>();

   // DataSource
   // This is simple example, no database.
   // then using empty datasource.
   JRDataSource dataSource = new JREmptyDataSource();

   JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,parameters, dataSource);

   // Make sure the output directory exists.
   File outDir = new File("C:/jasperoutput");
   outDir.mkdirs();

   // Export to PDF.
   JasperExportManager.exportReportToPdfFile(jasperPrint,"C:/jasperoutput/StyledTextReport.pdf");

   System.out.println("Done!");
   }
  }

Where i am missing? or what i need to do fix this issue

 <?xml version="1.0" encoding="UTF-8"?>
    <!-- Created with Jaspersoft Studio version 6.3.1.final using JasperReports Library version 6.3.1  -->
    <!-- 2017-04-04T14:33:09 -->
    <!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
    <jasperReport name="StyledTextReport" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="30" bottomMargin="30">
    <title>
        <band height="640">
            <staticText>
                <reportElement x="14" y="63" width="521" height="24"/>
                <textElement>
                    <font fontName="MS Mincho" size="15"/>
                </textElement>
                <text><![CDATA[Cyrillic: 芒果]]></text>
            </staticText>
            <textField>
                <reportElement x="0" y="150" width="555" height="60" />
                <textElement textAlignment="Center">
                    <font size="16"/>
                </textElement>
                <textFieldExpression><![CDATA["This is a text field element that contains styled text displaying the text-only version of the <style size=\"12\" isBold=\"true\" forecolor=\"black\" pdfFontName=\"Helvetica-Bold\">^<style forecolor=\"#808080\">Jasper</style><style forecolor=\"#990000\">Reports</style></style> logo."]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement mode="Opaque" x="0" y="220" width="270" height="320" backcolor="#CCFFCC" />
                <textElement>
                    <font size="16"/>
                </textElement>
                <text><![CDATA[Here is the list with the attributes supported by the <style isBold="true" pdfFontName="Helvetica-Bold">style</style> tag used to format the text content inside a styled text element:

           fontName
       <style size="32">size</style>
       <style isBold="true" pdfFontName="Helvetica-Bold">isBold</style>
       <style isItalic="true" pdfFontName="Helvetica-Oblique">isItalic</style>
       <style isUnderline="true">isUnderline</style>
       <style isStrikeThrough="true">isStrikeThrough</style>
       <style pdfFontName="Helvetica-Bold">Helvetica-Bold</style>
       <style pdfEncoding="UTF-8">芒果</style>
       <style isPdfEmbedded="false">false</style>

     <style forecolor="red">forecolor</style>
     <style backcolor="blue" forecolor="white" isBold="true" pdfFontName="Helvetica-Bold" pdfEncoding="UTF-8" isPdfEmbedded="false">backcolor</style>]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="280" y="220" width="270" height="320" backcolor="#CCFFCC"/>
                <textElement>
                    <font fontName="MS Mincho" size="16"/>
                </textElement>
                <text><![CDATA[Here is the list with the supported HTML tags 芒果  : 

       <font size="12">&amp;lt;font size=&amp;quot;12&amp;quot;&amp;gt;</font>
       <font color="red">&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;</font>
       <font face="Comic Sans MS">&amp;lt;font face=&amp;quot;Comic Sans MS&amp;quot;&amp;gt;</font>
       <b>bold</b>
        <i>italic</i>
      <u>underlined</u>
       an empty line follows(&amp;lt;br/&amp;gt;):
         <br/>
        A bulleted list:
        <li>item 1</li>
        ]]></text>
            </staticText>
            <textField>
                <reportElement x="0" y="550" width="555" height="20" />
                <textElement textAlignment="Center">
                    <font size="16"/>
                </textElement>
                <textFieldExpression><![CDATA["ampersand &amp;amp; less &amp;lt; greater &amp;gt; quote &amp;quot;"]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="0" y="580" width="555" height="20" />
                <textElement textAlignment="Center" >
                    <font size="16"/>
                </textElement>
                <text><![CDATA[ampersand &amp;amp; less &amp;lt; greater &amp;gt; quote &amp;quot;]]></text>
            </staticText>
            <textField isStretchWithOverflow="true">
                <reportElement mode="Opaque" x="0" y="610" width="555" height="20" forecolor="#0000FF" backcolor="#FFFF00"/>
                <textElement textAlignment="Center" />
                <textFieldExpression><![CDATA["<style size=\"16\">1</style>\n<style size=\"24\">2</style>\n<style size=\"32\">3</style>\n<style size=\"24\">2</style>\n<style size=\"16\">1</style>\n"]]></textFieldExpression>
            </textField>
        </band>
    </title>
</jasperReport>
  • Are you using font extensions? – Alex K Apr 06 '17 at 07:05
  • Possible duplicate of [Jasper Reports PDF doesn't export cyrillic values](http://stackoverflow.com/questions/34041619/jasper-reports-pdf-doesnt-export-cyrillic-values) – Alex K Apr 06 '17 at 07:13
  • Yes i'm using MS Mincho fonts jar – GaneshBhagavath Apr 06 '17 at 07:27
  • Should work in this case. You can try to debug with attached JasperReports source code and check the availability of your font (I don't remember the name of class). Maybe your font definition file at font's *jar* is a little bit wrong – Alex K Apr 06 '17 at 07:30
  • It Is working in other jrxml file.. I'm using same jasper report 6.0, itext 5.50, and MS Mincho Jar.. and i'm able to display characters proeprly in the PDF.. but in the above jrxml it is displaying as ???? – GaneshBhagavath Apr 06 '17 at 07:33
  • Does 0.6.0 jasper will support Unicode characters? or which version i need to use? – GaneshBhagavath Apr 06 '17 at 07:33
  • So legacy... I don't remember about *0.6* version, but it works since *3.x* (or even *2.x*) version as I remembering. It is better to use the last version (*6.x*) – Alex K Apr 06 '17 at 07:37
  • but in 6.0.0 also it is printing as ???.Dont know what is the issue. – GaneshBhagavath Apr 06 '17 at 07:40
  • It is a working solution. Maybe something wrong with your classpath/font jar. The best way is to debug – Alex K Apr 06 '17 at 07:46
  • I Did, I;ve added MS Mincho fonts jar in classpath and it is working with Other jrxml with JR-6.0.0 but the above jrxml is not able to print Japanese characters properly to PDF using JR-6.0. It is printing as ??? – GaneshBhagavath Apr 06 '17 at 07:50
  • I've added the other jrxml in the above question, please check – GaneshBhagavath Apr 06 '17 at 07:52

0 Answers0