0

I using Jasper to export PDF file in java spring. First, I created report template in Jasper studio, change font as I expect and it display seem good. After that, I use this .jrxml template to export PDF file in java, but the problem is the font of this file is not corresponding to font I have configured. I have tried to change config font in template but it seem not have any effect on java application.

This lead to error when I use Vietnamese like that:

original text: "Chi phí phát triển thuê bao mới"
rendered text: "Chi phí phát trin thuê bao mi"

This is my java code:

public static void createPdfReport() {
    try{
      final InputStream stream = new FileInputStream(new File("/home/abc/JaspersoftWorkspace/MyReports/test_table.jrxml"));
      final JasperReport report = JasperCompileManager.compileReport(stream);
      final Map<String, Object> parameters = new HashMap<>();
      List<Employee> employees = getSource();
      JRBeanCollectionDataSource itemsJRBean = new JRBeanCollectionDataSource(employees);
      parameters.put("ItemDataSource", itemsJRBean);
//      final JRBeanCollectionDataSource source = new JRBeanCollectionDataSource(getSource());
      final JasperPrint print = JasperFillManager.fillReport(report, parameters, new JREmptyDataSource());
      final String filePath = "/home/abc/Documents/Draft/";
      JasperExportManager.exportReportToPdfFile(print, filePath + "test.pdf");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

Can anyone give me a clue to fix that?

Alex K
  • 22,315
  • 19
  • 108
  • 236
NAM
  • 107
  • 3
  • 10

1 Answers1

1

The problem is the machine that you deploy the java system does not have fonts that you config. Please review this article on stack overflow for more understanding: What is the jasperrepots-fonts jar for and how to use it?

Hai NGUYEN
  • 11
  • 2
  • Thank for your answer, but I have use dejavu font, which is available on my OS (I use Linux and check by fc-list command). Therefore, I'm afraid that it isn't my problem. – NAM Jun 09 '21 at 10:12
  • You need to add dejavu font to the machine that you deploy the program or add it in to jasperreports-fonts.jar – Hai NGUYEN Jun 09 '21 at 10:34