示例#1
0
        /// <summary>
        /// This is the event handler for PrintDocument.Paginate. It creates print preview pages for the app.
        /// </summary>
        /// <param name="sender">PrintDocument</param>
        /// <param name="e">Paginate Event Arguments</param>
        protected virtual void CreatePrintPreviewPages(object sender, PaginateEventArgs e)
        {
            // Clear the cache of preview pages
            printPreviewPages.Clear();

            PrintTaskOptions     printingOptions      = ((PrintTaskOptions)e.PrintTaskOptions);
            PrintPageDescription printPageDescription = printingOptions.GetPageDescription(0);

            foreach (Page page in this.PagesToPrint)
            {
                // Set "paper" width
                page.Width  = printPageDescription.PageSize.Width;
                page.Height = printPageDescription.PageSize.Height;

                // Get the margins size
                // If the ImageableRect is smaller than the app provided margins use the ImageableRect
                double marginWidth  = Math.Max(printPageDescription.PageSize.Width - printPageDescription.ImageableRect.Width, printPageDescription.PageSize.Width * ApplicationContentMarginLeft * 2);
                double marginHeight = Math.Max(printPageDescription.PageSize.Height - printPageDescription.ImageableRect.Height, printPageDescription.PageSize.Height * ApplicationContentMarginTop * 2);

                Grid printableArea = (Grid)page.FindName("printableArea");

                // Set-up "printable area" on the "paper"
                printableArea.Width  = page.Width - marginWidth;
                printableArea.Height = page.Height - marginHeight;

                printPreviewPages.Add(page);
            }

            PrintDocument printDoc = (PrintDocument)sender;

            // Report the number of preview pages created
            printDoc.SetPreviewPageCount(printPreviewPages.Count, PreviewPageCountType.Intermediate);
        }
示例#2
0
        private void RegisterForPrinting()
        {
            PrintDocument pd = new PrintDocument();

            pd.Paginate += (a, b) =>
            {
                pd.SetPreviewPageCount(1, PreviewPageCountType.Final);
            };
            pd.AddPages += (a, b) =>
            {
                pd.AddPage(webReceipt);
                pd.AddPagesComplete();
            };
            pd.GetPreviewPage += (a, b) =>
            {
                pd.SetPreviewPage(b.PageNumber, webReceipt);
            };

            PrintManager.GetForCurrentView().PrintTaskRequested += (sender, e) => e.Request.CreatePrintTask("Účtenka RestSys", async args =>
            {
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    args.SetSource(pd.DocumentSource);
                });
            });
        }
示例#3
0
        /// <summary>
        /// This is the event handler for PrintDocument.Paginate. It creates print preview pages for the app.
        /// </summary>
        /// <param name="sender">PrintDocument</param>
        /// <param name="e">Paginate Event Arguments</param>
        private void CreatePrintPreviewPages(object sender, PaginateEventArgs e)
        {
            // Clear the cache of preview pages
            ClearPageCache();

            // Clear the print canvas of preview pages
            _printCanvas.Children.Clear();

            // Get the PrintTaskOptions
            PrintTaskOptions printingOptions = e.PrintTaskOptions;

            // Get the page description to determine how big the page is
            PrintPageDescription pageDescription = printingOptions.GetPageDescription(0);

            foreach (var element in _elementsToPrint)
            {
                AddOnePrintPreviewPage(element, pageDescription);
            }

            OnPreviewPagesCreated?.Invoke(_printPreviewPages);

            PrintDocument printDoc = (PrintDocument)sender;

            // Report the number of preview pages created
            printDoc.SetPreviewPageCount(_printPreviewPages.Count, PreviewPageCountType.Intermediate);
        }
示例#4
0
        private void PrintDic_Paginate(object sender, PaginateEventArgs e)
        {
            PrintTaskOptions       opt = task.Options;
            PrintTaskOptionDetails printDetailedOptions = PrintTaskOptionDetails.GetFromPrintTaskOptions(e.PrintTaskOptions);

            printDoc.SetPreviewPageCount(1, PreviewPageCountType.Final);
        }
        /// <summary>
        /// This is the event handler for PrintDocument.Paginate.
        /// It fires when the PrintManager requests print preview
        /// </summary>
        /// <param name="sender">PrintDocument</param>
        /// <param name="e">Paginate Event Arguments</param>
        private void Paginate(object sender, PaginateEventArgs e)
        {
            if (pages.Count > 0)
            {
                pages.Clear();
            }
            var mgr = new C1RichTextViewManager {
                Document = rtb.Document
            };
            var layout      = rtb.ViewManager.PresenterInfo as C1PageLayout;
            var contentSize = new Size(layout.Width - layout.Padding.Left - layout.Padding.Right, layout.Height - layout.Padding.Top - layout.Padding.Bottom);

            // print the pages outside the visual tree
            var elements = mgr.OfflinePaint(contentSize).ToList();

            foreach (var el in elements)
            {
                var page   = (Grid)printTemplate.LoadContent();
                var canvas = el as Canvas;
                if (canvas != null)
                {
                    canvas.Margin = layout.Padding;
                }
                page.Children.Clear();
                page.Children.Add(canvas);
                pages.Add(page);
            }
            PrintDocument printDoc = (PrintDocument)sender;

            // Report the number of preview pages
            printDoc.SetPreviewPageCount(pages.Count, PreviewPageCountType.Intermediate);
        }
