Skip to Main Content

Developer Community

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Switching the font on jasper report on runtime | adf integration with oracle adf | JDeveloper

Rajat AnandOct 24 2024 — edited Oct 24 2024

We have one requirement to switch the font of jasper report on runtime on the basis language selected by user over the application. i.e. either English or Arabic

I did tried couple of way to achieve this from jasper report itself and while calling the jasper report from oracle adf.

I did create both the fonts jar and attach on project library and tried to pass this font using following code, but it didn't work.

private SimpleJasperReportsContext setDynamicFont(boolean isArabic) {

  SimpleJasperReportsContext jasperReportsContext = new SimpleJasperReportsContext();

  SimpleFontFamily fontFamily = new SimpleFontFamily(jasperReportsContext);

   if(isArabic)

      fontFamily.setName("Calibri");//to be used in reports as fontName

   else

      fontFamily.setName("Sakkal Majalla");//to be used in reports as fontName

  //fontFamily.setPdfEmbedded(true);

  //fontFamily.setPdfEncoding("Identity-H");

   SimpleFontFace regular = new SimpleFontFace(jasperReportsContext);

   if(isArabic)

      regular.setTtf("E:\\\\Rajat\\\\eNOCReportIntegration\\\\ViewController\\\\public\_html\\\\WEB-INF\\\\lib\\\\SakkalMajalla.jar");

   else

      regular.setTtf("E:\\\\Rajat\\\\eNOCReportIntegration\\\\ViewController\\\\public\_html\\\\WEB-INF\\\\lib\\\\Calibri.jar");

  fontFamily.setNormalFace(regular);

  jasperReportsContext.setExtensions(FontFamily.class, Arrays.asList(fontFamily));

   return jasperReportsContext;

}

SimpleJasperReportsContext jasperReportsContext = setDynamicFont(locale.getLanguage().equals("ar"));

report = JasperCompileManager.compileReport(design);

report.setProperty(TimeoutGovernor.PROPERTY_TIMEOUT, "60000");

report.setProperty(TimeoutGovernor.PROPERTY_TIMEOUT_ENABLED, "true");

print =JasperFillManager.getInstance(jasperReportsContext).getfillReport(report, param, conn);

ByteArrayOutputStream baos = new ByteArrayOutputStream();

JasperExportManager.getInstance(jasperReportsContext).exportReportToPdfStream(print, baos);

Also tried a way to solve this from jasper report itself. In this scenario, I create the conditional style over the jasper report code and write condition using the parameter that decides the language that user wants in output report i.e. either English or Arabic

In this I create two conditions if bindLocale == “AR” then font is Sakkal Majalla else if bindLocale == “EN” then font is Calibri

Now use this style with all the fields created over the report and their sub reports, but didn’t give expected output.

What is the correct way to solve this issue and complete this requirement. Please help me to resolve and complete this implementation.

Comments
Post Details
Added on Oct 24 2024
0 comments
68 views