有没有办法在 .Net(或 WMI)中确定打印驱动程序在打印到文件时是否打印为 PCL 或 PostScript 格式?

发布于 2024-08-07 05:24:21 字数 72 浏览 3 评论 0原文

有没有办法在 .Net(或 WMI)中确定打印驱动程序在打印到文件时是否会打印为 PCL、PostScript 或 XPS 格式?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

两人的回忆 2024-08-14 05:24:21

如果您的目标操作系统是 Windows,另一种方法是在驱动程序和打印队列上执行一些逻辑。您可以使用 WMI/.NET API 来获取驱动程序 DLL 名称。如果是 unidrv.dll,则该驱动程序是 PCL 驱动程序,如果是 pscript.dll,则该驱动程序是 PS 驱动程序。当然,这是针对基于 MS Unidrv/PScript 驱动程序框架的驱动程序,但您会发现您安装的大部分驱动程序都基于此框架。

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.

Oo萌小芽oO 2024-08-14 05:24:21

您应该能够通过 WMI 收集此信息。 Win32_Printer.DefaultLanguage 应该返回此值。如果我记得过去尝试过此操作,许多打印机驱动程序不会返回值。

检查这里:
http://msdn.microsoft.com/en- us/library/aa394363%28VS.85%29.aspx

这样的东西“应该”可以解决问题:

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);
}

这将返回 UInt16,检查“默认语言”到英语术语的翻译的链接,即: PCL、Postscript、HPGL 等。

请问您为什么要尝试事先确定输出是什么?如果它是打印到文件过程,我只需查看输出并确定它是什么。大多数较新的打印驱动程序都会在作业顶部插入 PJL 语句,如下所示

@PJL ENTER LANUGAGE = "PCL"

或者只需查看代码本身以获取指示性指示符,例如 for PCL 或 %PS for Postscript 等。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文