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

我只是一个虾纸丫 提交于 2019-12-11 04:14:26

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/1534207/is-there-a-way-to-determine-in-net-or-wmi-if-a-print-driver-will-print-to-pcl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!