需要帮助通过XML修改PrintTickets

时间:2021-07-08 21:35:50

Doing some work on controlling printing via the System.Printing framework (main classes are PrintQueue, PrintTicket and PrinterCapabilities). Like with most stuff I've been working on lately, there's damn little information about it. I'm hoping to compile some good information in this question to help flesh out this subject.

通过System.Printing框架(主要类是PrintQueue,PrintTicket和PrinterCapabilities)进行一些控制打印的工作。就像我最近一直在做的大多数事情一样,关于它的信息很少。我希望在这个问题中汇总一些好的信息,以帮助充实这个主题。

PrintTickets give developers a good handle on most common configuration settings for printing. That's fortunate, because I'd hate to have to do it the old DEVMODE way (you can convert DEVMODE binary stream to and from PrintTickets, which is convenient!).

PrintTickets使开发人员能够很好地处理大多数常见的打印配置设置。这是幸运的,因为我讨厌必须以旧的DEVMODE方式(你可以将DEVMODE二进制流转换为PrintTickets和从PrintTickets转换,这很方便!)。

The problem is that there are LOTS of printers, each with unique configurations. These don't fall within the nice properties and enumerations created for PrintTickets. If you have to configure a printer whose settings lay beyond this interface, you have to serialize your PrintTicket to xml and modify it there.

问题是有很多打印机,每个打印机都有独特的配置。这些不属于为PrintTicket创建的不错的属性和枚举。如果必须配置其设置超出此界面的打印机,则必须将PrintTicket序列化为xml并在那里进行修改。

When you are working with PrintTicket xml, your life is ruled by three or more schemas: Two by Microsoft and one or more by the printer manufacturer. The two MS schemas are

当您使用PrintTicket xml时,您的生活由三个或更多模式决定:两个由Microsoft和一个或多个打印机制造商。这两个MS模式是

One of the first issues I've had dealing with the raw xml is that I can't find any XSDs covering these schemas.

我处理raw xml的第一个问题之一就是我找不到任何覆盖这些模式的XSD。

Does anybody know where I can get the XSDs for these schemas?

有谁知道我可以在哪里获得这些模式的XSD?

The second big issue I've encountered was mapping user input to the PrintTicket xml. Optimally, I would want to take a user's input, say "Tray 3", and map that through the PrintCapabilities to determine the value of the option to set for that feature. The documentation for the print capabilities is somewhat unclear, and I'm afraid that its full of edge cases that will come back and bite me if I don't do it right.

我遇到的第二个大问题是将用户输入映射到PrintTicket xml。最理想的情况是,我想要获取用户的输入,比如“Tray 3”,并通过PrintCapabilities将其映射,以确定为该功能设置的选项的值。打印功能的文档有点不清楚,我担心如果我做得不对,它会充满边缘情况会回来咬我。

Does anybody have any good examples for modifying PrintTicket XML?

有没有人有任何修改PrintTicket XML的好例子?

That's a good starting point for this wiki...

这是这个wiki的一个很好的起点......


Update on question 1:

问题1的更新:

Sent an email off to an address I got from a WinHEC PPT dated back in 2005, and got an actual response from Justin Hutchings, the program manager for Windows Experience - Documents and Printing (cool, no?):

发送电子邮件到我从2005年的WinHEC PPT获得的地址,得到了Windows体验 - 文档和打印项目经理Justin Hutchings的实际回复(很酷,没有?):

Will,

There are no XSDs for the Print Schema namespaces. You should review the Print Schema Specification 1.0 and validate your conformance using that. http://www.microsoft.com/whdc/xps/downloads.mspx

Print Schema名称空间没有XSD。您应该查看打印模式规范1.0并使用它验证您的一致性。 http://www.microsoft.com/whdc/xps/downloads.mspx

We also have PrintSchema validation built into PrintVerifier. More information on obtaining and configuring Print Verifier is available at these urls:

我们还在PrintVerifier中内置了PrintSchema验证。有关获取和配置Print Verifier的更多信息,请访问以下网址:

3 个解决方案

#1


Check out the thread about selecting trays at:

查看有关选择托盘的主题:

http://social.msdn.microsoft.com/forums/en-US/windowsxps/thread/f5859148-26f1-4e89-949c-180413bcc898/

CAnderson and Jo0815 are interrogating the PrintQueue's PrintCapabilities to ask for the features related to input bins. After that, they load up the XML from the DefaultPrintTicket into an XMLDocument to insert nodes to specify the bin, write the XMLDocument into stream, and then build a new PrintTicket from that stream. (Probably more straight forward approach as compared to the process of concatenating and then removing duplicates described in Procedure for Creating a WholePrintTicket Class.)

CAnderson和Jo0815正在询问PrintQueue的PrintCapabilities,以询问与输入箱相关的功能。之后,他们将DefaultPrintTicket中的XML加载到XMLDocument中以插入节点以指定bin,将XMLDocument写入流,然后从该流构建新的PrintTicket。 (与连接然后删除在创建WholePrintTicket类的过程中描述的重复项的过程相比,可能更直接的方法。)

The same techniques can be applied to the other features not exposed by the standard PrintTicket.

相同的技术可以应用于标准PrintTicket未公开的其他功能。

#2


It seems like what you are trying to do is described in outline form at:

看起来你正在尝试做的事情在大纲形式中描述:

http://msdn.microsoft.com/en-us/library/aa970573.aspx#ExtendingthePrintTicketClass

#3


There is now a Print Schema Specification (dated 28 July 2013) on Microsoft's website at

现在在微软的网站上有一个打印模式规范(日期为2013年7月28日)

http://msdn.microsoft.com/en-us/windows/hardware/gg463385.aspx

This has a 300+ specification and also includes a schema for http://schemas.microsoft.com/windows/2003/08/printing/printschemaframework

这有300多个规范,还包括http://schemas.microsoft.com/windows/2003/08/printing/printschemaframework的架构

#1


Check out the thread about selecting trays at:

查看有关选择托盘的主题:

http://social.msdn.microsoft.com/forums/en-US/windowsxps/thread/f5859148-26f1-4e89-949c-180413bcc898/

CAnderson and Jo0815 are interrogating the PrintQueue's PrintCapabilities to ask for the features related to input bins. After that, they load up the XML from the DefaultPrintTicket into an XMLDocument to insert nodes to specify the bin, write the XMLDocument into stream, and then build a new PrintTicket from that stream. (Probably more straight forward approach as compared to the process of concatenating and then removing duplicates described in Procedure for Creating a WholePrintTicket Class.)

CAnderson和Jo0815正在询问PrintQueue的PrintCapabilities,以询问与输入箱相关的功能。之后,他们将DefaultPrintTicket中的XML加载到XMLDocument中以插入节点以指定bin,将XMLDocument写入流,然后从该流构建新的PrintTicket。 (与连接然后删除在创建WholePrintTicket类的过程中描述的重复项的过程相比,可能更直接的方法。)

The same techniques can be applied to the other features not exposed by the standard PrintTicket.

相同的技术可以应用于标准PrintTicket未公开的其他功能。

#2


It seems like what you are trying to do is described in outline form at:

看起来你正在尝试做的事情在大纲形式中描述:

http://msdn.microsoft.com/en-us/library/aa970573.aspx#ExtendingthePrintTicketClass

#3


There is now a Print Schema Specification (dated 28 July 2013) on Microsoft's website at

现在在微软的网站上有一个打印模式规范(日期为2013年7月28日)

http://msdn.microsoft.com/en-us/windows/hardware/gg463385.aspx

This has a 300+ specification and also includes a schema for http://schemas.microsoft.com/windows/2003/08/printing/printschemaframework

这有300多个规范,还包括http://schemas.microsoft.com/windows/2003/08/printing/printschemaframework的架构