Crystal report PDF font issue for japanese characters using Java

613 views Asked by At

I am using crystal report for generating different format files(pdf, excel, word). The .rpt files i am exporting while sending emails. I am facing issue while sending emails as PDF attachment. Japanese characters are showing as box. When am sending as Excel or Word attachment, am able to see the japanese characters.

For solution, i searched in google and came to know this is font issue of crystal report when exported as PDF, and we need to give "MS Gothic" font for japanese characters. I tried the same thing for a particular field in the "crystal reposrt designer" and now that is working fine.

But this is not the solution which i wanted because there are thousands of reports(.rpt files) are there and in each many fields are there, so its not feasible to do that for each field in each report.

So i wanted to do it programmatically in my java code for .pdf file.

private void exportReport(HttpSession session, HttpServletRequest req, ReportClientDocument rptDoc, String sReport)
        throws Exception
    {
        String sExportType = req.getParameter("cmbExportTypes");
        
        if (sReport == null)
            sReport = (String) session.getValue("selected_report");
            
        sReport = Util.removeEndingChar(sReport, ".rpt");
        
        String sExtension = "";
        
        if (sExportType.toLowerCase().indexOf("word") != -1)
            sExtension = ".doc";
        else if (sExportType.toLowerCase().indexOf("excel") != -1)
            sExtension = ".xls";
        else if (sExportType.toLowerCase().indexOf("pdf") != -1)
            sExtension = ".pdf";
        else if (sExportType.toLowerCase().indexOf("rtf") != -1)
            sExtension = ".rtf";
        else if (sExportType.toLowerCase().indexOf("report") != -1)
            sExtension = ".rpt";
            
        String sFileName = sReport + sExtension;
        FileType file = new FileType(-1, sFileName, false);
        
        FieldObject fieldObject = new FieldObject();
        IFontColor fontColor = fieldObject.getFontColor();
        IFont iFont = fontColor.getIFont();
        iFont.setName("MS Gothic");
        iFont.setSize(9.5f);
        
        //rptDoc.getReportDefController().getReportObjectController().modify(fieldObject ,fieldObject);
        
        // 07/03/2012 EA: PR #15087  -- Support Crystal Reports 2008 SP5
        InputStream  byteIS = rptDoc.getPrintOutputController().export(ReportExportFormat.from_string(sExportType));
        EmailAttachment attachment = new EmailAttachment(byteIS, file.type, sFileName);
        session.putValue("report_attachment", attachment);
        
        rptDoc.close();
    }

am still getting those square box in place of japanese characters. Need help. I think the modify method needs some changes.

1

There are 1 answers

1
Razilein On

I don't think this would work programmatically. In our company we also came to the conclusion that we have to change the font in the report. :-(

Also I wouldn't recommend it to do it programmatically. Every font is different. When I take a report and change all field from "Tahoma" to "Verdana", the fields are displaced, to long, overlapping and so on. The same could happen here.

Maybe you don't have to change all thousand reports. Maybe only the ones which include fields with japanese characters and are often used.