MathML 或 OMML 到 PNG w/.NET?

发布于 2024-07-26 07:14:42 字数 380 浏览 9 评论 0原文

是否有任何库可以采用 MathML(或者更好的是 OMML)并输出 .PNG 文件?

我正在整理 .docx 文件的导出过程,作为此过程的一部分,我想提取方程并将其渲染为 .PNG 文件。 当您保存 Web 文档时,Word 2007 会本机执行此操作,但到目前为止,我还没有找到以编程方式执行此操作的方法(如果有人对此有答案,那就更好了)。 因此,下一个最好的办法是采用 OMML 并使用 Microsoft 提供的 XSL 样式表并将它们转换为 MathML。

不幸的是,我无法找到任何适用于 MathML 或 OMML 的(工作)渲染库。

如果没有任何纯 .NET 库可以实现此目的,我将满足于可以从命令行调用的任何内容,以从 MathML 或 OMML 输出 .PNG。

Are there any libraries which take MathML (or, even more preferably, OMML) and outputs a .PNG file?

I am putting together an export process for .docx files and, as a part of this process, I'd like to extract equations and render them as .PNG files. Word 2007 does this natively when you save a document for the web, but so far, I have not been able to find a way to do this programmatically (if anyone has an answer for that, it would be even better). So the next best thing is to take the OMML and use the Microsoft provided XSL stylesheets and transform them to MathML.

Unfortunately, I haven't been able to find any (working) rendering libraries for either MathML or OMML.

If there aren't any pure .NET libraries for this, I'll settle for just about anything that I can call from a commandline to output a .PNG from either MathML or OMML.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

铃予 2024-08-02 07:14:42

您可以尝试 SVGMath 将 mathml 转换为 SVG,然后使用一些工具将 svg 转换为 png 例如

http://harriyott.com/2008/05/ Converting-svg-images-to-png-in-c.aspx

或使用 rsvg lib将 svg 转换为 png 文件。

You can try SVGMath to convert mathml to SVG and then some tool to convert svg to png e.g.

http://harriyott.com/2008/05/converting-svg-images-to-png-in-c.aspx

or use rsvg lib to convert svg to png files.

万水千山粽是情ミ 2024-08-02 07:14:42

我们制作了一个名为 Equation Composer 的 DLL 库,许多人将其与 .NET 一起使用以将 MathML 转换为 PNG。 它也可以作为命令行可执行文件使用。 它不是免费的,但这意味着您可以获得技术支持和错误修复。 更多信息请访问:http://dessci.com/en/products/mathflow/ mf_components.htm

We make a DLL library called the Equation Composer that many use with .NET to convert MathML to PNG. It's also available as a commandline executable. It's not free, but that means you get technical support and bug fixes. More info is available here: http://dessci.com/en/products/mathflow/mf_components.htm

执手闯天涯 2024-08-02 07:14:42

我有类似的需求。 这是一个适合我的片段:

public void FormulaToImage(string imageName, string eq)
{
    Application app = new Application();
    Document _doc = app.Documents.Add();
    Range _range = _doc.Range();
    _range.Text = eq; // "Celsius = (5/9)(Fahrenheit – 32)";
    _doc.OMaths.Add(_range);
    _doc.OMaths.BuildUp();
    _doc.SaveAs(@"foo.htm", WdSaveFormat.wdFormatHTML);

    //the gif appears to be better quality than the png
    File.Move(@"foo_files\image002.gif", imageName + ".gif");                
    app.Documents.Close(WdSaveOptions.wdDoNotSaveChanges);
    app.Quit(false);
}

I have a similar need. Here's a fragment that works for me:

public void FormulaToImage(string imageName, string eq)
{
    Application app = new Application();
    Document _doc = app.Documents.Add();
    Range _range = _doc.Range();
    _range.Text = eq; // "Celsius = (5/9)(Fahrenheit – 32)";
    _doc.OMaths.Add(_range);
    _doc.OMaths.BuildUp();
    _doc.SaveAs(@"foo.htm", WdSaveFormat.wdFormatHTML);

    //the gif appears to be better quality than the png
    File.Move(@"foo_files\image002.gif", imageName + ".gif");                
    app.Documents.Close(WdSaveOptions.wdDoNotSaveChanges);
    app.Quit(false);
}
少跟Wǒ拽 2024-08-02 07:14:42

你可以尝试Java库JEuclid:
http://jeuclid.sourceforge.net/

You can try Java library JEuclid:
http://jeuclid.sourceforge.net/

物价感观 2024-08-02 07:14:42

一些不错的消息,一些不太好的消息和一些奇怪的消息:

好的消息是您正在寻找的库位于 http://msdn.microsoft.com/en-us/library/documentformat.openxml.math%28office。 14%29.aspx。 至少这就是我认为你正在寻找的。

不太好的消息是下面的代码并不完全按照希望的方式工作 - 它将大部分字符复制为“?” 结果图像几乎是垃圾。

Sub SaveOMML()
Dim rng As Range
Dim Equation As OMath

Set rng = Selection.Range
rng.Text = "Celsius = (5/9)(Fahrenheit – 32)"
Set rng = Selection.OMaths.Add(rng)
Set Equation = rng.OMaths(1)
Equation.BuildUp
Equation.Range.Select

With Selection.Range
        .CopyAsPicture
        .PasteSpecial DataType:=wdPasteMetafilePicture
End With

End Sub

奇怪的消息是 OMML 可以像图像一样复制/粘贴到 PowerPoint 中,然后可以将其另存为 PNG。 虽然有点麻烦,但是用VSTO就可以完成。

Some okay news, some not so great news and some weird news:

The okay news is the library you're looking for is at http://msdn.microsoft.com/en-us/library/documentformat.openxml.math%28office.14%29.aspx. At least that's what I think you're looking for.

The not so great news is that the code below doesn't exactly work as hoped - it copies most of the characters as "?" and the resulting image is pretty much crap.

Sub SaveOMML()
Dim rng As Range
Dim Equation As OMath

Set rng = Selection.Range
rng.Text = "Celsius = (5/9)(Fahrenheit – 32)"
Set rng = Selection.OMaths.Add(rng)
Set Equation = rng.OMaths(1)
Equation.BuildUp
Equation.Range.Select

With Selection.Range
        .CopyAsPicture
        .PasteSpecial DataType:=wdPasteMetafilePicture
End With

End Sub

The weird news is that OMML does copy/paste into PowerPoint just fine as an image, which can then be saved out as a PNG. At little cumbersome, but it can be done with VSTO.

憧憬巴黎街头的黎明 2024-08-02 07:14:42

如果您喜欢 Microsoft Word 的功能,可以从 Decision Science 获取他们用于实现此功能的代码... http://dessci.com / ...我很快就会评估他们的 MathFlow 产品,但还没有...所以,我还无法验证 PNG 生成是否运行良好。

If you like what Microsoft Word does, the code they use to do it is available from Decision Science... http://dessci.com/ ... I'll be evaluating their MathFlow product soon, but haven't yet... so, I can't yet verify that the PNG generation works well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文