示例#6
0
        void printDocument_Paginate(object sender, PaginateEventArgs e)
        {
            pages.Clear();
            PrintContainer.Children.Clear();

            RichTextBlockOverflow lastRTBOOnPage;
            PrintTaskOptions      printingOptions = ((PrintTaskOptions)e.PrintTaskOptions);
            PrintPageDescription  pageDescription = printingOptions.GetPageDescription(0);

            lastRTBOOnPage = AddOnePrintPreviewPage(null, pageDescription);

            while (lastRTBOOnPage.HasOverflowContent && lastRTBOOnPage.Visibility == Windows.UI.Xaml.Visibility.Visible)
            {
                lastRTBOOnPage = AddOnePrintPreviewPage(lastRTBOOnPage, pageDescription);
            }

            if (pagesCreated != null)
            {
                pagesCreated.Invoke(pages, null);
            }

            PrintDocument printDoc = (PrintDocument)sender;

            printDoc.SetPreviewPageCount(pages.Count, PreviewPageCountType.Intermediate);
        }
示例#7
0
        private void PrintDic_Paginate(object sender, PaginateEventArgs e)
        {
            PrintTaskOptions opt = task.Options;
            // 根据页面的方向来调整打印内容的旋转方向
            //switch (opt.Orientation)
            //{
            //    case PrintOrientation.Default:
            //        rottrf.Angle = 0d;
            //        break;
            //    case PrintOrientation.Portrait:
            //        rottrf.Angle = 0d;
            //        break;
            //    case PrintOrientation.Landscape:
            //        rottrf.Angle = 90d;
            //        break;
            //}
            // 设置预览页面的总页数
            PrintTaskOptionDetails printDetailedOptions = PrintTaskOptionDetails.GetFromPrintTaskOptions(e.PrintTaskOptions);
            string pageContent = (printDetailedOptions.Options["PageContent"].Value as string).ToLowerInvariant();

            // Set the text & image display flag
            imageText = (DisplayContent)((Convert.ToInt32(pageContent.Contains("pictures")) << 1) | Convert.ToInt32(pageContent.Contains("text")));


            printDoc.SetPreviewPageCount(1, PreviewPageCountType.Final);
        }
        void OnPrintDocumentPaginate(object sender, PaginateEventArgs args)
        {
            // Obtain the print range option
            PrintTaskOptionDetails optionDetails =
                PrintTaskOptionDetails.GetFromPrintTaskOptions(args.PrintTaskOptions);

            string strValue = optionDetails.Options["idPrintRange"].Value as string;

            if (strValue == "idPrintCustom")
            {
                // Parse the print range for GetPreviewPage and AddPages
                string strPageRange = optionDetails.Options["idCustomRangeEdit"].Value as string;
                customPageRange = new CustomPageRange(strPageRange, bookPages.Length);
            }
            else
            {
                // Make sure field is null if printing all pages
                customPageRange = null;
            }

            int pageCount = bookPages.Length;

            if (customPageRange != null && customPageRange.IsValid)
            {
                pageCount = customPageRange.PageMapping.Count;
            }

            printDocument.SetPreviewPageCount(pageCount, PreviewPageCountType.Final);
        }
