Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Printing Tiff's

Printing Tiff's

Scheduled Pinned Locked Moved C#
csharpphpdatabasegraphicstutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    HahnTech
    wrote on last edited by
    #1

    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

    N 1 Reply Last reply
    0
    • H HahnTech

      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

      N Offline
      N Offline
      Nader Elshehabi
      wrote on last edited by
      #2

      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:

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups