Esempio n. 1
0
        private static PrintQueue GetPrintQueue()
        {
            PrintQueue printQueue = null;
            bool       finished   = false;

            //  window.Dispatcher.BeginInvoke(new Action(() =>
            // {
            System.Windows.Controls.PrintDialog dlg = new System.Windows.Controls.PrintDialog();
            bool?bPrint = dlg.ShowDialog();

            if (bPrint.GetValueOrDefault())
            {
                printQueue = dlg.PrintQueue;
                try
                {
                    System.Printing.ValidationResult result = printQueue.MergeAndValidatePrintTicket(printQueue.UserPrintTicket, dlg.PrintTicket);
                    printQueue.UserPrintTicket = result.ValidatedPrintTicket;
                    printQueue.Commit();
                }
                catch (Exception ex)
                {
                }
            }
            //      finished = true;
            //   }));

            //   while (!finished)
            //       Thread.Sleep(10);

            return(printQueue);
        }
Esempio n. 2
0
        private static PrintDialog AdjustPrinterCapabilities()
        {
            PrintTicket printTicket = new PrintTicket();

            printTicket.PageOrientation = PageOrientation.Portrait;
            printTicket.PageMediaSize   = new PageMediaSize(PageMediaSizeName.ISOA4, 2480, 3508);
            System.Printing.ValidationResult validationResult = m_printDialog.PrintQueue.MergeAndValidatePrintTicket(m_printDialog.PrintTicket, printTicket);
            m_printDialog.PrintTicket = validationResult.ValidatedPrintTicket;
            m_printDialog.PrintQueue.Commit();

            return(m_printDialog);
        }
Esempio n. 3
0
        /* Set up the print ticket */
        private PrintTicket SetUpTicket(PrintQueue queue, Print printcontrol,
                                        FixedDocumentSequence fixdoc, bool tempfile)
        {
            PrintTicket Ticket = new PrintTicket();

            PageMediaSizeName name      = PaperKindToPageMediaSize(printcontrol.m_pagedetails.PaperSize.Kind);
            PageMediaSize     mediasize = new PageMediaSize(name, printcontrol.m_pagedetails.PaperSize.Width, printcontrol.m_pagedetails.PaperSize.Height);

            /* Media size */
            Ticket.PageMediaSize = mediasize;
            /* Scale to fit */
            Ticket.PageScalingFactor = (int)Math.Round(printcontrol.m_page_scale * 100.0);

            System.Windows.Size page_size = new System.Windows.Size(mediasize.Width.Value, mediasize.Height.Value);
            DocumentPaginator   paginator = fixdoc.DocumentPaginator;

            paginator.PageSize = page_size;

            /* Copy Count */
            Ticket.CopyCount = printcontrol.m_numcopies;

            if (printcontrol.m_pagedetails.Landscape)
            {
                Ticket.PageOrientation = PageOrientation.Landscape;
            }
            else
            {
                Ticket.PageOrientation = PageOrientation.Portrait;
            }

            /* Orientation. If we had a tempfile, then gs did a conversion
             * and adjusted everything for us.  Other wise we may need to
             * rotate the document if it was xps to start with. */
            if (printcontrol.m_isrotated && !tempfile)
            {
                if (printcontrol.m_pagedetails.Landscape)
                {
                    Ticket.PageOrientation = PageOrientation.Portrait;
                }
                else
                {
                    Ticket.PageOrientation = PageOrientation.Landscape;
                }
            }

            System.Printing.ValidationResult result = queue.MergeAndValidatePrintTicket(queue.UserPrintTicket, Ticket);
            queue.UserPrintTicket = result.ValidatedPrintTicket;
            queue.Commit();
            return(result.ValidatedPrintTicket);
        }
        public void LoadPrintTicket(PrintDialog dialog)
        {
            string configFile = Path.Combine(Settings.SessionFolder, ServiceProvider.Settings.DefaultSession.Name + "_printer.xml");

            PrintTicket defaultTicket;

            try
            {
                defaultTicket = dialog.PrintQueue.UserPrintTicket ?? dialog.PrintQueue.DefaultPrintTicket;
            }
            catch (Exception e)
            {
                Log.Error("Unable to load printer settings.", e);
                return;
            }

            if (File.Exists(configFile))
            {
                try
                {
                    using (FileStream stream = new FileStream(configFile, FileMode.Open))
                    {
                        PrintTicket newTicket = new PrintTicket(stream);

                        System.Printing.ValidationResult result = dialog.PrintQueue.MergeAndValidatePrintTicket(defaultTicket, newTicket);
                        dialog.PrintTicket = result.ValidatedPrintTicket;
                        stream.Close();
                    }
                }
                catch (Exception e)
                {
                    Log.Error("Unable to load printer settings.", e);
                    dialog.PrintTicket = defaultTicket;
                }
            }
            else
            {
                if (defaultTicket != null)
                {
                    dialog.PrintTicket = defaultTicket;
                }
            }
        }