Use FileOutputStream to Create a UTF-8 PDF File

I use JasperReports and DynamicReports with this piece of java code to generate a pdf report that contains utf-8 characters, the problem is that the pdf file does not contain utf-8 characters at all, as if they were replaced with "" . is there anything i need to know when using OutputStream to create a utf-8 file?

    public void toPdf(String path){
        OutputStream outHtml;
        try {
            outHtml = new FileOutputStream(path);

            jasperBuilder.toPdf(outHtml);
        } catch (Exception e1) {
            logger.error("failed to create PDF", e1);
        }
}

it may be noteworthy that creating XLS and HTML files does not encounter such a problem.

Note that there are many lines of code under jasperBuilder.toPdf(outHtml);that I have traced, and no where utf-8 characters are removed in these lines. so I guess the devil is inoutHtml = new FileOutputStream(path);

+3
2

, . , <pdfEncoding>UTF-8</pdfEncoding> <pdfEncoding>Identity-H</pdfEncoding> fonts.xml

<fontFamilies>
  <fontFamily name="FreeUniversal">
    <normal>/home/moien/tahoma.ttf</normal>
    <bold>/home/moien/tahoma.ttf</bold>
    <italic>/home/moien/tahoma.ttf</italic>
    <boldItalic>/home/moien/tahoma.ttf</boldItalic>
    <pdfEncoding>Identity-H</pdfEncoding>
    <pdfEmbedded>true</pdfEmbedded>
  </fontFamily>
</fontFamilies> 

, URL- !

+4

A FileOutputStream "", . . , , , .

, / jasperBuilder .

+2

All Articles