Printing multipage Tiff with C#
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.
You could extract the pages into single bitmaps before you start printing.
精彩评论