Envirment: word2007 on windows7.
I parse a word(.docx) file by using the latest Apache POI library(3.16), and exact the texts, pictures and embedded mathtype equations successfully.
To parse the embedded mathtype equations, I used the following api
List<XWPFPictureData> allPictures = doc.getAllPictures();
int i = 0;
for (XWPFPictureData picture: allPictures) {
if (picture.getFileName().endsWith(".wmf")) {
FileUtils.writeByteArrayToFile(new File(i + ".wmf"),
picture.getData());
i++;
}
}
Now I want to create a new word(docx) file, adding the texts,pictures and embedded mathtype equations back to it.
Add text: XWPFRun run = para.createRun(); run.setText("xxx")
.
Add picture: XWPFPicture xwpfPicture = run.addPicture(pictureData, pictureType, filename, Units.pixelToEMU(width), Units.pixelToEMU(height));
Add wmf:
String rId = doc.addPictureData(new FileInputStream(wmfFilePath), Document.PICTURE_TYPE_WMF);
The problem is that wmf is now invisible, and how to make it visible and place it in the right position? or to say make the wmf related to a created run.
Seeing the poi examples and test cases, but still can't find any api or method. http://svn.apache.org/repos/asf/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/ http://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/examples/
There is one related question: How can I add embedded equations to docx files by using Apache POI?
The difference is that I just want to add the parsed wmf files to a new word file, not to write some mathtype equations programaticly.
Can someone please give some help?
eg: I have a word which has one mathtype equation, when double click it, the mathtype editor is open since the mathtype soft is installed on the machine.
Parsed it use POI api:
doc.getAllPictures(); FileUtils.writeByteArrayToFile(new File(i + ".wmf"), picture.getData());
Now the mathtype equation is convert to wmf files on the disk.
run.addPicture(pictureData, Document.PICTURE_TYPE_WMF, filename, Units.pixelToEMU(width), Units.pixelToEMU(height)) it can add wmf as picture, but I want to restore the word, when the user does double click on the word equation, the mathtype editor is open.
POI can parse the mathtype equation in word to wmf files, is there any way to write back to a word as original?