I want to convert Word to markdown through simple code. But the formula I created became a string and lost its format. Is there any way for me to convert the formula into an image and save it.
Document doc = new Document("test.docx");
MarkdownSaveOptions options = new MarkdownSaveOptions();
doc.save("test.md",options);
test.zip (11.0 KB)
@zhengkai Unfortunately, currently there is no such option.
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): WORDSNET-27646
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
For now, as a workaround, you can convert OfficeMath equations to images before exporting document to markdown. For example see the following code:
Document doc = new Document("C:\\Temp\\in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
for (OfficeMath m : (Iterable<OfficeMath>)doc.getChildNodes(NodeType.OFFICE_MATH, true))
{
// process only top level OfficeMath.
if (m.getAncestor(NodeType.OFFICE_MATH) == null)
{
// Save office math as PNG
ByteArrayOutputStream tmpStream = new ByteArrayOutputStream();
m.getMathRenderer().save(tmpStream, new ImageSaveOptions(SaveFormat.PNG));
builder.moveTo(m);
builder.insertImage(new ByteArrayInputStream(tmpStream.toByteArray()));
m.remove();
}
}
doc.save("C:\\Temp\\out.md");