示例#9
0
        /// <summary>
        /// This is the event handler for PrintDocument.Paginate. It creates print preview pages for the app.
        /// </summary>
        /// <param name="sender">PrintDocument</param>
        /// <param name="e">Paginate Event Arguments</param>
        protected virtual void CreatePrintPreviewPages(object sender, PaginateEventArgs e)
        {
            // Clear the cache of preview pages.
            PrintPreviewPages.Clear();

            // Clear the print canvas of preview pages.
            PrintCanvas.Children.Clear();

            // This variable keeps track of the last RichTextBlockOverflow element that was added to a page which will be printed.
            RichTextBlockOverflow lastRTBOOnPage;

            // Get the PrintTaskOptions.
            PrintTaskOptions printingOptions = e.PrintTaskOptions;

            // Get the page description to deterimine how big the page is.
            PrintPageDescription pageDescription = printingOptions.GetPageDescription(0);

            // We know there is at least one page to be printed. passing null as the first parameter to
            // AddOnePrintPreviewPage tells the function to add the first page.
            lastRTBOOnPage = AddOnePrintPreviewPage(null, pageDescription);

            // We know there are more pages to be added as long as the last RichTextBoxOverflow added to a print preview
            // page has extra content.
            while (lastRTBOOnPage.HasOverflowContent && lastRTBOOnPage.Visibility == Visibility.Visible)
            {
                lastRTBOOnPage = AddOnePrintPreviewPage(lastRTBOOnPage, pageDescription);
            }

            PreviewPagesCreated?.Invoke(PrintPreviewPages, EventArgs.Empty);

            PrintDocument printDoc = sender as PrintDocument;

            // Report the number of preview pages created.
            printDoc.SetPreviewPageCount(PrintPreviewPages.Count, PreviewPageCountType.Intermediate);
        }
示例#10
0
        /// <summary>
        /// This is the event handler for PrintDocument.Paginate.
        /// It fires when the PrintManager requests print preview
        /// </summary>
        /// <param name="sender">PrintDocument</param>
        /// <param name="e">Paginate Event Arguments</param>
        private void Paginate(object sender, PaginateEventArgs e)
        {
            option = e.PrintTaskOptions;
            PrintDocument printDoc = (PrintDocument)sender;

            // Report the number of preview pages
            printDoc.SetPreviewPageCount(c1PdfViewer1.PageCount, PreviewPageCountType.Intermediate);
        }
示例#11
0
        private void PrintDic_Paginate(object sender, PaginateEventArgs e)
        {
            PrintTaskOptions       opt = task.Options;
            PrintTaskOptionDetails printDetailedOptions = PrintTaskOptionDetails.GetFromPrintTaskOptions(e.PrintTaskOptions);
            string pageContent = (printDetailedOptions.Options["PageContent"].Value as string).ToLowerInvariant();

            // Set the text & image display flag
            imageText = (DisplayContent)((Convert.ToInt32(pageContent.Contains("pictures")) << 1) | Convert.ToInt32(pageContent.Contains("text")));
            printDoc.SetPreviewPageCount(1, PreviewPageCountType.Final);
        }
        /// <summary>
        /// This is the event handler for PrintDocument.Paginate. It creates print preview pages for the app.
        /// </summary>
        /// <param name="sender">PrintDocument</param>
        /// <param name="e">Paginate Event Arguments</param>
        protected virtual void CreatePrintPreviewPages(object sender, PaginateEventArgs e)
        {
            // Clear the cache of preview pages
            printPreviewPages.Clear();

            // Clear the printing root of preview pages
            PrintingRoot.Children.Clear();

            // This variable keeps track of the last RichTextBlockOverflow element that was added to a page which will be printed
            RichTextBlockOverflow lastRTBOOnPage;

            // Get the PrintTaskOptions
            PrintTaskOptions printingOptions = ((PrintTaskOptions)e.PrintTaskOptions);

            // Get the page description to deterimine how big the page is
            PrintPageDescription pageDescription = printingOptions.GetPageDescription(0);


            // XAML element that is used to represent to "printing page"
            FrameworkElement page = firstPage;

            // Set "paper" width
            page.Width  = pageDescription.PageSize.Width;
            page.Height = pageDescription.PageSize.Height;

            Grid printableArea = (Grid)page.FindName("printableArea");

            // Get the margins size
            // If the ImageableRect is smaller than the app provided margins use the ImageableRect
            double marginWidth  = Math.Max(pageDescription.PageSize.Width - pageDescription.ImageableRect.Width, pageDescription.PageSize.Width * ApplicationContentMarginLeft * 2);
            double marginHeight = Math.Max(pageDescription.PageSize.Height - pageDescription.ImageableRect.Height, pageDescription.PageSize.Height * ApplicationContentMarginTop * 2);

            // Set-up "printable area" on the "paper"
            printableArea.Width  = firstPage.Width - marginWidth;
            printableArea.Height = firstPage.Height - marginHeight;

            // Add the (newly created) page to the printing root which is part of the visual tree and force it to go
            // through layout so that the linked containers correctly distribute the content inside them.
            PrintingRoot.Children.Add(page);
            PrintingRoot.InvalidateMeasure();
            PrintingRoot.UpdateLayout();

            // Add the page to the page preview collection
            printPreviewPages.Add(page);

            if (pagesCreated != null)
            {
                pagesCreated.Invoke(printPreviewPages, null);
            }

            PrintDocument printDoc = (PrintDocument)sender;

            // Report the number of preview pages created
            printDoc.SetPreviewPageCount(printPreviewPages.Count, PreviewPageCountType.Intermediate);
        }
