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.