Out of memory in printing

  • Thread starter Thread starter Shawn_skr
  • Start date Start date
S

Shawn_skr

Guest
try
{
PrintDocument pd = new PrintDocument();
pd.DefaultPageSettings.PrinterSettings.PrinterName = printer;
pd.PrintController = new StandardPrintController();

pd.DefaultPageSettings.PaperSize = a4Size;

pd.PrintPage += (s, args) =>
{
using (MemoryStream stream = new MemoryStream(data))
{
using (Image image = Image.FromStream(stream))
{
if (image.Width > image.Height)
{
image.RotateFlip(RotateFlipType.Rotate270FlipNone);
}
args.Graphics.PixelOffsetMode = PixelOffsetMode.HighSpeed;
args.Graphics.DrawImage(image, args.MarginBounds);
args.HasMorePages = false;
image.Dispose();
stream.Dispose();
Logger.Debug("print page end");
}
}
};
Logger.Debug("print page");
pd.Print();
pd.Dispose();
}
catch (Exception ex)
{
error = ex.Message;
Logger.Error(ex.Message, ex);
return false;
}
finally
{
}
return true;

------------------------------------------------------------------------

Out of memory.
System.OutOfMemoryException: Out of memory.
at System.Drawing.Graphics.CheckErrorStatus(Int32 status)
at System.Drawing.Graphics.DrawImage(Image image, Single x, Single y, Single width, Single height)
at System.Drawing.Graphics.DrawImage(Image image, RectangleF rect)
at TomTaw.eWord.Bussiness.Services.ImagePrintService.<>c__DisplayClass1_0.<Print>b__0(Object s, PrintPageEventArgs args)
at System.Drawing.Printing.PrintDocument.OnPrintPage(PrintPageEventArgs e)
at System.Drawing.Printing.PrintDocument._OnPrintPage(PrintPageEventArgs e)
at System.Drawing.Printing.PrintController.PrintLoop(PrintDocument document)
at System.Drawing.Printing.PrintController.Print(PrintDocument document)
at System.Drawing.Printing.PrintDocument.Print()
at TomTaw.eWord.Bussiness.Services.ImagePrintService.Print(Byte[] data, String printer, String& error)

Continue reading...
 
Back
Top