示例#13
0
        private void CreatePrintPreviewPages(object sender, PaginateEventArgs e)
        {
            printPreviewPages = new List <UIElement>();
            PrintCanvas.Children.Clear();
            var           printOptions    = e.PrintTaskOptions;
            var           pageDescription = printOptions.GetPageDescription(0);
            PrintDocument printDoc        = (PrintDocument)sender;



            var printPage = CreateNewPrintPage(pageDescription.PageSize);

            SquadronPrintHeader printHeader = new SquadronPrintHeader()
            {
                ViewModel = this.ViewModel.SquadronViewModel,
                Margin    = new Thickness(10)
            };

            printPage.AddContent(printHeader);
            var Pilots = ViewModel.SquadronViewModel.Pilots;

            for (int i = 0; i < Pilots.Count(); i++)
            {
                PilotPrintControl pilotPrint = new PilotPrintControl()
                {
                    ViewModel = Pilots[i],
                    Margin    = new Thickness(10)
                };
                printPage.AddContent(pilotPrint);
                PrintCanvas.InvalidateMeasure();
                PrintCanvas.UpdateLayout();


                if (printPage.ActualHeight >= pageDescription.PageSize.Height)
                {
                    printPage.RemoveLastContentItem();
                    printPreviewPages.Add(printPage);
                    printPage = CreateNewPrintPage(pageDescription.PageSize);
                    i--;
                }
            }
            printPreviewPages.Add(printPage);
            PrintCanvas.Children.Clear();


            foreach (var item in printPreviewPages)
            {
                PrintCanvas.Children.Add(item);
            }
            PrintCanvas.InvalidateMeasure();
            PrintCanvas.UpdateLayout();
            // Report the number of preview pages created
            printDoc.SetPreviewPageCount(printPreviewPages.Count, PreviewPageCountType.Intermediate);
        }
示例#14
0
        /// <summary>
        /// This is the event handler for <see cref="PrintDocument.Paginate"/>.
        /// It creates print preview pages for the app.
        /// </summary>
        /// <param name="sender">PrintDocument</param>
        /// <param name="e">Paginate Event Arguments</param>
        private async void CreatePrintPreviewPages(object sender, PaginateEventArgs e)
        {
            // Get the PrintTaskOptions
            PrintTaskOptions printingOptions = e.PrintTaskOptions;

            // Get the page description to determine how big the page is
            PrintPageDescription pageDescription = printingOptions.GetPageDescription(0);

            if (_directPrint)
            {
                _canvasContainer.RequestedTheme = ElementTheme.Light;
                foreach (FrameworkElement element in this._canvasContainer.Children)
                {
                    _printPreviewPages.Add(element);
                }
            }
            else
            {
                // Attach the canvas
                if (!_canvasContainer.Children.Contains(_printCanvas))
                {
                    _canvasContainer.Children.Add(_printCanvas);
                }

                _canvasContainer.RequestedTheme = ElementTheme.Light;

                // Clear the cache of preview pages
                await ClearPageCache();

                // Clear the print canvas of preview pages
                _printCanvas.Children.Clear();

                var printPageTasks = new List <Task>();
                foreach (var element in _elementsToPrint)
                {
                    printPageTasks.Add(AddOnePrintPreviewPage(element, pageDescription));
                }

                await Task.WhenAll(printPageTasks);
            }

            OnPreviewPagesCreated?.Invoke(_printPreviewPages);

            PrintDocument printDoc = (PrintDocument)sender;

            // Report the number of preview pages created
            _printCanvas.UpdateLayout();
            printDoc.SetPreviewPageCount(_printPreviewPages.Count, PreviewPageCountType.Intermediate);
            //printDoc.SetPreviewPage(_printPreviewPages.Count, _printPreviewPages[_printPreviewPages.Count - 1]);
            if (_printPreviewPages.Count != 0)
            {
                printDoc.SetPreviewPage(1, _printPreviewPages[0]);
            }
        }
        private void Paginate(object sender, PaginateEventArgs e)
        {
            PreviewPages = new List <UIElement>();
            PreviewPages.Clear();
            //PreviewPages.Add(this.SkladListL);

            PreviewPages.Add(PanelPrePrint);

            //PreviewPages.Add(this.PanelZagolovokRow);
            //УСТАНАВЛИВАЕТ КОЛ-ВО СТРАНИЦ В ПРЕДПРОСМОТРЕ ПЕЧАТИ ПО КОЛ-ВУ ЭЛЕМЕНТОВ СПИСКА PREVIEWPAGES
            printDoc.SetPreviewPageCount(PreviewPages.Count, PreviewPageCountType.Intermediate);
        }
