使用 C# 打印多页 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 问题”的异常,
到目前为止我还不知道。如果有人可以提供帮助,那就太好了。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在开始打印之前将页面提取为单个位图。
You could extract the pages into single bitmaps before you start printing.