Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Jasper reports pdf in chinese

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my project I use jasper reports for pdf and excel. The reports work fine when I export English characters from the database, but when I export Chinese character the report works fine for excel, but no Chinese characters are displayed in pdf.

I have adobe reader 11 installed with language packs for Simplified and traditional chinese.

This is the code where reportfinal.build() function is called which builds the reports:



Next I am also providing the code for build function:-

 
Bartender
Posts: 3648
16
Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy

The font issue isn't in the java code... it's in the jasper report (jrxml) file. You need to choose a font that is Chinese compatible.

If your computer doesn't already have one, search for the font Arial Unicode MS (arialuni.tff). The jar file to embed in your app can be found at http://community.jaspersoft.com/wiki/displaying-east-asian-characters-report-pdf-output

Also i-Text library is needed. It should also come with a jar for Asian fonts (iTextAsian.jar)
 
Karan Saxena
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi buddy ,thanks for the prompt reply,,

I have downloaded the zip for arial unicode font jar ,and has included both arial unicode .jar and itextasian.jar in the buildpath of my web folder .but as I am using

Adhoc Reports ,so do i need to make any additional changes in templates.java file .

Below is the code for the file:-

import static net.sf.dynamicreports.report.builder.DynamicReports.*;

import java.awt.Color;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import com.lowagie.text.Font;

import net.sf.dynamicreports.report.base.expression.AbstractValueFormatter;
import net.sf.dynamicreports.report.builder.HyperLinkBuilder;
import net.sf.dynamicreports.report.builder.ReportTemplateBuilder;
import net.sf.dynamicreports.report.builder.component.ComponentBuilder;
import net.sf.dynamicreports.report.builder.datatype.BigDecimalType;
import net.sf.dynamicreports.report.builder.style.StyleBuilder;
import net.sf.dynamicreports.report.builder.tableofcontents.TableOfContentsCustomizerBuilder;
import net.sf.dynamicreports.report.constant.HorizontalAlignment;
import net.sf.dynamicreports.report.constant.PageOrientation;
import net.sf.dynamicreports.report.constant.PageType;
import net.sf.dynamicreports.report.constant.StretchType;
import net.sf.dynamicreports.report.constant.VerticalAlignment;
import net.sf.dynamicreports.report.definition.ReportParameters;

