Click here to Skip to main content
15,888,816 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
hi
I want to create one copy of any jobs in PrinterQueue to another printer.

for example:
I have 2 active printer (defaultprinter & printer2)
when i print any document to defaultprinter i want print in 2 printers (defaultprinter&printer2)
i tried this code in windows form application;
C#
private void Form1_Load(object sender, EventArgs e)
{
    getSystemPrinters();
}

private void getSystemPrinters()
{
    LocalPrintServer ps = new LocalPrintServer();
    PrintQueueCollection pqc = ps.GetPrintQueues();
    foreach (PrintQueue pq in pqc)
    {
        comboBoxDefaultPrinter.Items.Add(pq.FullName);
        comboBoxPrinter2.Items.Add(pq.FullName);
    }
    if (comboBoxDefaultPrinter.Items.Count > 0) comboBoxDefaultPrinter.SelectedIndex = 2;
    comboBoxPrinter2.SelectedIndex = 3;
}

private void btnInitialQueue_Click(object sender, EventArgs e)
{
    LocalPrintServer server = new LocalPrintServer();
    PrintQueueCollection queueCollection = server.GetPrintQueues();
    PrintQueue pq1 = server.GetPrintQueue(comboBoxDefaultPrinter.Text);
    PrintQueue pq2 = server.GetPrintQueue(comboBoxPrinter2.Text);

    ListBoxDefaultPrinterQueue.Items.Clear();
    pq1.Refresh();
    PrintJobInfoCollection jobs1 = pq1.GetPrintJobInfoCollection();
    foreach (PrintSystemJobInfo job in jobs1)
        ListBoxDefaultPrinterQueue.Items.Add(job.JobIdentifier.ToString() + " : " + job.Name + " | " + job.JobStatus.ToString() + " | " + job.JobSize / 1024 + " KByte");

    ListBoxPrinter2Queue.Items.Clear();
    pq2.Refresh();
    PrintJobInfoCollection jobs2 = pq2.GetPrintJobInfoCollection();
    foreach (PrintSystemJobInfo job in jobs2)
        ListBoxPrinter2Queue.Items.Add(job.JobIdentifier.ToString() + " : " + job.Name + " | " + job.JobStatus.ToString() + " | " + job.JobSize / 1024 + " KByte");
}

private void btnCopyQueue_Click(object sender, EventArgs e)
{
    LocalPrintServer server = new LocalPrintServer();            
    PrintQueue DefaultPrinterQueue = server.GetPrintQueue(comboBoxDefaultPrinter.Text);
    PrintQueue Printer2Queue=server.GetPrintQueue(comboBoxPrinter2.Text);

    ListBoxPrinter2Queue.Items.Clear();

    PrintJobInfoCollection jobs = DefaultPrinterQueue.GetPrintJobInfoCollection();
    
    foreach (PrintSystemJobInfo job in jobs)
        Printer2Queue.AddJob(job.Name);        // this Code Not work            
    
    PrintJobInfoCollection jobs2 = Printer2Queue.GetPrintJobInfoCollection();
    foreach (PrintSystemJobInfo job in jobs2)
        ListBoxPrinter2Queue.Items.Add(job.JobIdentifier.ToString() + " : " + job.Name + " " + job.JobStatus.ToString() + " | " + job.JobSize / 1024 + " KByte");
}

on this app when i print a document for example "in office word", i goto this form and click "btnInitialQueue" which this function show defaultprinter queue jobs in list1 then i click "btnCopyQueu" to create copy of jobs of defaultprinter to printer2 but it not work!

on this code "Printer2Queue.AddJob(job.Name); " not work to print job

please help me or if you know better method please help.

thank you.
Posted
Updated 13-May-15 7:09am
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