locked
Unicode values in Print Ticket come as "?????" (question marks) into JavaScript convertPrintTicketToDevMode.

    Question

  • Hello!

    We are developing V4 printer driver and encountered the following problem:

    When we create unicode string values in Print Ticket with our Printer Extension (for example, as a string-valued ScoredProperty), these unicode values are converted to the strings of question marks (like "??????") when calling convertPrintTicketToDevMode in a JavaScript constraint script.

    This happens when JavaScript is called from explorer.exe process (i.e. when user opens Printing preferences from "Devices and Printers" control panel), but does not seem to happen when JavaScript is called from Printer Extension process (for example when it calls ValidateAsync).

    We checked whether the same problem happens with Printer extension sample or not, and we found that it happens. You can check it if you add a call to sample ModifyPrintTicketXml function before calling ValidateSync, and change ModifyPrintTicketXml as follows:

            /// <summary>
            /// Demonstrates how to modify print ticket XML. This piece of code does not perform any functionality. 
            /// It serves to demonstrate the usage of IPrintSchemaTicket::GetReadStream()/GetWriteStream()
            /// </summary>
            private void ModifyPrintTicketXml()
            {
                //
                // Load the ticket XML (as a Stream) into an XElement object.
                //
    
                XElement ticketRootXElement = null;
                using (Stream ticketReadStream = displayedPrintTicket.GetReadStream())
                {
                    ticketRootXElement = XElement.Load(ticketReadStream);
                }
    
                //
                // Perform any modifications on the XElement object.
                //
                ticketRootXElement.Add(new XElement(psf.GetName("Property"),
                    new XAttribute("name", "ns0000:TestProperty"),
                    new XElement(psf.GetName("Value"),
                        new XAttribute(xsi.GetName("type"), "xsd:string"),
                        "ㅊㅌㅍㅌ")));
    
                //
                // Write the changes back to the print ticket.
                //
                using (Stream ticketWriteStream = displayedPrintTicket.GetWriteStream())
                {
                    ticketRootXElement.Save(ticketWriteStream);
                }
            }
    
    Then when you press OK in printing preferences and debug JavaScript, you will see that the value of "ns0000:TestProperty" is correct when JavaScript is called from PrinterExtensionSample.exe process, but comes as "????", when JavaScript is called from explorer.exe.

    Is that an OS bug, or we did something wrong?

    Thank you,

    Dmitry.

    Tuesday, July 24, 2012 5:43 PM

Answers

  • Hello Eric,

    Yes, this issue is still there in the RTM build.

    We submitted a bug report to Microsoft some time ago. As far as I know, this issue will be fixed in GA release.

    Best regards,

    Dmitry.

    Wednesday, September 26, 2012 7:03 AM

All replies

  • Dmitry,

    Looks like you're adding double byte characters to the PrintTicket. You should confirm that your PrintTicket explicitly indicates it is encoded in UTF-16 in the <?xml?> tag at the top of the document, or the characters won't be properly encoded.

    Thanks!

    Justin

    Tuesday, July 24, 2012 8:35 PM
  • Justin,

    Yes, these characters are double byte, but they are double byte in XElement object which holds PrintTicket xml. Anyway, when this XElement is stored to the stream by the XElement.Save method, it converts these characters to UTF-8 and also adds correct tag <?xml version="1.0" encoding="utf-8"?> to the beginning of the stream, so xml encoding is correct when saved back to PrintTicket. This can be easily checked if you try to save XElement, for example, to FileStream instead of PrintTicket stream.

    Anyway, I also tried to save XElement to PrintTicket stream as UTF-16 and explicitely indicate UTF-16 encoding in <?xml?> tag, as you suggested:

                using (Stream ticketWriteStream = displayedPrintTicket.GetWriteStream())
                using (var writer = new StreamWriter(ticketWriteStream, Encoding.Unicode))
                {
                    var document = new XDocument(new XDeclaration("1.0", "UTF-16", null), ticketRootXElement);
                    document.Save(writer);
                }
    

    But this caused another problem - after closing printer extension, the standard printing preferences UI pops up and the print ticket from printer extension is not saved at all.

    Wednesday, July 25, 2012 2:06 PM
  • Kondakovdmitry,

    Are you still seeing this issue?

    Best Wishes  - Eric

    Tuesday, September 25, 2012 11:19 PM
    Moderator
  • Hello Eric,

    Yes, this issue is still there in the RTM build.

    We submitted a bug report to Microsoft some time ago. As far as I know, this issue will be fixed in GA release.

    Best regards,

    Dmitry.

    Wednesday, September 26, 2012 7:03 AM