471,599 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,599 software developers and data experts.

Printing Multi-page .tif files

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

Nov 17 '05 #1
0 1909

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Roger Binns | last post: by
11 posts views Thread by Marian Aldenhövel | last post: by
9 posts views Thread by Gary | last post: by
16 posts views Thread by gb | last post: by
9 posts views Thread by Jody Gelowitz | last post: by
1 post views Thread by John | last post: by
1 post views Thread by Yatin Bhuta | last post: by
reply views Thread by matpublic | last post: by
2 posts views Thread by XIAOLAOHU | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.