Esempio n. 1
0
        private async void MainWindow_ContentRendered(object sender, EventArgs e)
        {
            await Task.Delay(1000);

            var pageSize = new Size(1280 * 8, 720 * 8);
            var document = new FixedDocument();

            document.DocumentPaginator.PageSize = pageSize;

            var fixedPage = new FixedPage
            {
                Width  = pageSize.Width,
                Height = pageSize.Height,
            };

            for (int i = 0; i < 100; i++)
            {
                fixedPage.Children.Add(new Border
                {
                    Width      = pageSize.Width,
                    Height     = pageSize.Height,
                    Background = new VisualBrush
                    {
                        Visual = DemoImage,
                    }
                });
            }
            fixedPage.Measure(pageSize);
            fixedPage.Arrange(new Rect(new Point(), pageSize));
            fixedPage.UpdateLayout();

            // Add page to document
            var pageContent = new PageContent();

            ((IAddChild)pageContent).AddChild(fixedPage);
            document.Pages.Add(pageContent);

            // Send to the printer.
            var pd = new PrintDialog();

            pd.PrintDocument(document.DocumentPaginator, "正在打印……");

            return;

            using var _localPrintServer = new LocalPrintServer();
            var _currentPrintQueue = _localPrintServer.DefaultPrintQueue;

            _xpsDocumentWriter = PrintQueue.CreateXpsDocumentWriter(_currentPrintQueue);
            //_xpsDocumentWriter.WritingProgressChanged += XpsDocumentWriter_WritingProgressChanged;
            //_xpsDocumentWriter.WritingPrintTicketRequired += XpsDocumentWriterOnWritingPrintTicketRequired;
            //_xpsDocumentWriter.WritingCancelled += XpsDocumentWriterOnWritingCancelled;
            //_xpsDocumentWriter.WritingCompleted += XpsDocumentWriterOnWritingCompleted;
            _vToXspd = (VisualsToXpsDocument)_xpsDocumentWriter.CreateVisualsCollator();
            _vToXspd.BeginBatchWrite();
            for (int i = 0; i < 100; i++)
            {
                _vToXspd?.WriteAsync(RootPanel);
            }
            _vToXspd?.EndBatchWrite();
        }
Esempio n. 2
0
        public static string SaveXPS2(Visual page, Visual page1, bool isSaved, string strType)
        {
            string containerName = GetXPSFromDialog(isSaved, strType);

            if (containerName != null)
            {
                try
                {
                    File.Delete(containerName);
                }
                catch (Exception e)
                {
                    //  MessageWindow3.Show(e.Message);
                }

                XpsDocument          _xpsDocument = new XpsDocument(containerName, FileAccess.Write);
                XpsDocumentWriter    xpsdw        = XpsDocument.CreateXpsDocumentWriter(_xpsDocument);
                VisualsToXpsDocument xpsdw1       = (VisualsToXpsDocument)xpsdw.CreateVisualsCollator();

                xpsdw1.Write(page);
                xpsdw1.Write(page1);//写入XPS文件
                //xpsdw1.Write(page);
                xpsdw1.EndBatchWrite();
                //xpsdw.Write(((IDocumentPaginatorSource)page).DocumentPaginator);
                _xpsDocument.Close();
            }
            return(containerName);
            //}
            //else
            //{
            //    return false;
            //}
            //}
        }
Esempio n. 3
0
        private void saveVisuals(XpsDocumentWriter xpsdw, List <Visual> vc)
        {
            VisualsToXpsDocument vtoxps = (VisualsToXpsDocument)xpsdw.CreateVisualsCollator();

            foreach (Visual v in vc)
            {
                vtoxps.Write(v);
            }

            vtoxps.EndBatchWrite();
        }
Esempio n. 4
0
        /// <summary>
        /// 印刷ダイアログを出さずに既定のプリンタで画面のグリッドを印刷します。
        /// </summary>
        private void PrintXpsDocument2()
        {
            var lps = new LocalPrintServer();
            var q   = lps.DefaultPrintQueue;
            XpsDocumentWriter xps = PrintQueue.CreateXpsDocumentWriter(q);

            VisualsToXpsDocument vs = (VisualsToXpsDocument)xps.CreateVisualsCollator();

            vs.Write(this.grid1);
            vs.EndBatchWrite();
        }
Esempio n. 5
0
        //</SnippetWriteToXpsWithVisual>

        //<SnippetCreateAndWriteToVisualsCollator>
        private void SaveVisuals(XpsDocumentWriter xpsdw, List <Visual> vc)
        {
            // Setup for writing multiple visuals
            VisualsToXpsDocument vToXpsD = (VisualsToXpsDocument)xpsdw.CreateVisualsCollator();

            // Iterate through all visuals in the collection
            foreach (Visual v in vc)
            {
                vToXpsD.Write(v);   //Write each visual to single page
            }

            // End writing multiple visuals
            vToXpsD.EndBatchWrite();
        }
Esempio n. 6
0
        public static void Save(MainViewModel viewModel, string path)
        {
            using (XpsDocument xpsdoc = new XpsDocument(path, FileAccess.Write))
            {
                XpsDocumentWriter    xpsdw   = XpsDocument.CreateXpsDocumentWriter(xpsdoc);
                VisualsToXpsDocument vToXpsD = (VisualsToXpsDocument)xpsdw.CreateVisualsCollator();

                var fixedDoc = new FixedDocument();

                var objReportToPrint = new ToPrint();

                var ReportToPrint = objReportToPrint as UserControl;
                ReportToPrint.DataContext = viewModel;

                vToXpsD.Write(ReportToPrint);
                vToXpsD.EndBatchWrite();
            }
        }
Esempio n. 7
0
        private void btnPrintVisuals_Click(object sender, RoutedEventArgs e)
        {
            //Get hold of the visual you want to print.
            List <Visual> visuals = GetVisuals();

            // Create a Print dialog.
            PrintDialog printDialog = new PrintDialog();

            if (printDialog.ShowDialog() != true)
            {
                return;
            }

            // Get the default print queue
            PrintQueue printQueue = printDialog.PrintQueue;

            // Get an XpsDocumentWriter for the default print queue
            XpsDocumentWriter xpsdw = PrintQueue.CreateXpsDocumentWriter(printQueue);

            VisualsToXpsDocument vtxd =
                (VisualsToXpsDocument)xpsdw.CreateVisualsCollator();

            //Indicate we want any writes to be performed in a batch operation.
            vtxd.BeginBatchWrite();

            //Write out each visual.
            visuals.ForEach(delegate(Visual visual)
            {
                //Scale the visual
                Visual scaledVisual = ScaleVisual(visual, printQueue);

                vtxd.Write(scaledVisual);
            });

            //Mark the end of the batch operation.
            vtxd.EndBatchWrite();
        }