Exemplo n.º 1
0
        public Task PrintCanvasAsync(Canvas canvas, CancellationToken token = default(CancellationToken))
        {
            System.Windows.Controls.PrintDialog     printDialog      = new System.Windows.Controls.PrintDialog();
            System.Drawing.Printing.PrinterSettings printer          = new System.Drawing.Printing.PrinterSettings();
            System.Printing.LocalPrintServer        localPrintServer = new System.Printing.LocalPrintServer();

            System.Printing.PrintTicket pt = new System.Printing.PrintTicket();
            System.Printing.PrintQueue  pq = new System.Printing.PrintQueue(localPrintServer, printer.PrinterName, System.Printing.PrintSystemDesiredAccess.UsePrinter);

            System.Printing.PageMediaSize PMS      = new System.Printing.PageMediaSize(canvas.ActualWidth + 20, canvas.ActualHeight + 20);
            System.Windows.Size           pageSize = new System.Windows.Size(canvas.ActualWidth + 20, canvas.ActualHeight + 20);
            canvas.Arrange(new Rect(0, 0, pageSize.Width, pageSize.Height));
            canvas.Measure(pageSize);

            pt.PageMediaSize = PMS;
            pt.PageMediaType = System.Printing.PageMediaType.Unknown;

            pq.DefaultPrintTicket.PageMediaSize = PMS;
            pq.DefaultPrintTicket.PageMediaType = System.Printing.PageMediaType.Unknown;

            printDialog.PrintQueue  = pq;
            printDialog.PrintTicket = pt;
            //printDialog.PrintQueue.Commit();

            if (printDialog.ShowDialog() == true)
            {
                printDialog.PrintVisual(canvas, "Состояние холста");
            }
            return(Task.FromResult(0)); //Task.CompletedTask;
        }
Exemplo n.º 2
0
 public abstract void WriteAsync(System.Windows.Media.Visual visual, System.Printing.PrintTicket printTicket, Object userState);
Exemplo n.º 3
0
 public abstract void WriteAsync(System.Windows.Media.Visual visual, System.Printing.PrintTicket printTicket);
Exemplo n.º 4
0
 public abstract void WriteAsync(System.Windows.Documents.FixedDocumentSequence fixedDocumentSequence, System.Printing.PrintTicket printTicket);
Exemplo n.º 5
0
 public abstract void WriteAsync(System.Windows.Documents.FixedPage fixedPage, System.Printing.PrintTicket printTicket, object userState);
Exemplo n.º 6
0
 public abstract void WriteAsync(System.Windows.Documents.DocumentPaginator documentPaginator, System.Printing.PrintTicket printTicket, object userState);
Exemplo n.º 7
0
 public abstract void Write(System.Windows.Documents.FixedPage fixedPage, System.Printing.PrintTicket printTicket);
Exemplo n.º 8
0
 public abstract void Write(System.Windows.Documents.DocumentPaginator documentPaginator, System.Printing.PrintTicket printTicket);
Exemplo n.º 9
0
 public abstract System.Windows.Documents.Serialization.SerializerWriterCollator CreateVisualsCollator(System.Printing.PrintTicket documentSequencePT, System.Printing.PrintTicket documentPT);
Exemplo n.º 10
0
        protected MatrixBase()
        {
            this.CommandCopyToClipboard = new DelegateCommand(
                this.CopyToClipboard,
                () =>
            {
                return(this.HasData);
            });

            this.CommandPrint = new DelegateCommand(
                () =>
            {
                var section           = Helpers.FormatHelper.MatrixToFlowDocumentSectionWithTable(this);
                var flowDocument      = new System.Windows.Documents.FlowDocument(section);
                flowDocument.FontSize = 11d;

                System.Windows.Controls.PrintDialog pd = new System.Windows.Controls.PrintDialog();
                System.Printing.PrintTicket pt         = new System.Printing.PrintTicket();
                pt.PageOrientation = System.Printing.PageOrientation.Landscape;
                pd.PrintTicket     = pd.PrintQueue.MergeAndValidatePrintTicket(pd.PrintQueue.DefaultPrintTicket, pt).ValidatedPrintTicket;

                System.Windows.Documents.IDocumentPaginatorSource fdd = flowDocument;
                flowDocument.PageWidth   = pd.PrintableAreaWidth;
                flowDocument.PageHeight  = pd.PrintableAreaHeight;
                flowDocument.ColumnWidth = pd.PrintableAreaWidth;
                flowDocument.PagePadding = new Thickness(30.0, 50.0, 20.0, 30.0);
                flowDocument.IsOptimalParagraphEnabled = true;
                flowDocument.IsHyphenationEnabled      = true;

                var ms = new System.IO.MemoryStream();
                using (var pkg = System.IO.Packaging.Package.Open(ms, System.IO.FileMode.Create))
                {
                    using (System.Windows.Xps.Packaging.XpsDocument doc = new System.Windows.Xps.Packaging.XpsDocument(pkg))
                    {
                        System.Windows.Xps.XpsDocumentWriter writer = System.Windows.Xps.Packaging.XpsDocument.CreateXpsDocumentWriter(doc);
                        writer.Write(fdd.DocumentPaginator);
                    }
                }

                ms.Position = 0;
                var pkg2    = System.IO.Packaging.Package.Open(ms);

                // Read the XPS document into a dynamically generated
                // preview Window
                var url = new Uri("memorystream://printstream");
                System.IO.Packaging.PackageStore.AddPackage(url, pkg2);
                try
                {
                    using (System.Windows.Xps.Packaging.XpsDocument doc = new System.Windows.Xps.Packaging.XpsDocument(pkg2, System.IO.Packaging.CompressionOption.SuperFast, url.AbsoluteUri))
                    {
                        System.Windows.Documents.FixedDocumentSequence fds = doc.GetFixedDocumentSequence();

                        Window wnd = new Window();
                        wnd.Title  = string.Format("Предварительный просмотр :: {0}", this.Header);
                        wnd.Owner  = Application.Current.MainWindow;
                        System.Windows.Media.TextOptions.SetTextFormattingMode(wnd, System.Windows.Media.TextFormattingMode.Display);
                        wnd.Padding = new Thickness(2);
                        wnd.Content = new System.Windows.Controls.DocumentViewer()
                        {
                            Document = fds,
                        };
                        wnd.ShowDialog();
                    }
                }
                finally
                {
                    System.IO.Packaging.PackageStore.RemovePackage(url);
                }
            },
                () =>
            {
                return(this.HasData);
            });

            this.CommandRefresh = new DelegateCommand(this.Build, () => this.HasData);
        }