我有一个包含数学公式的MS Word 2013文档,我想以编程方式将其转换为图像。
我尝试的是:
自Office 2007以来,Microsoft已将数学公式的表示形式更改为Office MathML( OMML )格式。
//获取xslt
StreamSource xlsStreamSource = new StreamSource("D:/TEMP/OMML2MML.XSL");
//Get the document.xml from .docx file
StreamSource xmlStreamSource = new StreamSource("D:/TEMP/word/document.xml");
//Using xalan transformer factory.
TransformerFactory transformerFactory = TransformerFactory.newInstance("org.apache.xalan.processor.TransformerFactoryImpl", null);
File pathToHTMLFile = new File("D:/TEMP/Newfolder/word/documentModified.xml");
StreamResult result = new StreamResult(pathToHTMLFile);
Transformer transformer = transformerFactory.newTransformer(xlsStreamSource);
transformer.transform(xmlStreamSource, result);
//在剪贴板中写入和读取XMLstring
/**
* Write to Clipboard.
* @param s string containing MathML representation
* @param owner
*/
public static void writeToClipboard(String s, ClipboardOwner owner)
{
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable transferable = new StringSelection(s);
clipboard.setContents(transferable, owner);
}
/**
* Read clipboard data as image
* @return Image
* @throws Exception
*/
public static Image getImageFromClipboard() throws Exception
{
Transferable transferable = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
if (transferable != null&& transferable.isDataFlavorSupported(DataFlavor.imageFlavor)) {
return (Image) transferable.getTransferData(DataFlavor.imageFlavor);
} else {
return null;
}
}
我想将MathML(XML)写入剪贴板,因此我可以从中读取图像味道。 如何将这个MathML公式格式写入剪贴板,这样我就能从中获得图像味道?
注意:我不确定我是否朝着正确的方向前进。如果 有任何现有的API可用于更多 更容易做到这一点。