使用 C# 打印多页 Tiff

发布于 2024-09-24 01:11:19 字数 1823 浏览 2 评论 0原文

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

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

I am trying to print a multidimensional tiff. This tiff is having 3 Pages using variable imagetoprint. So I wrote following code, that unfortunately only prints the first dimension. All others are printed on empty paper. If I save the image from memory to file, irfanview shows all pages correctly...

Who can give me a hint ?

 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);
  }
 }

On Page 2 pd_PrintPage thows an exception with "general gdi problem"

I have no idea so far. It would be very nice if somebody can help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

楠木可依 2024-10-01 01:11:19

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

You could extract the pages into single bitmaps before you start printing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文