示例#16
0
        private void PrintDocument_Paginate(object sender, PaginateEventArgs e)
        {
            _printPages.Clear();

            PrintingRoot.Children.Clear();

            PrintPageDescription pageDescription = e.PrintTaskOptions.GetPageDescription(0);

            GeneratePrintPages(pageDescription);

            _printDocument.SetPreviewPageCount(_printPages.Count, PreviewPageCountType.Intermediate);
        }
示例#17
0
文件: Printer.cs 项目: beryah/Yo
        private void CreatePrintPreviewPages(object sender, PaginateEventArgs e)
        {
            PrintTaskOptions printingOptions = ((PrintTaskOptions)e.PrintTaskOptions);

            PrintPageDescription pageDescription = printingOptions.GetPageDescription(0);

            this.PrintPreviewPages = this.GetPreviewPages();

            PrintDocument printDoc = (PrintDocument)sender;

            printDoc.SetPreviewPageCount(this.PrintPreviewPages.Count, PreviewPageCountType.Intermediate);
        }
示例#18
0
        /// <summary>
        /// This is the event handler for PrintDocument.Paginate. It creates print preview pages for the app.
        /// </summary>
        /// <param name="sender">PrintDocument</param>
        /// <param name="e">Paginate Event  </param>
        public virtual async void CreatePrintPreviewPages(object sender, PaginateEventArgs e)
        {
            var paperSize = e.PrintTaskOptions.GetPageDescription(0).PageSize;

            System.Diagnostics.Debug.WriteLine("CreatePrintPreviewPages: {" + paperSize.Width + "," + paperSize.Height + "}");

            //lock (printPreviewPages)
            await _semaphoreSlim.WaitAsync();

            {
                // Clear the cache of preview pages
                printPreviewPages.Clear();

                // Clear the print canvas of preview pages
                PrintCanvas.Children.Clear();

                // Get the PrintTaskOptions
                PrintTaskOptions printingOptions = ((PrintTaskOptions)e.PrintTaskOptions);

                // Get the page description to deterimine how big the page is
                PrintPageDescription pageDescription = printingOptions.GetPageDescription(0);



                if (await GeneratePagesAsync(pageDescription) is List <UIElement> pages)
                {
                    foreach (var page in pages)
                    {
                        PrintCanvas.Children.Add(page);
                    }
                    PrintCanvas.InvalidateMeasure();
                    PrintCanvas.UpdateLayout();

                    await Task.Delay(1000);

                    printPreviewPages.AddRange(pages);
                    await Task.Delay(1000);
                }

                if (PreviewPagesCreated != null)
                {
                    PreviewPagesCreated.Invoke(printPreviewPages, null);
                }

                PrintDocument printDoc = (PrintDocument)sender;

                // Report the number of preview pages created
                printDoc.SetPreviewPageCount(printPreviewPages.Count, PreviewPageCountType.Intermediate);
            }
            _semaphoreSlim.Release();
        }
示例#19
0
        private async void PrintDoc_Paginate(object sender, PaginateEventArgs e)
        {
            PrintTaskOptions printingOptions = ((PrintTaskOptions)e.PrintTaskOptions);

            deviceCollection = await DeviceInformation.FindAllAsync("System.Devices.InterfaceClassGuid:=\"{0ecef634-6ef0-472a-8085-5ad023ecbccd}\"");

            var rolloPrinter = deviceCollection.Where(x => x.Name.Contains("Rollo")).SingleOrDefault();

            // Get the page description to deterimine how big the page is
            PrintPageDescription pageDescription = printingOptions.GetPageDescription(0);

            PrintTaskOptions opt = Task.Options;

            printDoc.SetPreviewPageCount(1, PreviewPageCountType.Final);
        }
示例#20
0
        private void PrintDocument_Paginate(object sender, PaginateEventArgs e)
        {
            Debug.WriteLine("PrintDocument_Paginate");

            PrintTaskOptions     printingOptions      = ((PrintTaskOptions)e.PrintTaskOptions);
            PrintPageDescription printPageDescription = printingOptions.GetPageDescription(0);

            page = this;
            //NewsGrid.Width = double.NaN;
            //NewsGrid.Height = double.NaN;
            //Grid grid = new Grid();
            //grid.Children.Add(htmlBlock);


            printDocument.SetPreviewPageCount(2, PreviewPageCountType.Final);
        }
