Пример #1
0
        public void Print()
        {
            List <string> files;

            if (Document is List <string> )
            {
                files = (List <string>)Document;
            }
            else
            {
                files = new List <string>();
                files.Add(Document.ToString());
            }
            if (Settings is PrintDialog)
            {
                PrintDialog pDialog = (PrintDialog)Settings;
                OfficeHelper.ConvertWordToXPS(files);
                foreach (string file in files)
                {
                    string                xpsfile  = file + ".xps";
                    XpsDocument           document = new XpsDocument(xpsfile, FileAccess.Read);
                    FixedDocumentSequence seq      = document.GetFixedDocumentSequence();
                    FileInfo              fileinfo = new FileInfo(file);
                    pDialog.PrintDocument(seq.DocumentPaginator, fileinfo.Name);
                    document.Close();
                }
            }
            else
            {
                // one file only
                if (Printer == null)
                {
                    Printer = printService.GetPrinter();
                }
                if (Printer == null)
                {
                    return;
                }

                string xpsfile = Document.ToString() + ".xps";
                OfficeHelper.ConvertWordToXPS(files);

                PrintQueue  pq      = printService.GetPrintQueue(Printer.ToString());
                PrintDialog pDialog = new PrintDialog();
                pDialog.PageRangeSelection   = PageRangeSelection.AllPages;
                pDialog.UserPageRangeEnabled = true;
                pDialog.PrintQueue           = pq;

                // Display the dialog. This returns true if the user presses the Print button.
                Nullable <Boolean> print = pDialog.ShowDialog();
                if (print == true)
                {
                    XpsDocument           document = new XpsDocument(xpsfile, FileAccess.Read);
                    FixedDocumentSequence seq      = document.GetFixedDocumentSequence();
                    FileInfo file = new FileInfo(Document.ToString());
                    pDialog.PrintDocument(seq.DocumentPaginator, file.Name);
                    //dialog.ShowTaskDialog("Printing complete", "Printed to " + pDialog.PrintQueue.Name, "File printed: " + Document.ToString());
                    document.Close();
                }
            }

            /* more crap that doesn't duplex
             * PrintQueue pq = Common.Services.PrintService.GetPrintQueue(Printer.ToString());
             * if (pq == null)
             * {
             *  dialog.ShowTaskDialog("Printer Problem", "Printer not set up or not available!", "Go to top menu -> Configuration -> My Details to set up your printer");
             *  return;
             * }
             * System.Printing.PrintTicket ticket = pq.DefaultPrintTicket;
             * PrintCapabilities capable = pq.GetPrintCapabilities();
             * if (capable.DuplexingCapability.Contains(Duplexing.TwoSidedLongEdge))
             * {
             *  News.AddMessage("Printer can do duplex");
             *  ticket.Duplexing = Duplexing.TwoSidedLongEdge;
             * }
             * ticket.PageMediaSize = new PageMediaSize(PageMediaSizeName.ISOA4);
             * if (Settings != null)
             * {
             *  if (Settings.ToString().Contains("landscape")) { ticket.PageOrientation = PageOrientation.Landscape; }
             * }
             *
             * XpsDocumentWriter xpsdw = PrintQueue.CreateXpsDocumentWriter(pq);
             * xpsdw.Write(seq, ticket);
             * document.Close();
             */

            /*
             * Word automation crap that doesn't duplex
             * try
             * {
             *  Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
             *  app.Visible = false;
             *  Microsoft.Office.Interop.Word.Document doc = app.Documents.Open(Document);
             *
             *  // print using word
             *  object wb = app.WordBasic;
             *  app.ActivePrinter = Printer.ToString();
             *
             *  if (Settings != null)
             *  {
             *      if (Settings.ToString().Contains("landscape")) { doc.PageSetup.Orientation = WdOrientation.wdOrientLandscape; }
             *  }
             *
             *  app.PrintOut();
             *  app.NormalTemplate.Saved = true;
             *  app.Documents.Close(Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges);
             *  app.Quit();
             * }
             * catch (Exception ex)
             * {
             *  News.AddError("DocxPrinter", ex.Message, ex);
             *  return;
             * }
             */
        }
Пример #2
0
        public void Print()
        {
            if (Settings is PrintDialog)
            {
                PrintDialog pDialog = (PrintDialog)Settings;
                string      xpsfile = Document.ToString() + ".xps";
                OfficeHelper.ConvertPPTXtoXPS(Document.ToString(), xpsfile);
                XpsDocument           document = new XpsDocument(xpsfile, FileAccess.Read);
                FixedDocumentSequence seq      = document.GetFixedDocumentSequence();
                FileInfo file = new FileInfo(Document.ToString());
                pDialog.PrintDocument(seq.DocumentPaginator, file.Name);
                document.Close();
            }
            else
            {
                if (Printer == null)
                {
                    Printer = printService.GetPrinter();
                }
                if (Printer == null)
                {
                    //dialog.ShowTaskDialog("Printer Problem", "Printer not set up or not available!", "Go to top menu -> Configuration -> My Details to set up your printer");
                    return;
                }

                string xpsfile = Document.ToString() + ".xps";
                OfficeHelper.ConvertPPTXtoXPS(Document.ToString(), xpsfile);

                PrintQueue  pq      = printService.GetPrintQueue(Printer.ToString());
                PrintDialog pDialog = new PrintDialog();
                pDialog.PageRangeSelection   = PageRangeSelection.AllPages;
                pDialog.UserPageRangeEnabled = true;
                pDialog.PrintQueue           = pq;

                // Display the dialog. This returns true if the user presses the Print button.
                Nullable <Boolean> print = pDialog.ShowDialog();
                if (print == true)
                {
                    XpsDocument           document = new XpsDocument(xpsfile, FileAccess.Read);
                    FixedDocumentSequence seq      = document.GetFixedDocumentSequence();
                    FileInfo file = new FileInfo(Document.ToString());
                    pDialog.PrintDocument(seq.DocumentPaginator, file.Name);
                    document.Close();
                }
            }

            /*
             * try
             * {
             *  Microsoft.Office.Interop.PowerPoint.Application app;
             *  try
             *  {
             *      app = new Microsoft.Office.Interop.PowerPoint.Application();
             *  }
             *  catch (Exception ex)
             *  {
             *      News.AddError("PrintPPTX", "Problem with PowerPoint", ex);
             *      return;
             *  }
             *  app.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
             *  Microsoft.Office.Interop.PowerPoint.Presentation p = app.Presentations.Open(Document.ToString());
             *  p.PrintOptions.ActivePrinter = Printer.ToString();
             *
             *  if (Settings != null)
             *  {
             *      if (Settings.ToString().Contains("landscape")) { p.PageSetup.Orientation = WdOrientation.wdOrientLandscape; }
             *  }
             *
             *  p.PrintOut();
             *  p.Close();
             *  app.Quit();
             * }
             * catch (Exception ex)
             * {
             *  News.AddError("DocxPrinter", ex.Message, ex);
             *  return;
             * }
             * dialog.ShowTaskDialog("Printing complete", "Printed to " + Printer.ToString(), "File printed: " + Document.ToString());
             */
        }