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

  • Thread starter Thread starter ashok.kumar1974
  • Start date Start date
A

ashok.kumar1974

Guest
Hi,
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.1604501.png1604502.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);

  1. using (System.Drawing.Brush border = new SolidBrush(System.Drawing.Color.White /*Change it to whichever color you want.*/))
  2. {
  3. g.FillRectangle(border, 0, 0, Width + borderSize, Height + borderSize);
  4. }
  5. var WMargin = (float) (borderSize * Dpi);
  6. var HMargin = (Height > Width)
  7. ? (float) ((borderSize * Dpi) / 2)
  8. : (float) (borderSize * Dpi);
  9. g.DrawImage(m_emf, borderSize, borderSize, (Width - (float) WMargin), (Height - (float) HMargin));
  10. target.Save(Desc, ImageFormat.Png);
  11. }
  12. m_emf.Dispose();

}

Kindly help us to resolve this issue.

Regards
Ashok

Continue reading...
 
Back
Top