示例#21
0
        void OnPrintDocumentPaginate(object sender, PaginateEventArgs args)
        {
            PrintPageDescription printPageDescription = args.PrintTaskOptions.GetPageDescription(0);

            // Set Padding on outer Border
            double left  = printPageDescription.ImageableRect.Left;
            double top   = printPageDescription.ImageableRect.Top;
            double right = printPageDescription.PageSize.Width
                           - left - printPageDescription.ImageableRect.Width;
            double bottom = printPageDescription.PageSize.Height
                            - top - printPageDescription.ImageableRect.Height;

            border.Padding = new Thickness(left, top, right, bottom);

            printDocument.SetPreviewPageCount(1, PreviewPageCountType.Final);
        }
示例#22
0
        /// <summary>
        /// This is the event handler for PrintDocument.Paginate. It creates print preview pages for the app.
        /// </summary>
        /// <param name="sender">PrintDocument</param>
        /// <param name="e">Paginate Event Arguments</param>
        private void CreatePrintPreviewPages(object p_sender, PaginateEventArgs e)
        {
            if (m_printDocumentSource == null)
            {
                return;
            }
            else
            {
                if (m_pages == null || m_pages.Count == 0)
                {
                    return;
                }
            }

            PrintDocument l_printDoc = (PrintDocument)p_sender;

            l_printDoc.SetPreviewPageCount(m_pages.Count, PreviewPageCountType.Intermediate);
        }
示例#23
0
        private void CreatePrintPages(object sender, PaginateEventArgs e)
        {
            // Clear the cache of preview pages
            _printPages.Clear();

            // Clear the printing root of preview pages
            PrintingRoot.Children.Clear();

            PrintTaskOptions printingOptions = e.PrintTaskOptions;

            // Get the page description to deterimine how big the page is
            PrintPageDescription pageDescription = printingOptions.GetPageDescription(0);

            AddPrintPages(pageDescription);

            // Report the number of preview pages created
            _printDocument.SetPreviewPageCount(_printPages.Count, PreviewPageCountType.Intermediate);
        }
示例#24
0
        /// <summary>
        /// This is the event handler for PrintDocument.Paginate. It creates print preview pages for the app.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected virtual void CreatePrintPreviewPages(object sender, PaginateEventArgs e)
        {
            // Clear the cache of preview pages
            printPreviewPages.Clear();

            // Clear the printing root of preview pages
            PrintingRoot.Children.Clear();

            // This variable keeps track of the last RichTextBlockOverflow element that was added to a page which will be printed
            RichTextBlockOverflow lastRTBOOnPage;

            // Get the PrintTaskOptions
            PrintTaskOptions printingOptions = ((PrintTaskOptions)e.PrintTaskOptions);

            // Get the page description to deterimine how big the page is
            PrintPageDescription pageDescription = printingOptions.GetPageDescription(0);


            PrintTaskOptionDetails printDetailedOptions = PrintTaskOptionDetails.GetFromPrintTaskOptions(e.PrintTaskOptions);
            //string pageContentSettings = (printDetailedOptions.Options["PageContent"].Value as string).ToLowerInvariant();
            string tagsSettings = (printDetailedOptions.Options["Tags"].Value as string).ToLowerInvariant();

            //imageText = (DisplayContent)((Convert.ToInt32(pageContentSettings.Contains("pictures")) << 1) | Convert.ToInt32(pageContentSettings.Contains("text")));
            ShowTags = tagsSettings.Contains("show");

            // We know there is at least one page to be printed. passing null as the first parameter to
            // AddOnePrintPreviewPage tells the function to add the first page.
            lastRTBOOnPage = AddOnePrintPreviewPage(null, pageDescription);

            // We know there are more pages to be added as long as the last RichTextBoxOverflow added to a print preview
            // page has extra content
            while (lastRTBOOnPage.HasOverflowContent)
            {
                lastRTBOOnPage = AddOnePrintPreviewPage(lastRTBOOnPage, pageDescription);
            }

            if (pagesCreated != null)
            {
                pagesCreated.Invoke(printPreviewPages, null);
            }

            // Report the number of preview pages created
            printDocument.SetPreviewPageCount(printPreviewPages.Count, PreviewPageCountType.Intermediate);
        }
