none
请问PrintTicket的PageScalingFactor设定,为什么没有效果? RRS feed

  • 问题

  • 下面的代码是在WindowsService的,为了测试方便我把它放在了WPF工程里面。

    问题:

    我通过下面的代码进行打印xps文件,可是无论我如何设定PageScalingFactor值,打印出来的文档,

    既没有放大也没有缩小。请问是否是我打印方法不正确?如果是,如何去更正?

    打印机名字:TOSHIBA e-STUDIO4520CSeriesPCL6

    已经安装其驱动程序。

    代码如下
    public partial class MainWindow : Window
        {
            PrintTicket m_pt;

            public MainWindow()
            {
                InitializeComponent();
            }

            private void button1_Click(object sender, RoutedEventArgs e)
            {
                // Printer
                PrintQueue pq = null;
                using (LocalPrintServer ps = new LocalPrintServer())
                {
                    pq = ps.GetPrintQueue("TOSHIBA e-STUDIO4520CSeriesPCL6");
                }

                m_pt = new PrintTicket();
                m_pt = pq.UserPrintTicket.Clone();

                m_pt.PageScalingFactor = 200;

                //System.Printing.ValidationResult result = pq.MergeAndValidatePrintTicket(pq.UserPrintTicket, m_pt);
                //pq.UserPrintTicket = result.ValidatedPrintTicket;
                pq.UserPrintTicket = m_pt;
                pq.Commit();

                // XPSファイルよりFixedDocumentSequence
                FixedDocumentSequence fds = LoadFixedDocumentSequenceFromDocument();
                // XpsDocumentWrite
                XpsDocumentWriter xdwPrint = GetPrintXpsDocumentWriter(pq);

                xdwPrint.WritingPrintTicketRequired += new System.Windows.Documents.Serialization.WritingPrintTicketRequiredEventHandler(xdwPrint_WritingPrintTicketRequired);

                // Print
                xdwPrint.Write(fds);
            }

            private XpsDocumentWriter GetPrintXpsDocumentWriter(PrintQueue pq)
            {
                XpsDocumentWriter xpsdw = PrintQueue.CreateXpsDocumentWriter(pq);
                return xpsdw;
            }

            private FixedDocumentSequence LoadFixedDocumentSequenceFromDocument()
            {
                FixedDocumentSequence seq = null;

                using (XpsDocument xpsDoc = new XpsDocument(@"C:\testxps.XPS", System.IO.FileAccess.Read,
                     System.IO.Packaging.CompressionOption.NotCompressed))
                {
                    seq = xpsDoc.GetFixedDocumentSequence();
                }
                return seq;
            }

            void xdwPrint_WritingPrintTicketRequired(object sender, System.Windows.Documents.Serialization.WritingPrintTicketRequiredEventArgs e)
            {
                switch (e.CurrentPrintTicketLevel)
                {
                    case System.Windows.Xps.Serialization.PrintTicketLevel.FixedDocumentPrintTicket:
                        e.CurrentPrintTicket = m_pt;
                        break;

                    case System.Windows.Xps.Serialization.PrintTicketLevel.FixedDocumentSequencePrintTicket:
                        // FixedDocumentSequencePrintTicket
                        //e.CurrentPrintTicket = m_pt;
                        break;
                    case System.Windows.Xps.Serialization.PrintTicketLevel.FixedPagePrintTicket:
                        // FixedPagePrintTicket
                        //e.CurrentPrintTicket = m_pt;
                        break;
                }
            }
        }

    2012年8月24日 9:30