当前位置: 首页>>代码示例>>C#>>正文


C# PrintTicket.GetXmlStream方法代码示例

本文整理汇总了C#中PrintTicket.GetXmlStream方法的典型用法代码示例。如果您正苦于以下问题:C# PrintTicket.GetXmlStream方法的具体用法?C# PrintTicket.GetXmlStream怎么用?C# PrintTicket.GetXmlStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PrintTicket的用法示例。


在下文中一共展示了PrintTicket.GetXmlStream方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ModifyPrintTicket

        public static PrintTicket ModifyPrintTicket(PrintTicket ticket, string featureName, string newValue)
        {
            if (ticket == null)
            {
                throw new ArgumentNullException("ticket");
            }

            var xmlDoc = new XmlDocument();
            xmlDoc.Load(ticket.GetXmlStream());

            var manager = new XmlNamespaceManager(xmlDoc.NameTable);
            manager.AddNamespace(xmlDoc.DocumentElement.Prefix, xmlDoc.DocumentElement.NamespaceURI);

            var xpath = string.Format("//psf:Feature[contains(@name, 'InputBin')]/psf:Option", featureName);
            var node = xmlDoc.SelectSingleNode(xpath, manager);
            if (node != null)
            {
                node.Attributes["name"].Value = newValue;
            }

            var printTicketStream = new MemoryStream();
            xmlDoc.Save(printTicketStream);
            printTicketStream.Position = 0;
            var modifiedPrintTicket = new PrintTicket(printTicketStream);
            return modifiedPrintTicket;
        }
开发者ID:modulexcite,项目名称:printengine,代码行数:26,代码来源:XpsPrinterUtils.cs

示例2: ModifyPrintTicket

        public static PrintTicket ModifyPrintTicket(PrintTicket ticket, string featureName, string newValue)
        {
            if (ticket == null)
            {
                throw new ArgumentNullException("ticket");
            }

            // read Xml of the PrintTicket
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(ticket.GetXmlStream());

            // create NamespaceManager and add PrintSchemaFrameWork-Namespace hinzufugen (should be on DocumentElement of the PrintTicket)
            // Prefix: psf NameSpace: xmlDoc.DocumentElement.NamespaceURI = "http://schemas.microsoft.com/windows/2003/08/printing/printschemaframework"
            XmlNamespaceManager manager = new XmlNamespaceManager(xmlDoc.NameTable);
            manager.AddNamespace(xmlDoc.DocumentElement.Prefix, xmlDoc.DocumentElement.NamespaceURI);

            // search node with desired feature we're looking for and set newValue for it
            string xpath = string.Format("//psf:Feature[@name='{0}']/psfSurpriseption", featureName);
            XmlNode node = xmlDoc.SelectSingleNode(xpath, manager);
            if (node != null)
            {
                node.Attributes["name"].Value = newValue;
            }

            // create a new PrintTicket out of the XML
            MemoryStream printTicketStream = new MemoryStream();
            xmlDoc.Save(printTicketStream);
            printTicketStream.Position = 0;
            PrintTicket modifiedPrintTicket = new PrintTicket(printTicketStream);

            // for testing purpose save the printticket to file
            //FileStream stream = new FileStream("modPrintticket.xml", FileMode.CreateNew, FileAccess.ReadWrite);
            //modifiedPrintTicket.GetXmlStream().WriteTo(stream);

            return modifiedPrintTicket;
        }
开发者ID:alexanderwieland,项目名称:PrintTicket,代码行数:36,代码来源:Program.cs


注:本文中的PrintTicket.GetXmlStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。