示例#25
0
        /// <summary>
        /// This is the event handler for <see cref="PrintDocument.Paginate"/>.
        /// It creates print preview pages for the app.
        /// </summary>
        /// <param name="sender">PrintDocument</param>
        /// <param name="e">Paginate Event Arguments</param>
        private void CreatePrintPreviewPages(object sender, PaginateEventArgs e)
        {
            // Get the PrintTaskOptions
            PrintTaskOptions printingOptions = e.PrintTaskOptions;

            // Get the page description to determine how big the page is
            PrintPageDescription pageDescription = printingOptions.GetPageDescription(0);

            if (_directPrint)
            {
                _canvasContainer.RequestedTheme = ElementTheme.Light;
                foreach (FrameworkElement element in this._canvasContainer.Children)
                {
                    _printPreviewPages.Add(element);
                }
            }
            else
            {
                // Attach the canvas
                if (!_canvasContainer.Children.Contains(_printCanvas))
                {
                    _canvasContainer.Children.Add(_printCanvas);
                }

                // Clear the cache of preview pages
                ClearPageCache();

                // Clear the print canvas of preview pages
                _printCanvas.Children.Clear();

                foreach (var element in _elementsToPrint)
                {
                    AddOnePrintPreviewPage(element, pageDescription);
                }
            }

            OnPreviewPagesCreated?.Invoke(_printPreviewPages);

            PrintDocument printDoc = (PrintDocument)sender;

            // Report the number of preview pages created
            printDoc.SetPreviewPageCount(_printPreviewPages.Count, PreviewPageCountType.Intermediate);
        }
示例#26
0
        /// <summary>
        /// This is the event handler for PrintDocument.Paginate. It creates print preview pages for the app.
        /// </summary>
        /// <param name="sender">PrintDocument</param>
        /// <param name="e">Paginate Event Arguments</param>
        protected virtual void CreatePrintPreviewPages(object sender, PaginateEventArgs e)
        {
            // Clear the cache of preview pages
            printPreviewPages.Clear();
            PrintTaskOptions     printingOptions = ((PrintTaskOptions)e.PrintTaskOptions);
            PrintPageDescription pageDescription = printingOptions.GetPageDescription(0);

            foreach (var page in Pages)
            {
                page.Height = pageDescription.PageSize.Height;
                page.Width  = pageDescription.PageSize.Width;
                printPreviewPages.Add(page);
            }

            PrintDocument printDoc = (PrintDocument)sender;

            // Report the number of preview pages created
            printDoc.SetPreviewPageCount(printPreviewPages.Count, PreviewPageCountType.Intermediate);
        }
示例#27
0
        /// <summary>
        /// This is the event handler for PrintDocument.Paginate. It creates print preview pages for the app.
        /// </summary>
        /// <param name="sender">PrintDocument</param>
        /// <param name="e">Paginate Event Arguments</param>
        protected virtual void CreatePrintPreviewPages(object sender, PaginateEventArgs e)  // Required  2. called
        {
            lock (_printPreviewPages)
            {
                // Clear the cache of preview pages
                _printPreviewPages.Clear();

                // Clear the print canvas of preview pages
                //PrintCanvas?.Children.Clear();

                // This variable keeps track of the last RichTextBlockOverflow element that was added to a page which will be printed
                //RichTextBlockOverflow lastRTBOOnPage;

                // Get the PrintTaskOptions
                PrintTaskOptions printingOptions = ((PrintTaskOptions)e.PrintTaskOptions);

                // Get the page description to determine how big the page is
                PrintPageDescription pageDescription = printingOptions.GetPageDescription(0);

                // We know there is at least one page to be printed. passing null as the first parameter to
                // AddOnePrintPreviewPage tells the function to add the first page.
                //lastRTBOOnPage = AddOnePrintPreviewPage(null, pageDescription);
                AddOnePrintPreviewPage(null, pageDescription);

                // We know there are more pages to be added as long as the last RichTextBoxOverflow added to a print preview
                // page has extra content
                //while (lastRTBOOnPage.HasOverflowContent && lastRTBOOnPage.Visibility == Windows.UI.Xaml.Visibility.Visible)
                //{
                //    lastRTBOOnPage = AddOnePrintPreviewPage(lastRTBOOnPage, pageDescription);
                //}

                if (PreviewPagesCreated != null)
                {
                    PreviewPagesCreated.Invoke(_printPreviewPages, null);
                }

                PrintDocument printDoc = (PrintDocument)sender;

                // Report the number of preview pages created
                printDoc.SetPreviewPageCount(_printPreviewPages.Count, PreviewPageCountType.Intermediate);
            }
        }
