有没有办法在 Crystal Reports 中呈现 LaTeX 方程?

Is there a way of rendering LaTeX equations in Crystal Reports?(有没有办法在 Crystal Reports 中呈现 LaTeX 方程?)

本文介绍了有没有办法在 Crystal Reports 中呈现 LaTeX 方程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Crystal Reports 中开发一个报表,需要在其中呈现一些数学公式和方程式.公式和方​​程式以纯文本形式(使用 LaTeX 标记)存储在 SQL Server 数据库中.

让它们在 HTML 中呈现不是问题,因为我使用 MathJax 在浏览器级别(在 HTML/CSS 或 MathML 中)完成工作.

真正的问题是:如何在报告中呈现这些方程式?我在网上搜索过,没有发现任何关于它的信息.在 Crystal 界面上进行更多搜索,我发现的唯一一件事是将(过时的)Microsoft 公式编辑器"作为 OLE 对象插入到报表中,但这都不起作用.

那么,如何在这个 Crystal 报表中呈现这些 LaTeX 数学方程?是否有一些(晦涩的)组件/插件可以完成这项工作?如果没有,是否有更好的方法来做到这一点?有人已经得到并解决了类似的用例?

OBS 1:我必须以 PDF 格式生成这份报告,因为我的工作中使用的标准已经过验证.

OBS 2:将生成此报告的应用程序是 ASP.NET MVC 3 Web 应用程序,带有 SQL Server 2008 数据库(使用 NHibernate).

解决方案

我找到了一种既优雅又不依赖于使用 C 扩展 Crystal Reports 的解决方法.p>

我发现了这个小而简单的乳胶方程渲染器":mimeTeX.使用它,我能够将乳胶方程式渲染成 GIF 图像(作为 CGI 应用程序).有了这个,我在报表获取数据的数据表中创建了一个幻字节数组字段.

这是我所做的:

  1. 从我的真实数据库中恢复乳胶方程标记;
  2. 使用此标记查询 mimeTeX,mimeTeX 返回一个 gif 图像;
  3. 将此图片转换为 png 格式(Crystal 令人惊讶地不支持 GIF 文件);
  4. 最后把这个PN​​G图像(它的字节)放在报表使用的数据表中创建的幻像字段中;
  5. 现在您可以在报告中使用此字段了!每个记录(方程)的图像都生成并显示没有问题!

到目前为止,我发现使用这种方法的唯一缺点所有图像都被拉伸到与字段占位符相同的大小.如果图像的尺寸变化很大,一些会被显示为像素化,而另一些则会被压扁".但我很期待如何解决这个问题!

--- 编辑---

解决了压缩图像"问题.我在代码中调整图像的大小,保持它们的纵横比,并将它们粘贴"到固定大小的图像中.现在所有图像的大小都相同并且不会被压扁!

这是调整大小的代码:

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);//防止使用图片内部缩略图FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);如果 (OnlyResizeIfWider){if (FullsizeImage.Width <= NewWidth){NewWidth = FullsizeImage.Width;}}int NewHeight = FullsizeImage.Height * NewWidth/FullsizeImage.Width;如果(新高度 > 最大高度){//改为使用高度调整大小NewWidth = FullsizeImage.Width * MaxHeight/FullsizeImage.Height;新高度 = 最大高度;}System.Drawing.Image NewImage = FullsizeImage.GetThumbnailImage(NewWidth, NewHeight, null, IntPtr.Zero);//清除原始文件的句柄,以便我们可以在必要时覆盖它全尺寸图像.Dispose();MemoryStream bmpStream = new MemoryStream();//放入 A x B 像素的新图像以消除失真使用 (var bitmap = new Bitmap(finalWidth, finalHeight)){使用 (var canvas = Graphics.FromImage(bitmap)){canvas.InterpolationMode = InterpolationMode.HighQualityBicubic;canvas.Clear(Color.White);canvas.DrawImage(NewImage, 0, 0);画布.保存();}bitmap.Save(bmpStream, ImageFormat.Bmp);}返回 bmpStream;}

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).

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).

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.

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: I must have this report generated in PDF because of already validated standards in use at my job.

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).

解决方案

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

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.

Here is what I've done:

  1. Recover the latex equation markup from my real database;
  2. Query mimeTeX using this markup and mimeTeX returns a gif image;
  3. Take this image and convert it to png format (Crystal surprisingly do not support GIF files);
  4. Finally put this PNG image (its bytes) in the phantom field created in the datatable used by the report;
  5. Now you can use this field in the report! The images for each record (equation) are generated and displayed without problems!

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!

--- Edit ---

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!

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;
}

这篇关于有没有办法在 Crystal Reports 中呈现 LaTeX 方程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:有没有办法在 Crystal Reports 中呈现 LaTeX 方程?

基础教程推荐