I found a workaround that is elegant at the same time and does not rely on the Crystal Reports extension using C.
I found this small and simple tool for visualizing latex equations: mimeTeX . Using this, I can visualize latex equations in GIF images (as a CGI application). With this, I created a phantom array field in datatable where the report receives data.
Here is what I did:
- Retrieve the markup of the latex equation from my real database;
- A mimeTeX request using this markup and mimeTeX returns a gif image;
- Take this image and convert it to png format (Crystal unexpectedly does not support GIF files);
- Finally, put this PNG image (its bytes) in the phantom field created in the datatable used in the report;
- Now you can use this field in the report! Images for each record (equation) are generated and displayed without problems!
the only drawback I have found so far using this approach is that all the images are stretched to the same size as the placeholder. If the images have sizes that vary greatly, some will be displayed in pixels, while others will become “crushed”. But I look forward to how to solve this problem!
--- Edit ---
The problem of "crushed images" is resolved. I resize images in code, preserving their aspect ratio and "pasting" them into a fixed-size image. Now all images get the same size and are not crushed!
Here is the code for 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; }
source share