示例#28
0
        /// <summary>
        /// This is the event handler for PrintDocument.Paginate. It creates print preview pages for the app.
        /// </summary>
        /// <param name="sender">PrintDocument</param>
        /// <param name="e">Paginate Event Arguments</param>
        private static void CreatePrintPreviewPages(object sender, PaginateEventArgs e)
        {
            lock (_printPreviewPages)
            {
                // Clear the cache of preview pages
                _printPreviewPages.Clear();

                // Clear the print canvas of preview pages
                PrintCanvas.Children.Clear();

                // This variable keeps track of the last RichTextBlockOverflow element that was added to a page which will be printed
                RichTextBlockOverflow lastRTBOOnPage;

                // Get the PrintTaskOptions
                PrintTaskOptions printingOptions = e.PrintTaskOptions;

                // Get the page description to determine how big the page is
                PrintPageDescription pageDescription = printingOptions.GetPageDescription(0);

                var count = 0;
                do
                {
                    // We know there is at least one page to be printed. passing null as the first parameter to
                    // AddOnePrintPreviewPage tells the function to add the first page.
                    lastRTBOOnPage = AddOnePrintPreviewPage(null, pageDescription, count);

                    // We know there are more pages to be added as long as the last RichTextBoxOverflow added to a print preview
                    // page has extra content
                    while (lastRTBOOnPage.HasOverflowContent && lastRTBOOnPage.Visibility == Visibility.Visible)
                    {
                        lastRTBOOnPage = AddOnePrintPreviewPage(lastRTBOOnPage, pageDescription, count);
                    }

                    count += 1;
                } while (count < _firstPage.Count);

                PrintDocument printDoc = (PrintDocument)sender;

                // Report the number of preview pages created
                printDoc.SetPreviewPageCount(_printPreviewPages.Count, PreviewPageCountType.Intermediate);
            }
        }
示例#29
0
        private void OnPaginate(object sender, PaginateEventArgs e)
        {
            this.pages.Clear();

            List <double> heights = new List <double>();

            foreach (var group in this.viewmodel.SmartCollection.Items)
            {
                heights.Add(GroupItemHeight);
                foreach (var task in group)
                {
                    heights.Add(TaskItemHeight);
                }
            }

            PrintDocument    printDoc        = (PrintDocument)sender;
            PrintTaskOptions printingOptions = e.PrintTaskOptions;

            int startIndex = 0;

            while (heights.Count > 0)
            {
                int itemsInPage = 0;

                PrintPageDescription pageDescription = printingOptions.GetPageDescription((uint)this.pages.Count);
                double availableHeight = pageDescription.PageSize.Height - (2 * GetVerticalMargin(pageDescription));

                while (heights.Count > 0 && heights[0] < availableHeight)
                {
                    availableHeight -= heights[0];
                    heights.RemoveAt(0);
                    itemsInPage++;
                }

                // create page
                this.pages.Add(this.CreatePage(startIndex, startIndex + itemsInPage, pageDescription));

                startIndex += itemsInPage;
            }

            printDoc.SetPreviewPageCount(this.pages.Count, PreviewPageCountType.Intermediate);
        }
示例#30
0
        /// <summary>
        /// This is the event handler for PrintDocument.Paginate. It creates print preview pages for the app.
        /// </summary>
        /// <param name="sender">PrintDocument</param>
        /// <param name="e">Paginate Event Arguments</param>
        protected virtual void CreatePrintPreviewPages(object sender, PaginateEventArgs e)
        {
            lock (printPreviewPages)
            {
                // Clear the cache of preview pages
                printPreviewPages.Clear();

                // Clear the print canvas of preview pages
                PrintCanvas.Children.Clear();

                // Get the PrintTaskOptions
                PrintTaskOptions printingOptions = ((PrintTaskOptions)e.PrintTaskOptions);

                // Get the page description to deterimine how big the page is
                PrintPageDescription pageDescription = printingOptions.GetPageDescription(0);

                if (print_Page == 1)
                {
                    // setup print page 1
                    AddOnePrintPreviewPage(1, pageDescription, ScoutName, MeritBadge);
                }

                if (print_Page == 2)
                {
                    // setup print page 2
                    AddOnePrintPreviewPage(2, pageDescription, ScoutName, MeritBadge);
                }

                if (PreviewPagesCreated != null)
                {
                    PreviewPagesCreated.Invoke(printPreviewPages, null);
                }

                PrintDocument printDoc = (PrintDocument)sender;

                // Report the number of preview pages created
                printDoc.SetPreviewPageCount(printPreviewPages.Count, PreviewPageCountType.Intermediate);
            }
        }