コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #3
0
        private void PrintDic_Paginate(object sender, PaginateEventArgs e)
        {
            PrintTaskOptions       opt = task.Options;
            PrintTaskOptionDetails printDetailedOptions = PrintTaskOptionDetails.GetFromPrintTaskOptions(e.PrintTaskOptions);

            printDoc.SetPreviewPageCount(1, PreviewPageCountType.Final);
        }
コード例 #4
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);
        }
コード例 #5
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();
コード例 #6
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);
        }
コード例 #7
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);
        }
コード例 #8
0
        public static void DebugPrintTaskOptionDetails(this PrintTaskOptions options)
        {
            var optionDetails = PrintTaskOptionDetails.GetFromPrintTaskOptions(options);

            foreach (var option in optionDetails.Options)
            {
                Debug.WriteLine("{0} - {1}", option.Key, option.Value.Value);
            }
        }
コード例 #9
0
        public static void DebugPrintTaskOptionDetails(this PrintTaskOptions options, Int32 currentPreviewPageNumber)
        {
            options.DebugPrintTaskOptionDetails();
            var pageDescription = options.GetPageDescription((UInt32)currentPreviewPageNumber);

            Debug.WriteLine("Page Description - DPI X={0}, Y={1}", pageDescription.DpiX, pageDescription.DpiY);
            Debug.WriteLine("Page Description - Page Size Width={0}, Height={1} (Device Independent Pixels)", pageDescription.PageSize.Width, pageDescription.PageSize.Height);
            Debug.WriteLine("Page Description - Imageable Rect={0} (Device Independent Pixels)", pageDescription.ImageableRect);
        }
コード例 #10
0
        private void PrintDocument_Preview(CanvasPrintDocument sender, CanvasPreviewEventArgs args)
        {
            PrintTaskOptions       options = args.PrintTaskOptions;
            PrintTaskOptionDetails printDetailedOptions = PrintTaskOptionDetails.GetFromPrintTaskOptions(options);
            Rect          imageableRect = GetImageableRect(options, args.PageNumber);
            GraphSize     size          = GetOptionValue <GraphSize>(printDetailedOptions);
            LabelLocation labelLocation = GetOptionValue <LabelLocation>(printDetailedOptions);

            DrawPage(args.DrawingSession, imageableRect, size, labelLocation);
        }
コード例 #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);
        }
コード例 #12
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 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
        /// <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]);
            }
        }
コード例 #14
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);
        }
コード例 #15
0
        private void PrintDocument_Print(CanvasPrintDocument sender, CanvasPrintEventArgs args)
        {
            PrintTaskOptions       options = args.PrintTaskOptions;
            PrintTaskOptionDetails printDetailedOptions = PrintTaskOptionDetails.GetFromPrintTaskOptions(options);
            Rect          imageableRect = GetImageableRect(options, pageNumber: 1);
            GraphSize     size          = GetOptionValue <GraphSize>(printDetailedOptions);
            LabelLocation labelLocation = GetOptionValue <LabelLocation>(printDetailedOptions);

            using (CanvasDrawingSession drawingSession = args.CreateDrawingSession())
            {
                DrawPage(drawingSession, imageableRect, size, labelLocation);
            }
        }
コード例 #16
0
        protected void CreatePrintPreviewPages(object sender, PaginateEventArgs e)
        {
            printPreviewElements.Clear();
            PrintTaskOptions     printingOptions = ((PrintTaskOptions)e.PrintTaskOptions);
            PrintPageDescription pageDescription = printingOptions.GetPageDescription(0);

            AddOnePrintPreviewPage(pageDescription);
            if (pagesCreated != null)
            {
                pagesCreated.Invoke(printPreviewElements, null);
            }
            ((PrintDocument)sender).SetPreviewPageCount(printPreviewElements.Count, PreviewPageCountType.Intermediate);
        }
コード例 #17
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();
        }
