有没有渲染LaTeX的公式在Crystal Reports的一种方式?公式、方式、LaTeX、Reports

2023-09-05 01:05:48 作者:为你千千万

我正在开发的水晶报表的报告,并需要渲染一些数学公式和方程它。公式和公式都存储在纯文本SQL Server数据库(使用LaTeX的标记)。

I'm developing a report in Crystal Reports and need to render some math formulas and equations in it. The formulas and equations are stored in a SQL Server database in plain text (using LaTeX markup).

让他们在HTML中呈现的是不是一个问题,因为我使用MathJax做在浏览器层面的工作(以HTML / CSS或MATHML)。

Getting them to render in HTML is not a problem, because I'm using MathJax to do the work at browser level (in either HTML/CSS or MathML).

真正的问题是:我如何能得到这些方程在报告中呈现的?我搜索throught网页,发现一无所知。这样做在水晶界面的一些更多的搜索,我发现的唯一的事情是插入(过时)Microsoft公式编辑器,在报表中的OLE对象,但是没有这个工作。

The real problem is: how can I get these equations rendered in the report? I've searched throught the web and found nothing about it. Doing some more search at the Crystal interface, the only thing I've found is inserting the (obsolete) "Microsoft Equation Editor" as a OLE object in the report, but neither this worked.

那么,如何使这个Crystal报表在这些LaTeX的数学方程式?有一些(模糊)组件/插件,它的工作吗?如果没有,有没有更好的方式这样做的?有人已经拥有的,解决了类似的用例?

So, how render these LaTeX math equations in this Crystal report? Is there some (obscure) component/plugin that does the job? If not, is there a better manner of doing this? Someone already got and resolved a similar use-case?

OBS 1:我必须有,因为在使用中我的工作已经验证的标准PDF生成此报告

OBS 1: I must have this report generated in PDF because of already validated standards in use at my job.

OBS 2:这将产生本报告中的应用程序是一个ASP.NET MVC 3 web应用程序,与SQL Server 2008数据库(使用NHibernate)

OBS 2: The app which will generate this report is a ASP.NET MVC 3 web app, with a SQL Server 2008 database (using NHibernate).

推荐答案

我发现一种解决方法是在同一时间典雅,而不是依赖于使用C扩展的Crystal Reports。

I've found a workaround that is at the same time elegant and not relies on extending the Crystal Reports using C.

我发现这个小而简单的乳胶式渲染器:的mimetex 。使用它,我可以为渲染乳胶公式为GIF图像(作为CGI应用程序)。就这样,我在数据表中创建一个幻影字节数组字段其中,报告中获取数据。

I've found this small and simple "latex equation renderer": mimeTeX. Using it, I'm able to render latex equations into GIF images (as a CGI application). With that, I created a phantom byte array field in the datatable where the report is getting data.

下面是我做了什么:

从我真正的数据库恢复乳胶式标记; 在使用查询的mimetex这个标记和返回的mimetex GIF图像; 在拿这个图像并将其转换为png格式(水晶令人惊讶的不支持GIF文件); 最后把这个PN​​G图像(其字节)的数据表中所使用的报表创建幻影场; 现在,你可以在报告中使用此字段!生成并显示每个记录(公式)的图像没有问题!

在唯一的缺点我发现到现在为止使用这种方法的缺点是的所有的图像都streched到现场占位符的大小相同。如果图像有尺寸的变化很大,有的会显示像素化等将成为挤压。但我期待着如何解决这个问题!

The only drawback I've found until now using this approach is that all the images are streched to the same size of the field placeholder. If the images have sizes that varies much, some will be displayed pixelated and others will become "squashed". But I'm looking forward how to resolve this issue!

---编辑---

解决了压扁影像的问题。我调整保持其宽高比和粘贴他们在一个固定大小的图像在code中的图像。现在所有的图像得到相同的大小并没有得到挤压!

Solved the "squashed images" problem. I resize the images in code maintaining their aspect ratio and "pasting" them in a fixed size image. Now all the images get the same size and doesn't get squashed!

下面是code的大小调整:

Here is the code for the resizing:

MemoryStream ResizeImage(Stream OriginalFile, int NewWidth, int MaxHeight, bool OnlyResizeIfWider)
{
    int finalWidth = NewWidth;
    int finalHeight = MaxHeight;

    System.Drawing.Image FullsizeImage = System.Drawing.Image.FromStream(OriginalFile);

    // Prevent using images internal thumbnail
    FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
    FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);

    if (OnlyResizeIfWider)
    {
        if (FullsizeImage.Width <= NewWidth)
        {
            NewWidth = FullsizeImage.Width;
        }
    }

    int NewHeight = FullsizeImage.Height * NewWidth / FullsizeImage.Width;
    if (NewHeight > MaxHeight)
    {
        // Resize with height instead
        NewWidth = FullsizeImage.Width * MaxHeight / FullsizeImage.Height;
        NewHeight = MaxHeight;
    }

    System.Drawing.Image NewImage = FullsizeImage.GetThumbnailImage(NewWidth, NewHeight, null, IntPtr.Zero);

    // Clear handle to original file so that we can overwrite it if necessary
    FullsizeImage.Dispose();

    MemoryStream bmpStream = new MemoryStream();

    // Put in a new image of A x B pixels to evict distortion
    using (var bitmap = new Bitmap(finalWidth, finalHeight))
    {
        using (var canvas = Graphics.FromImage(bitmap))
        {
            canvas.InterpolationMode = InterpolationMode.HighQualityBicubic;
            canvas.Clear(Color.White);
            canvas.DrawImage(NewImage, 0, 0);
            canvas.Save();
        }

        bitmap.Save(bmpStream, ImageFormat.Bmp);
    }

    return bmpStream;
}