Is there a way to determine in .Net (or WMI) if a

2019-08-02 09:27发布

Is there a way to determine in .Net (or WMI) if a print driver will print to PCL or PostScript or XPS format when printing to a file?

2条回答
爷、活的狠高调
2楼-- · 2019-08-02 10:01

If your target OS is Windows, one more way is to do some logic on the driver and the print queue. You can use WMI/.NET APIs to get the driver DLL name. If it is unidrv.dll then the driver is a PCL driver and if it is pscript.dll then it is a PS driver. Of course, this is for drivers based on the MS Unidrv/PScript driver framework but you will find that a large majority of your installed based drivers are based on this framework.

查看更多
再贱就再见
3楼-- · 2019-08-02 10:03

You should be able to gather this information via WMI. Win32_Printer.DefaultLanguage is suppose to return this value. If I recall from trying this in the past though, many printer drivers don't return a value.

Check here: http://msdn.microsoft.com/en-us/library/aa394363%28VS.85%29.aspx

Somthing like this 'should' do the trick:

System.Management.ObjectQuery oq = new System.Management.ObjectQuery("SELECT * FROM Win32_Printer");
ManagementObjectSearcher mos = new ManagementObjectSearcher(oq);
ManagementObjectCollection moc = mos.Get();
foreach( ManagementObject mo in moc )
{

    string name = mo["Name"].ToString();
    string language = mo["DefaultLanguage"].ToString();
    MessageBox.Show(String.Format("Printer: {0} -- Language: {1}", name, language);
}

This will return a UInt16, check the link for the translation of 'Default Language' to the English term ie: PCL, Postscript, HPGL etc.

Can I ask why you are trying to determine before hand what the output will be? If it's a print to file process I'd simply look at the output and determine what it is. Most newer print drivers will insert a PJL statement at the top of the job like this

@PJL ENTER LANUGAGE = "PCL"

Or simply look at the code itself for telltale indicators such as the for PCL or %PS for Postscript etc.

查看更多
登录 后发表回答