【问题标题】:Printing multipage Tiff with C#使用 C# 打印多页 Tiff
【发布时间】:2010-09-20 14:42:22
【问题描述】:

我正在尝试打印多维 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 问题”的异常

到目前为止,我不知道。如果有人可以提供帮助,那就太好了。

【问题讨论】:

  • 应该可以工作,将存在此问题的示例 .tiff 文件放在文件共享服务上。
  • 您的代码对我有用。谢谢!

标签: c# printing tiff


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    • 2014-12-06
    • 2015-08-07
    • 1970-01-01
    • 2013-06-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多