Printing Tiff's
-
The following functions are suppose to print multi page Tiff images but they don't. If I have a 2 page tiff it prints 2 copies of page one. I can't figure out how to get to the next page. The code is adapted from http://en.csharp-online.net/index.php?title=Graphics%2C_Multimedia%2C_and_Printing_Recipes%E2%80%94Recipe_8_15[^]
public class TiffDocument : PrintDocument { private string _Tiff; private int _PageNumber=0; private int _NumberOfPages=0; //private int offset; public string Tif { get { return _Tiff; } set { _Tiff = value; } } public int PageNumber { get { return _PageNumber; } set {_PageNumber = value;} } public int NumberOfPages { get { return _NumberOfPages; } set { _NumberOfPages = value; } } public TiffDocument(string tif) { this._Tiff = tif; if(File.Exists(tif)) { Image i = Image.FromFile(tif); FrameDimension myFrame = new FrameDimension(i.FrameDimensionsList[0]); _NumberOfPages = i.GetFrameCount(myFrame); } } } private void doc_PrintTiff(object sender, PrintPageEventArgs e) { TiffDocument doc = (TiffDocument)sender; using(Image i = Image.FromFile(doc.Tif)) { e.Graphics.DrawImageUnscaled(i,0,0); doc.PageNumber++; if (doc.PageNumber < doc.NumberOfPages) { // There is still at least one more page. // Signal this event to fire again. e.HasMorePages = true; } else { // Printing is complete. e.HasMorePages=false; } } } private void button1_Click(object sender, System.EventArgs e) { PrintDocument doc = new TiffDocument(@"C:\test.tif"); doc.PrintPage +=new PrintPageEventHandler(doc_PrintTiff); printDialog1.Document= doc; doc.Print(); }
Ronald Hahn, CNT - Computer Engineering Technologist New Technologies Analyst HahnTech Affiliated With Code Constructors Edmonton, Alberta, Canada Email: rhahn82@telus.net
-
The following functions are suppose to print multi page Tiff images but they don't. If I have a 2 page tiff it prints 2 copies of page one. I can't figure out how to get to the next page. The code is adapted from http://en.csharp-online.net/index.php?title=Graphics%2C_Multimedia%2C_and_Printing_Recipes%E2%80%94Recipe_8_15[^]
public class TiffDocument : PrintDocument { private string _Tiff; private int _PageNumber=0; private int _NumberOfPages=0; //private int offset; public string Tif { get { return _Tiff; } set { _Tiff = value; } } public int PageNumber { get { return _PageNumber; } set {_PageNumber = value;} } public int NumberOfPages { get { return _NumberOfPages; } set { _NumberOfPages = value; } } public TiffDocument(string tif) { this._Tiff = tif; if(File.Exists(tif)) { Image i = Image.FromFile(tif); FrameDimension myFrame = new FrameDimension(i.FrameDimensionsList[0]); _NumberOfPages = i.GetFrameCount(myFrame); } } } private void doc_PrintTiff(object sender, PrintPageEventArgs e) { TiffDocument doc = (TiffDocument)sender; using(Image i = Image.FromFile(doc.Tif)) { e.Graphics.DrawImageUnscaled(i,0,0); doc.PageNumber++; if (doc.PageNumber < doc.NumberOfPages) { // There is still at least one more page. // Signal this event to fire again. e.HasMorePages = true; } else { // Printing is complete. e.HasMorePages=false; } } } private void button1_Click(object sender, System.EventArgs e) { PrintDocument doc = new TiffDocument(@"C:\test.tif"); doc.PrintPage +=new PrintPageEventHandler(doc_PrintTiff); printDialog1.Document= doc; doc.Print(); }
Ronald Hahn, CNT - Computer Engineering Technologist New Technologies Analyst HahnTech Affiliated With Code Constructors Edmonton, Alberta, Canada Email: rhahn82@telus.net
Hello Try to debug your code and go through the first and second excutions of the print event. does the doc.PageNumber actually increases the second time?
Regards:rose: