The v4 printer driver model supports a new model for extended constraint and PrintTicket handling that is derived from the v3 IPrintOemPrintTicketProvider interface.
Features and options added using CompletePrintCapabilities, as well as constraints specified in validatePrintTicket are not shown in the desktop printer preferences window.
Features and options added in using CompletePrintCapabilities are not persisted into the public DEVMODE.
Interactive debugging can be enabled by creating the following registry key:
Key Name: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print
The test app alone is sufficient to enable debugging, but it is also beneficial to add unit tests to ensure that the whole driver is handling PrintTicket, PrintCapabilities and constraints as expected. For more information on how to build Unit tests in Visual Studio, please see the following topics:
It is important to note that if the source file fails to parse, then the debugger is not invoked and it will seem as if the debug environment has failed. If the source file fails to parse, see Windows Script Host for more information about how to proceed.
If there are no errors and your source file is parsed successfully, debug your source file as follows:
Install Microsoft Visual Studio 2012 or later on the test machine
Set this print queue as the default.
At this time, the “Visual Studio Just-In-Time Debugger” will pop up saying “An unhandled exception occurred in <your app>”
Launch a new instance of Visual Studio 2012 or later
Choose Debug, then Attach To Process
In the Attach to Process dialog, ensure that Attach To: is set to Script code
Now choose the test app or app printing and finally choose Attach
Click on “Break All”
Now go back to the “Visual Studio Just-In-Time Debugger” dialog and click “No”
Visual Studio will break into the debugger at the location called by the current test. You may now debug the code normally.
This API is called in order to validate that a PrintTicket object is valid for a particular printer. This is analogous in function to the IPrintOemPrintTicketProvider::ValidatePrintTicket API.
function validatePrintTicket(printTicket, scriptContext)
[in][out] The IPrintSchemaTicket object to be validated. scriptContext
[in] The IPrinterScriptContext object that provides access to the driver property bag, the queue property bag and the user property bag. Return value
|0||Indicates that the printTicket parameter was invalid and could not be corrected. Equivalent to E_PRINTTICKET_FORMAT.|
|1||Indicates that the printTicket parameter is a valid PrintTicket for this printer. Equivalent to S_PT_NO_CONFLICT.|
|2||Indicates that the printTicket parameter was modified to make it valid. Equivalent to S_PT_CONFLICT_RESOLVED.|
This API is called to allow the PrintCapabilities object to be modified. This should be used for conditional features (for example, borderless is only supported on photo paper) or to represent features that could not otherwise be generated by a GPD or PPD file (for example, nested feature definitions). This is analogous in function to the IPrintOemPrintTicketProvider::CompletePrintCapabilities API.
function completePrintCapabilities(printTicket, scriptContext, printCapabilities)
[in] The IPrintSchemaTicket object input to constrain the generated PrintCapabilities document to. scriptContext
[in] The IPrinterScriptContext object that provides access to the driver property bag, the queue property bag and the user property bag. printCapabilities
[in][out] The IPrintSchemaCapabilities object representing the base PrintCapabilities object that was generated by the configuration module. Return value
This API is called to convert values from the DEVMODE property bag into a PrintTicket. This is analogous in function to the IPrintOemPrintTicketProvider::ConvertDevModeToPrintTicket API, except that this implementation encapsulates the private section of the DEVMODE into an IPrinterScriptablePropertyBag object and allows no access to the public section of the DEVMODE.
function convertDevModeToPrintTicket(devModeProperties, scriptContext, printTicket)
[in] The IPrinterScriptablePropertyBag object representing the DEVMODE Property Bag. scriptContext
[in] The IPrinterScriptContext object that provides access to the driver property bag, the queue property bag and the user property bag. printTicket
[in][out] The IPrintSchemaTicket object representing the PrintTicket. Return value
This API is called to convert values from a PrintTicket into the DEVMODE property bag. This is analogous in function to the IPrintOemPrintTicketProvider::ConvertPrintTicketToDevMode API, except that this implementation encapsulates the private section of the DEVMODE into an IPrinterScriptablePropertyBag object and allows no access to the public section of the DEVMODE.
function convertPrintTicketToDevMode(printTicket, scriptContext, devModeProperties)
[in] The IPrintSchemaTicket object representing the PrintTicket to be converted. scriptContext
[in] The IPrinterScriptContext object that provides access to the driver property bag, the queue property bag and the user property bag. devModeProperties
[in][out] The IPrinterScriptablePropertyBag object representing the DEVMODE Property Bag. Return value
Constraint Best Practices
The Windows 8 print dialog and the print preferences experience support only a subset of the Print Schema Keywords namespace. As a result, Microsoft does not recommend using constraints between features that are supported in the Windows 8 print dialog or print preferences UI and features that are not in that UI, since users will have no opportunity to resolve such constraints.