Cannot replace Arabic Apache POI characters in MS Word file

I need to dynamically modify Word files with values โ€‹โ€‹from a database or enter by user. Values โ€‹โ€‹and files are in Arabic.

The problem is that it does not work all the time. Each time I come across a new and different problem with Arabic characters.

The code I'm using is:

        FileInputStream in = new FileInputStream(path+"\\fiches\\"+fileName.trim()+".doc");
        POIFSFileSystem fs = new POIFSFileSystem(in);
        HWPFDocument doc = new HWPFDocument(fs);
        Range  r = doc.getRange();
         r.replaceText("<matricule>","  "+agent.getMatriculeAgent());
        r.replaceText("<cin>","  "+agent.getCin());
        r.replaceText("<ุงู„ุฅุณู… ุงู„ุดุฎุตูŠ>", " "+agent.getPrenomAgentArabe());
        OutputStream out = response.getOutputStream();
        response.setContentType("application/rtf");
        response.setHeader("Content-Disposition","attachment; filename="+fileName);
        doc.write(out);
        out.flush();
+5
source share
1 answer

Unfortunately, this was not a poi problem, the origin of the problem was the temple that I used, I realized that text areas or some word functions can cause this, the template should be the simplest, for example: a word in the text is a zone inserted in a table, may create strange behavior or may not be tolerated,

0
source

All Articles