Posted by on Apr 24, 2012 in Blog, c#, Printing, VS2010 | 3 comments

In developer’s life, it is so common we used to encounter lot of issues. I am working in a small proof concept. Automatically printing documents to file or printer in C# (.Net Framework 4.0).         private void Print()         {             if (m_streams == null || m_streams.Count == 0)                 throw new Exception(“Error: no stream to print.”);             PrintDocument printDoc = new PrintDocument();             if (!printDoc.PrinterSettings.IsValid)             {                 throw new Exception(“Error: cannot find the default printer.”);             }             else             {                 printDoc.PrintPage += new PrintPageEventHandler(PrintPage);                 m_currentPageIndex = 0;                 if (printDoc.PrinterSettings.PrinterName == “Microsoft XPS Document Writer”)                 {                     printDoc.PrinterSettings.PrintToFile = true;                     if (filename == “”)                         printDoc.PrinterSettings.PrintFileName = DateTime.Now.Ticks.ToString() + “.xps”;                     else                         printDoc.PrinterSettings.PrintFileName = filename;                 }                 printDoc.Print();             }         } But while printing the documents to file, I was annoyed by a pop up which showed me Printing page 1 of 5. I wanted to get rid of that.   After a bit google and MSDN, I have found that Print controller PrintController class Controls how a document is printed, when printing from a Windows Forms application. If you look at the PrintDocument class Meta data view, you will notice the following statement.      ...

Read More