コード例 #18
0
        private void ConfigureCustomOptions(PrintTaskOptions printTaskOptions)
        {
            if (printTaskOptions == null)
            {
                throw new ArgumentNullException("printTaskOptions");
            }

            var detailedOptions =
                PrintTaskOptionDetails.GetFromPrintTaskOptions(printTaskOptions);

            // Create the list of options for choosing a layout
            var selectedLayoutOption = detailedOptions.CreateItemListOption(
                LayoutOptionId, "Layout");

            selectedLayoutOption.AddItem(
                PrintLayoutId.LayoutOneByOne.ToString(),
                PrintLayout.Layouts[PrintLayoutId.LayoutOneByOne].LayoutName);

            selectedLayoutOption.AddItem(
                PrintLayoutId.LayoutTwoByTwo.ToString(),
                PrintLayout.Layouts[PrintLayoutId.LayoutTwoByTwo].LayoutName);

            selectedLayoutOption.TrySetValue(DefaultPrintLayoutId.ToString());
            detailedOptions.DisplayedOptions.Add(LayoutOptionId);

            // Create the list of options for choosing whether the preview
            // should use thumbnails or full-res images
            var previewTypeOption = detailedOptions.CreateItemListOption(
                PreviewTypeOptionId, "Preview Type");

            previewTypeOption.AddItem(
                PreviewTypeOption.Thumbnails.ToString(),
                "Thumbnails");
            previewTypeOption.AddItem(
                PreviewTypeOption.FullRes.ToString(),
                "Full Res");

            previewTypeOption.TrySetValue(DefaultPreviewTypeOption.ToString());
            detailedOptions.DisplayedOptions.Add(PreviewTypeOptionId);

            // Create the option that allows users to provide a page title
            // for the printout
            var pageTitleOption = detailedOptions.CreateTextOption(
                PageTitleOptionId, "Page Title");

            pageTitleOption.TrySetValue(DefaultPageTitle);
            detailedOptions.DisplayedOptions.Add(PageTitleOptionId);

            detailedOptions.OptionChanged += HandleCustomOptionsOptionChanged;
        }
コード例 #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
        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);
        }
コード例 #22
0
        public String GetPageTitle(PrintTaskOptions printTaskOptions)
        {
            if (printTaskOptions == null)
            {
                throw new ArgumentNullException("printTaskOptions");
            }

            var detailedOptions =
                PrintTaskOptionDetails.GetFromPrintTaskOptions(printTaskOptions);
            var result = DefaultPageTitle;
            IPrintOptionDetails option;

            if (detailedOptions.Options.TryGetValue(PageTitleOptionId, out option))
            {
                result = option.Value as String;
            }
            return(result);
        }
コード例 #23
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);
        }
コード例 #24
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);
        }
コード例 #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)  // 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);
            }
        }
コード例 #27
0
ファイル: PrintArgs.cs プロジェクト: MarcAnt01/Notepads
        /// <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);
            }
        }
コード例 #28
0
ファイル: PrintHelper.cs プロジェクト: yaneshtyagi/2day
        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);
        }
コード例 #29
0
        /// <summary>
        /// This is the event handler for PrintDocument.AddPages. It provides all pages to be printed, in the form of
        /// UIElements, to an instance of PrintDocument. PrintDocument subsequently converts the UIElements
        /// into a pages that the Windows print system can deal with.
        /// </summary>
        /// <param name="sender">PrintDocument</param>
        /// <param name="e">Add page event arguments containing a print task options reference</param>
        protected override void AddPrintPages(object sender, AddPagesEventArgs e)
        {
            // Clear the cache of print pages
            printPages.Clear();

            // Clear the print canvas of print 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 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
            // AddOnePrintPage tells the function to add the first page.
            lastRTBOOnPage = AddOnePrintPage(null, pageDescription);

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

            // Loop over all of the pages and add each one to add each page to be printed
            for (int i = 0; i < printPages.Count; i++)
            {
                // We should have all pages ready at this point...
                printDocument.AddPage(printPages[i]);
            }

            PrintDocument printDoc = (PrintDocument)sender;

            // Indicate that all of the print pages have been provided
            printDoc.AddPagesComplete();
        }
コード例 #30
0
        private PreviewTypeOption GetSelectedPreviewType(PrintTaskOptions printTaskOptions)
        {
            if (printTaskOptions == null)
            {
                throw new ArgumentNullException("printTaskOptions");
            }

            var detailedOptions =
                PrintTaskOptionDetails.GetFromPrintTaskOptions(printTaskOptions);
            var result = DefaultPreviewTypeOption;
            IPrintOptionDetails option;

            if (detailedOptions.Options.TryGetValue(PreviewTypeOptionId, out option))
            {
                var selectedValueText = option.Value as String;
                if (!String.IsNullOrWhiteSpace(selectedValueText))
                {
                    result = (PreviewTypeOption)Enum.Parse(typeof(PreviewTypeOption), selectedValueText);
                }
            }
            return(result);
        }