/**
* @author Ricardo Mariaca (r.mariaca@dynamicreports.org)
*/
public class Templates {
public static final StyleBuilder rootStyle;
public static final StyleBuilder boldStyle;
public static final StyleBuilder italicStyle;
public static final StyleBuilder boldCenteredStyle;
public static final StyleBuilder bold12CenteredStyle;
public static final StyleBuilder bold18CenteredStyle;
public static final StyleBuilder bold22CenteredStyle;
public static final StyleBuilder columnStyle;
public static final StyleBuilder columnTitleStyle;
public static final StyleBuilder groupStyle;
public static final StyleBuilder subtotalStyle;
public static final StyleBuilder aman;

public static final ReportTemplateBuilder reportTemplate1;
public static final ReportTemplateBuilder reportTemplate2;
public static final ReportTemplateBuilder reportTemplate3;
public static final CurrencyType currencyType;
public static final ComponentBuilder<?, ?> dynamicReportsComponent;
public static final ComponentBuilder<?, ?> footerComponent;

static {
rootStyle = stl.style().setPadding(1);
boldStyle = stl.style(rootStyle).bold();
italicStyle = stl.style(rootStyle).italic();
boldCenteredStyle = stl.style(boldStyle).setAlignment(
HorizontalAlignment.CENTER, VerticalAlignment.MIDDLE);
bold12CenteredStyle = stl.style(boldCenteredStyle).setFontSize(12);
bold18CenteredStyle = stl.style(boldCenteredStyle).setFontSize(18);
bold22CenteredStyle = stl.style(boldCenteredStyle).setFontSize(22);
columnStyle = stl.style(rootStyle)
.setVerticalAlignment(VerticalAlignment.JUSTIFIED)
.setBorder(stl.pen1Point())
.setHorizontalAlignment(HorizontalAlignment.CENTER);// to set
// the
// alignment
// of the
// data
columnTitleStyle = stl.style(columnStyle).setBorder(stl.pen1Point())
.setHorizontalAlignment(HorizontalAlignment.CENTER)
.setBackgroundColor(Color.LIGHT_GRAY).bold();
groupStyle = stl.style(boldStyle).setHorizontalAlignment(
HorizontalAlignment.LEFT);
subtotalStyle = stl.style(boldStyle).setTopBorder(stl.pen1Point());
aman = stl.style().setBackgroundColor(Color.WHITE);

StyleBuilder crosstabGroupStyle = stl.style(columnTitleStyle);
StyleBuilder crosstabGroupTotalStyle = stl.style(columnTitleStyle)
.setBackgroundColor(new Color(170, 170, 170));
StyleBuilder crosstabGrandTotalStyle = stl.style(columnTitleStyle)
.setBackgroundColor(new Color(140, 140, 140));
StyleBuilder crosstabCellStyle = stl.style(columnStyle).setBorder(
stl.pen1Point());

TableOfContentsCustomizerBuilder tableOfContentsCustomizer = tableOfContentsCustomizer()
.setHeadingStyle(0, stl.style(rootStyle).bold());

reportTemplate1 = template().setLocale(Locale.ENGLISH)
.setColumnStyle(columnStyle)
.setColumnTitleStyle(columnTitleStyle)
.setGroupStyle(groupStyle).setGroupTitleStyle(groupStyle)
.setSubtotalStyle(subtotalStyle).highlightDetailEvenRows()
.crosstabHighlightEvenRows()
.setCrosstabGroupStyle(crosstabGroupStyle)
.setCrosstabGroupTotalStyle(crosstabGroupTotalStyle)
.setCrosstabGrandTotalStyle(crosstabGrandTotalStyle)
.setCrosstabCellStyle(crosstabCellStyle)
.setTableOfContentsCustomizer(tableOfContentsCustomizer);

reportTemplate2 = template().setLocale(Locale.ENGLISH)
.setColumnStyle(columnStyle)
.setColumnTitleStyle(columnTitleStyle)
.setGroupStyle(groupStyle).setGroupTitleStyle(groupStyle)
.setSubtotalStyle(subtotalStyle).highlightDetailEvenRows()
.setPageFormat(PageType.A1, PageOrientation.LANDSCAPE)
.crosstabHighlightEvenRows()
.setCrosstabGroupStyle(crosstabGroupStyle)
.setCrosstabGroupTotalStyle(crosstabGroupTotalStyle)
.setCrosstabGrandTotalStyle(crosstabGrandTotalStyle)
.setCrosstabCellStyle(crosstabCellStyle)
.setTableOfContentsCustomizer(tableOfContentsCustomizer);

reportTemplate3 = template().setLocale(Locale.ENGLISH)
.setColumnStyle(columnStyle)
.setColumnTitleStyle(columnTitleStyle)
.setGroupStyle(groupStyle).setGroupTitleStyle(groupStyle)
.setSubtotalStyle(subtotalStyle).highlightDetailEvenRows()
.setPageFormat(PageType.A1, PageOrientation.PORTRAIT)
.crosstabHighlightEvenRows()
.setCrosstabGroupStyle(crosstabGroupStyle)
.setCrosstabGroupTotalStyle(crosstabGroupTotalStyle)
.setCrosstabGrandTotalStyle(crosstabGrandTotalStyle)
.setCrosstabCellStyle(crosstabCellStyle)
.setTableOfContentsCustomizer(tableOfContentsCustomizer);

currencyType = new CurrencyType();


dynamicReportsComponent = cmp.horizontalList(cmp
.image(Templates.class
.getResource("/MDMWAR.war/images/imdm.png"))
.setFixedDimension(40, 50)
.setHorizontalAlignment(HorizontalAlignment.LEFT)
.setFixedWidth(40));

footerComponent = cmp.pageXofY().setStyle(
stl.style(boldCenteredStyle).setTopBorder(stl.pen1Point())
.setHorizontalAlignment(HorizontalAlignment.CENTER));

}

/**
* Creates custom component which is possible to add to any report band
* component
*/
public static ComponentBuilder<?, ?> createTitleComponent(String label,String username,String Currentdate,String Beforedate) {

SimpleDateFormat sim = new SimpleDateFormat(
"dd-MMM-yy hh:mm:ss aa");

return cmp
.horizontalList()
.add(dynamicReportsComponent)
.newRow()
.add(cmp.text(label).setStyle(bold18CenteredStyle)
.setHorizontalAlignment(HorizontalAlignment.LEFT))
.newRow()
.add(cmp.horizontalList(cmp.text(
"Report Generated On : " +sim.format(new Date()) +" by "+username+" for the period "+Beforedate+" to "+Currentdate+"").setStyle(
stl.style(boldCenteredStyle)
.setTopBorder(stl.pen1Point())
.setHorizontalAlignment(
HorizontalAlignment.LEFT)))).newRow()

;
}

public static CurrencyValueFormatter createCurrencyValueFormatter(
String label) {
return new CurrencyValueFormatter(label);
}

public static class CurrencyType extends BigDecimalType {
private static final long serialVersionUID = 1L;

@Override
public String getPattern() {
return "$ #,###.00";
}
}

private static class CurrencyValueFormatter extends
AbstractValueFormatter<String, Number> {
private static final long serialVersionUID = 1L;

private String label;

public CurrencyValueFormatter(String label) {
this.label = label;
}

@Override
public String format(Number value, ReportParameters reportParameters) {
return label
+ currencyType.valueToString(value,
reportParameters.getLocale());
}
}
}
 
Karan Saxena
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
one thing more the arialUnicode .jar zip included two other files namely -report24775-eastAsian.jrxml ,,,and report24775-eastAsian.jasper.please help what to do with these .

I am new to jasper ,please help asap ...urgently required.
 
K. Tsang
Bartender
Posts: 3648
16
Mac OS X Firefox Browser Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the jar file, only the jar is needed. The other files are not needed in your app.

As for Dynamic Reports, I haven't used it, I think it should be similar, change the font inside the actual report.
 
Karan Saxena
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks buddy will surely try out your solution and let you know
 
Karan Saxena
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I tried what you said but didnt get to work

then i found the link
http://www.dynamicreports.org/documentation/fonts

Similarly i created a fonts.xml file and a jasperreports_extension.properties file under my webinf folder

but i wasnt able to get it working

here is the code for

fonts.xml:-
<?xml version="1.0" encoding="UTF-8"?>
<fontFamily name="Arial Unicode MS">
<normal>net.sf.jasperreports.engine.fonts.SimpleFontFamily</normal>
<bold>net.sf.jasperreports.engine.fonts.SimpleFontFamily</bold>
<italic>net.sf.jasperreports.engine.fonts.SimpleFontFamily</italic>
<boldItalic>net.sf.jasperreports.engine.fonts.SimpleFontFamily</boldItalic>

<pdfEmbedded>true</pdfEmbedded>
</fontFamily>

Here is the code for jasperreports_extension.properties

net.sf.jasperreports.extension.registry.factory.simple.font.families=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory
net.sf.jasperreports.extension.simple.font.families.drfonts=fonts.xml

Please whats wrong with the approach..
 
Today you are you, that is turer than true. There is no one alive who is youer than you! - Seuss. Tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic