You must Sign In to post a response.
  • Category: .NET

    How to count number of prints taken from a printer using WPF

    Hi Everyone,

    I am creating one setup file in WPF. The exe file is always opening in the system. There is a one field Printing Pages. Total print pages count will display in that field.

    I want to get the count of printing pages what we going to print.

    When we going to print any documents from computer, the program can count the pages. Please give me a tip for this?



    Thanks,
  • #761350
    Hello Lawrence,

    You can do it using C# :

    public static int GetPageCount(PrintDocument printDocument)
    {
    int count = 0;
    printDocument.PrintController = new PreviewPrintController();
    printDocument.PrintPage += (sender, e) => count++;
    printDocument.Print();
    return count;
    }

    Store your count value somewhere to use it again with last value.

    Hope this will help you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #761353
    Thank you for reply. But What is the PrintDocument parameter in that method?.

    The exe is running the system till we will close that. If I want to take the printout from Word or PDF anything. I want to get the count of printing pages what we going to print and display in that field. I don't want to print through the application.

  • #761375
    Hello Lawrence,

    You can make a windows service for that task which will run in the behind.

    It may work but you can try it.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #761649
    thanks for your reply. I'll try in WindowService. but What is the parameter of that GetPageCount method. Please tell me.

  • #761651
    Hello Lawrence,

    It's an object name of file.
    Ex. Crystalreport1 rpt = new Crystalreport1();

    Hope you understand.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #761663
    I knew that is the object name of PrintDocument. If I call that method I want to pass the some value of that parameter..right. I want to know what value can I pass that parameter of GetPageCount method ?

  • #761667
    Hello Lawrence,

    Crystalreport1 rpt = new Crystalreport1();

    GetPageCount(rpt);

    Try like this.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #762398
    thanks for your reply. but I doesn't get the print from cyrstalreport or other tool. I want to get the printout from Ms Word or Pdf or Ms Excel. So only I asked how to pass the parameter to GetPageCount method. How to do? Please help me.


Sign In to post your comments