Thanks to Bob's help, I was able to get .tif printing working. Now
i've got a new problem; if the image is more than one page, it only
prints the first page.
Here's my code:
############################################
public class PrintTif
{
public string curfname;
public string blankf;
public PrintTif(string blank)
{
this.blankf = blank;
}
public int PrintTheTif(string tifname)
{
this.curfname = tifname;
PageSettings ps = new PageSettings();
ps.Landscape = false;
ps.Margins.Bottom = 100;
ps.Margins.Top = 100;
ps.Margins.Left = 100;
ps.Margins.Right = 100;
PrintDocument pd = new PrintDocument();
pd.DefaultPageSettings = ps;
pd.PrintPage += new
PrintPageEventHandler(this.PrintImageHandler);
try
{
pd.Print();
return 1;
}
catch(Exception ex)
{
throw ex;
}
finally
{
pd.Dispose();
}
}
private void PrintImageHandler(object sender,
PrintPageEventArgs ppea)
{
Image img = Image.FromFile(this.curfname);
Image blank = null;
for(int i = 0; i < img.GetFrameCount(FrameDimension.Page); ++i)
{
blank = Image.FromFile(this.blankf);
Rectangle r = new Rectangle(0,0,blank.Width,blank.Height);
img.SelectActiveFrame(FrameDimension.Page, i);
Bitmap temp = new Bitmap(img);
temp.SetResolution(100,100);
Graphics g = ppea.Graphics;
g.DrawImage(temp,r);
temp.Dispose();
if(i == (img.GetFrameCount(FrameDimension.Page) - 1))
ppea.HasMorePages = false;
else
ppea.HasMorePages = true;
blank.Dispose();
}
img.Dispose();
}
}
#########################################
Apologies for the funky formatting. Here's a pastebin w/ the same code
if anybody is having a hard time reading it:
http://pastebin.com/307914
I'm pretty sure I konw what the problem is. It seems that the result
of the g.DrawImage() call is only being sent back to the calling method
once, instead of for each page. Is this correct?
Assuming it is, I'm not sure if i need to loop through the pages
outside of PrintImageHandler() or what.
Any ideas?
TIA,
Brett