用C#打印多页Tiff

时间:2010-09-20 14:42:22

标签: c# printing tiff

我正在尝试打印多维tiff。这个tiff有3个页面,使用可变的imagetoprint。所以我写了下面的代码,不幸的是只打印了第一个维度。所有其他都印在空纸上。如果我将图像从内存保存到文件,irfanview会正确显示所有页面......

谁可以给我一个提示?

 public void print(Bitmap imageToPrint, string printerName, int pagesToPrint)
 {
  try
  {
   printmap = imageToPrint;

   cur_page = 0;
   max_pages = pagesToPrint;

   m.Top = 1 * dpi; // Set a 1' margin, from the top
   m.Left = 1.25f * dpi; // Set a 1.25' margin, from the left
   m.Bottom = printmap.Height - m.Top; // 1', from the bottom
   m.Right = printmap.Width; // rechter Rand so weit wie es eben geht
   m.Width = printmap.Width - (m.Left * 2); // Get the width of our working area
   m.Height = printmap.Height - (m.Top * 2); // Get the height of our working area

   pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
   if (printerName != "")
    pd.DefaultPageSettings.PrinterSettings.PrinterName = printerName;
   pd.DefaultPageSettings.Color = true; 
   pd.DefaultPageSettings.PrinterSettings.PrintFileName = "tiffprint";
   pd.DocumentName = "InstantFormsPrinting";
   if (m.Width > m.Height)
   {
    pd.DefaultPageSettings.Landscape = true;
   }
   pd.Print(); // Print

  }
  catch (Exception ex)
  {
   Console.WriteLine("Error during print preparation:" + ex.Message);
  }
 }

 // Our printing event
 public void pd_PrintPage(object sender, PrintPageEventArgs e)
 {
  Rectangle crop = new Rectangle(1, 1, 200, 200);

  try
  {              
   printmap.SelectActiveFrame(FrameDimension.Page, cur_page);
   e.Graphics.DrawImageUnscaled(printmap, new Point(0, 0)); 

   ++cur_page;
   e.HasMorePages = (cur_page < max_pages);
  }
  catch (Exception ex)
  {
   Console.WriteLine("Error during print operation:" + ex.Message);
  }
 }

在页面2上,pd_PrintPage在“常规gdi问题”

中引发了异常

到目前为止我还不知道。如果有人可以提供帮助,那将是非常好的。

1 个答案:

答案 0 :(得分:3)

您可以在开始打印之前将页面提取为单个位图。