Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with static text encoding if default encoding in JVM is not UTF-8 #687

Open
mnyakushev opened this issue Aug 21, 2024 · 0 comments
Milestone

Comments

@mnyakushev
Copy link
Contributor

Sample code to reproduce problem:

    public static void main(String[] args) throws Exception {
        System.out.println(System.getProperty("file.encoding"));
        
        Path templatePath = Paths.get("C:\\Temp\\template.docx");
        Path reportPath = Paths.get("C:\\Temp\\report.docx");

        byte[] templateBytes = Files.readAllBytes(templatePath);
        InputStream templateInputStream = new ByteArrayInputStream(templateBytes);

        IXDocReport template = XDocReportRegistry.getRegistry()
                .loadReport(templateInputStream, "test", TemplateEngineKind.Velocity);
        
        try (OutputStream out = Files.newOutputStream(reportPath)) {
            IContext context = template.createContext();
            template.process(context, out);
        }
    }

template.docx

This code with JVM option -Dfile.encoding=CP1251 produces report with broken encoding.

Template content:
image

Expected result:
image

Actual result:
image

Problem was fixed for me when I started to use encoding parameter in method getResourceReader of class XDocReportEntryResourceLoader

Instead of line return new InputStreamReader(inputStream); I used return new InputStreamReader(inputStream, Charset.forName(encoding));

This was referenced Aug 21, 2024
@angelozerr angelozerr modified the milestones: 2.0.7, 2.11.0 Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants