Converting EMF to PNG preserves/displaying Excel cell with No Color data

Ashok Kumar 1 Reputation point
2020-06-25T09:47:06.23+00:00

10560-wpf-preview.pngHi,
We have NT EMF virtual printer, We have Excel sheet (contains each cell data with no color) show that no color cell will not be printed.
When we print that Excel sheet to our virtual printer, it will print EMF data to or WPF application.
The problem is after receiving the print data from Excel the data in no color cell are also visible.

Print Excel sheet to our virtual printer, Excel Print Preview is not showing the no color data. Screenshot attached. (Excel Print Preview.png)
See data in cell A1, C2, E3, G4 is not visible in Excel Print Preview.10684-excel-print-preview.png

After receiving the excel printed data as EMF in our WPF application, we are trying convert EMF (Metafile) to PNG and when preview no color cell data is visible. Screenshot attached. (WPF Preview.png)
See A1, C2, E3 , G4 data are visible.

We are using below code to convert EMF to PNG.
int borderSize = 10;
float Dpi = 2f; //2.54f
string FilePath = System.IO.Path.GetTempPath();
string Desc = System.IO.Path.Combine(FilePath, "TemptiffView.png");

System.Drawing.Imaging.Metafile m_emf = "Excel print data to our application via our virtual printer";

using (var target = new Bitmap(Width, Height))
{
using (var g = Graphics.FromImage(target))
{
g.Clear(System.Drawing.Color.White);

    using (System.Drawing.Brush border = new SolidBrush(System.Drawing.Color.White /*Change it to whichever color you want.*/))  
    {  
        g.FillRectangle(border, 0, 0, Width + borderSize, Height + borderSize);  
    }  

    var WMargin = (float) (borderSize * Dpi);  
    var HMargin = (Height > Width)  
    ? (float) ((borderSize * Dpi) / 2)  
    : (float) (borderSize * Dpi);  
                          
    g.DrawImage(m_emf, borderSize, borderSize, (Width - (float) WMargin), (Height - (float) HMargin));  
                             
    target.Save(Desc, ImageFormat.Png);  
}  
  
m_emf.Dispose();  

}

Kindly help us to resolve this issue.

Regards
Ashok

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,685 questions
{count} votes