0

我正在使用水晶报表生成不同格式的文件(pdf、excel、word)。我在发送电子邮件时导出的 .rpt 文件。我在以 PDF 附件形式发送电子邮件时遇到问题。日文字符显示为方框。当我作为 Excel 或 Word 附件发送时,可以看到日文字符。

对于解决方案,我在谷歌搜索并知道这是导出为 PDF 时水晶报表的字体问题,我们需要为日文字符提供“MS Gothic”字体。我在“水晶reposrt设计师”中为特定领域尝试了同样的事情,现在效果很好。

但这不是我想要的解决方案,因为那里有数千个报告(.rpt 文件),并且每个字段都有很多,因此对每个报告中的每个字段都这样做是不可行的。

所以我想在我的 .pdf 文件的 java 代码中以编程方式进行。

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();
    }

我仍然用那些方盒代替日文字符。需要帮忙。我认为修改方法需要一些更改。

4

1 回答 1

0

我认为这不会以编程方式工作。在我们公司,我们也得出结论,我们必须更改报告中的字体。:-(

另外我不建议它以编程方式进行。每种字体都不一样。当我进行报告并将所有字段从“Tahoma”更改为“Verdana”时,这些字段会移位、变长、重叠等等。同样的情况也可能发生在这里。

也许您不必更改所有数千份报告。也许只有那些包含带有日文字符的字段并且经常使用的字段。

于 2021-05-08T11:10:39.853 回答