0

我正在尝试拦截打印机作业并更改打印作业的属性。我可以拦截打印作业并获取有关它的信息。我为此关注了这篇文章

http://www.codeproject.com/Questions/423178/printing-order-intercept-with-csharp

现在我想更改打印作业的纸张尺寸,为此我找到了这篇文章

http://social.msdn.microsoft.com/Forums/en/windowsxps/thread/8af6ba92-5d2c-444b-91f4-a8747739c1b7

但问题是我无法创建类 PrintCapabilities。我错过了什么吗?请帮忙。

我当前的代码如下所示:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;
using System.Printing;

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;

            }

            PrintQueue printerSpooler = null;
            printerSpooler = new PrintQueue(new PrintServer(), "EPSON LQ-300+ /II ESC/P 2");
            PrintJobSettings printJobSetting = printerSpooler.CurrentJobSettings;
            string desc = printJobSetting.Description;



            //printerSpooler.CurrentJobSettings.CurrentPrintTicket

            Console.WriteLine("-------");
            Console.WriteLine(v);
        }
    }
}
4

1 回答 1

1

我真的找到了答案。如果您使用的是 4.0,您还应该引用 ReachFramework.dll,一旦您这样做了,魔法确实发生了 :)

于 2013-02-27T10:51:03.880 回答