Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I need to intercept a print order from a program like Core, Photosop or Word and capture a series of data from it just like the printdate,dimentions of impresion etc to save in a database and then release it to print.
Posted
Updated 17-Jul-12 8:44am
v2
Comments
Sergey Alexandrovich Kryukov 17-Jul-12 12:27pm    
No a question, and is not clear what you want and what's the problem.
--SA
Lisbey Collazo Alfonso 17-Jul-12 15:23pm    
hi sergey
what i need is to intercept a print order from an external program like Core, Photosop or Microsoft Word and capture a series of data from it just like the printdate,dimentions of impresion etc to save in a database and then release it to print.
Tim Corey 17-Jul-12 12:35pm    
This sounds like something that you would do inside your application when you send something to the printer. However, you have provided no detail so we have no way of accurately answering your question. We would need details of what is printing, how it is printing, how you intend to "intercept" that print job, what type of data you want out of the print job, etc. before we can help.
Lisbey Collazo Alfonso 17-Jul-12 14:49pm    
hi tim
what i need is to intercept a print order from an external program like Core, Photosop or Microsoft Word and capture a series of data from it just like the printdate,dimentions of impresion etc to save in a database and then release it to print.
Lisbey Collazo Alfonso 17-Jul-12 15:27pm    
thanks but I don't have money and I really want to found a way to do that by programing :)

I know you asked for a C# program, but instead of writing an application, I would recommend using this (free) application:

http://www.papercut.com/products/free_software/print_logger/[^]

It seems like it will do exactly what you want and someone else deals with the headache of handling the printer job interceptions. I have personally used the paid product they offer (PaperCut[^]) and I was very impressed by it.

If you put this exe in place, then you can deal with the data without needing to write the handler to capture the data. You can concentrate on what you want to do with the data rather than how to get the data.
 
Share this answer
 
this is de code that I was looking for........
C#
using System;
using System.Collections.Generic;
using System.Text;
using System.Management;
namespace PrintJob
{
    class EvenWatch
    {
        private ManagementEventWatcher manEWatch;
        
        public EvenWatch(string host) 
        {   
            
        System.Management.ManagementScope oMs = new System.Management
        .ManagementScope(@"\\" +host + @"\root\cimv2");              
        oMs.Connect();
        manEWatch = new ManagementEventWatcher(oMs,new EventQuery("SELECT * FROM    __InstanceCreationEvent WITHIN 0.1 WHERE TargetInstance ISA 'Win32_PrintJob'"));
            
            
           
        manEWatch.EventArrived += new EventArrivedEventHandler(
        mewPrintJobs_EventArrived);
        manEWatch.Start();  
        }
        
      static void mewPrintJobs_EventArrived(object sender, EventArrivedEventArgs e)
        {
            foreach (PropertyData prop in e.NewEvent.Properties)
            {
                string val = prop.Value == null ? "null" : prop.Value.ToString();
                
            }

            ManagementBaseObject printJob = (ManagementBaseObject)e.NewEvent.Properties["TargetInstance"].Value;
            string v = "";
            foreach (PropertyData propp in printJob.Properties)
            {
                string name = propp.Name;
                string val = propp.Value == null ? "null" : propp.Value.ToString();
                val += "\n";
                v+=name+":"+val;
                
            }
            System.Windows.Forms.MessageBox.Show(v);
        } 
    }
    }
 
Share this answer
 
Good luck, I've been working on this very problem for over a year.

You have a few options here:
1) Modify the application that does the printing to capture the data. If this is possible, do this. You don't want to mess with the other options unless you absolutely have to.
2) You could use RedMon[^] to redirect the print stream to a program and to a printer. You'll have to figure out how to parse the print stream, and it may change from program to program if you're looking for a generic solution (not as bad if you only need the print output of one program though).
3) Write a custom print driver. I started down this route and didn't have much luck, the Windows print system is a mess.

[Edit] Alright, looks like your problem is a little simpler than I thought, option #2 is your best bet if you really want to write your own program to record the information.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900