Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将MS Word中的数学方程转换为Java中的图像?_Java_Ms Word_Mathml_Omml - Fatal编程技术网

如何将MS Word中的数学方程转换为Java中的图像?

如何将MS Word中的数学方程转换为Java中的图像?,java,ms-word,mathml,omml,Java,Ms Word,Mathml,Omml,我有一个MS Word 2013文档,其中包含数学公式,我想通过编程将其转换为图像 我尝试的是: 自Office 2007以来,Microsoft已将数学公式的表示形式更改为Office MathML(OMML)格式 我可以将OMML格式的公式转换为MathML格式。 我的Java代码与此相同: //获取xslt StreamSource xlsStreamSource = new StreamSource("D:/TEMP/OMML2MML.XSL"); //Get the document.

我有一个MS Word 2013文档,其中包含数学公式,我想通过编程将其转换为图像

我尝试的是:
自Office 2007以来,Microsoft已将数学公式的表示形式更改为Office MathML(OMML)格式

  • 我可以将OMML格式的公式转换为MathML格式。 我的Java代码与此相同:
  • //获取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);
    
  • 现在我有了将公式转换成MathML格式的“结果”。 当我尝试将这个公式放入剪贴板以获取图像风格时,它存储为纯XML文本,没有可用的图像风格
  • //在剪贴板中写入和读取提供的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可用于相同的,这将是更多 更容易做到这一点


    请参阅更新的问题。实际上,我尝试使用JavaFX实现此转换,但未能成功。嗨,专家们,有什么答案吗?可能重复的不是重复的。在这里,我想将数学方程(OMathML格式)转换为图像。请参考更新的问题。事实上,我试图用JavaFX实现这个转换,但我没有成功。嗨,专家们,有什么答案吗?这可能是重复的,但不是重复的。在这里,我想把数学方程(OMathML格式)转换成图像。