views:

842

answers:

3

I'm attempting to use Mono to load a bitmap and print it on Linux but I'm getting an exception. Does Mono support printing on Linux? The code/exception are below:

EDIT: No longer getting the exception, but I'm still curious what kind of support there is. Leaving the code for posterity or something.

private void btnPrintTest_Click(object sender, EventArgs e)
{
    _printDocTest.DefaultPageSettings.Landscape = true;
    _printDocTest.DefaultPageSettings.Margins = new Margins(50,50,50,50);
    _printDocTest.Print();
}

void _printDocTest_PrintPage(object sender, PrintPageEventArgs e)
{
  var bmp = new Bitmap("test.bmp");

  // Determine center of graph
  var xCenter = e.MarginBounds.X + (e.MarginBounds.Width - bmp.Width) / 2;
  var yCenter = e.MarginBounds.Y + (e.MarginBounds.Height - bmp.Height) / 2;

  e.Graphics.DrawImage(bmp, xCenter, yCenter);

  e.HasMorePages = false;
}
+3  A: 

From the Mono docs, I think yes:

Managed.Windows.Forms (aka System.Windows.Forms): A complete and cross platform, System.Drawing based Winforms implementation.

It also useful if you run the Mono Migration Analyzer first.

John
+2  A: 

According to http://www.go-mono.com/archive/1.2/:

" System.Drawing is now complete, and in addition to being the underlying rendering engine for Windows.Forms, it has also been tested for using third party controls that heavily depend on it. "

Espo
A: 

Oh..oops, looks like I was just specifying the file path wrong (changed it to open the file first then load it into a bitmap). Got it working now -- nothing to see here, move along.

Luke