I rate apache poi as being able to write docx files. The specific thing I'm looking for is to generate content in the docx file in different languages (e.g. Hindi / Marathi). I ran into the following problem:
When a docx file is written, the text “Hindi / Marathi” is displayed as square squares, even if it is supported by the font “Arial Unicode MS”. The fact is that when checking boxes, MS Word displays the font as "Cailbri", although I explicitly set the font to "Arial Unicode MS". If I select the boxes in MS Word, and then change the font to "Arial Unicode MS", the Hindi / Marathi words will be visible correctly. Any idea why this is happening? Please note that I am using the POI version for development, as the previous stable version does not support customization of font families. Here is the source:
import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFParagraph; import org.apache.poi.xwpf.usermodel.XWPFRun; public class CreateDocumentFromScratch { public static void main(String[] args) { XWPFDocument document = new XWPFDocument(); XWPFParagraph paragraphTwo = document.createParagraph(); XWPFRun paragraphTwoRunOne = paragraphTwo.createRun(); paragraphTwoRunOne.setFontFamily("Arial Unicode MS"); paragraphTwoRunOne.setText("नसल्यास"); XWPFParagraph paragraphThree = document.createParagraph(); XWPFRun paragraphThreeRunOne = paragraphThree.createRun(); paragraphThreeRunOne.setFontFamily("Arial Unicode MS"); paragraphThreeRunOne.setText("This is nice"); FileOutputStream outStream = null; try { outStream = new FileOutputStream("c:/will/First.doc"); } catch (FileNotFoundException e) { e.printStackTrace(); } try { document.write(outStream); outStream.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
Any help would be appreciated.
source share