예제 #1
0
        /// <summary>
        /// This function creates and adds one print preview page to the internal cache of print preview
        /// pages stored in printPreviewPages.
        /// </summary>
        /// <param name="printPageDescription">Printer's page description</param>
        private void AddOnePrintPreviewPage(PrintPageDescription printPageDescription)
        {
            // Set "paper" width
            _printPage.Width  = printPageDescription.PageSize.Width;
            _printPage.Height = printPageDescription.PageSize.Height;

            var printableArea = (Grid)_printPage.Content;

            // 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);

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

            // Add the (newley 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(_printPage);
            PrintingRoot.InvalidateMeasure();
            PrintingRoot.UpdateLayout();

            // Add the page to the page preview collection
            PrintPreviewPages.Add(_printPage);
        }
예제 #2
0
        /// <summary>
        /// Applies height and width of the printer page.
        /// </summary>
        private void ApplyPrintPageDescription(PrintPageDescription printPageDescription, PrintPage printPage)
        {
            // Set paper size
            printPage.Width  = printPageDescription.PageSize.Width;
            printPage.Height = printPageDescription.PageSize.Height;

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

            // Set-up the printable area on the paper.
            printPage.PrintableArea.Width  = printPage.Width - marginWidth;
            printPage.PrintableArea.Height = printPage.Height - marginHeight;
            OnStatusChanged("Printable area: width = " + printPage.PrintableArea.Width + ", height = " + printPage.PrintableArea.Height);

            // Add the page to the printing root which is part of the visual tree.
            // Force it to go through layout so that the overflow correctly distribute the content inside them.
            PrintingRoot.Children.Add(printPage);
            PrintingRoot.InvalidateMeasure();
            PrintingRoot.UpdateLayout();
        }
예제 #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
        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);
        }
예제 #5
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);
        }
예제 #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
        private void CreateBoardingPassPage(PrintPageDescription printPageDescription, Reservation reservation)
        {
            var page        = new BoardingPassPreviewPage();
            var rootElement = (FrameworkElement)page.FindName("PrintRoot");

            PreparePrintPage(printPageDescription, reservation, page, rootElement);
        }
예제 #8
0
        private void GenerateBoardingPassPage(PrintPageDescription printPageDescription)
        {
            var page        = _firstPage;
            var rootElement = (FrameworkElement)page.FindName("PrintRoot");

            PreparePrintPage(printPageDescription, page, rootElement);
        }
        /// <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();
예제 #10
0
        private void PreparePrintPage(PrintPageDescription printPageDescription, Reservation reservation, FrameworkElement page, FrameworkElement rootElement)
        {
            page.DataContext = reservation;

            rootElement.Width  = printPageDescription.PageSize.Width;
            rootElement.Height = printPageDescription.PageSize.Height;

            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);

            // Set content size based on the given margins
            var contentContainer = (FrameworkElement)page.FindName("ContentContainer");

            contentContainer.Width  = printPageDescription.PageSize.Width - marginWidth;
            contentContainer.Height = printPageDescription.PageSize.Height - marginHeight;

            // Set content margins
            contentContainer.SetValue(Canvas.LeftProperty, marginWidth / 2);
            contentContainer.SetValue(Canvas.TopProperty, marginHeight / 2);

            page.UpdateLayout();

            _printPages.Add(page);
            PrintingRoot.Children.Add(page);
            PrintingRoot.InvalidateMeasure();
            PrintingRoot.UpdateLayout();
        }
예제 #11
0
        protected void AddOnePrintPreviewPage(PrintPageDescription printPageDescription)
        {
            TextBlock block = new TextBlock();

            block.Text   = "This is an example.";
            block.Width  = printPageDescription.PageSize.Width;
            block.Height = printPageDescription.PageSize.Height;
            printPreviewElements.Add(block);
        }
예제 #12
0
        /// <summary>
        /// Creates and adds one print preview page to the internal cache of print preview pages stored in <see cref="_printPreviewPages"/>.
        /// </summary>
        /// <param name="element">FrameworkElement used to represent the "printing page"</param>
        /// <param name="printPageDescription">Printer's page description</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        private Task AddOnePrintPreviewPage(FrameworkElement element, PrintPageDescription printPageDescription)
        {
            var page = new Page();

            // Save state
            if (!_stateBags.ContainsKey(element))
            {
                var stateBag = new PrintHelperStateBag();
                stateBag.Capture(element);
                _stateBags.Add(element, stateBag);
            }

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

            // Get the margins size
            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);

            // Set up the "printable area" on the "paper"
            element.VerticalAlignment   = VerticalAlignment.Top;
            element.HorizontalAlignment = HorizontalAlignment.Left;

            if (element.Width > element.Height)
            {
                var newWidth = page.Width - marginWidth;

                element.Height = element.Height * (newWidth / element.Width);
                element.Width  = newWidth;
            }
            else
            {
                var newHeight = page.Height - marginHeight;

                element.Width  = element.Width * (newHeight / element.Height);
                element.Height = newHeight;
            }

            element.Margin = new Thickness(marginWidth / 2, marginHeight / 2, marginWidth / 2, marginHeight / 2);
            page.Content   = element;

            return(DispatcherHelper.ExecuteOnUIThreadAsync(
                       () =>
            {
                // Add the (newly created) page to the print canvas 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.
                _printCanvas.Children.Add(page);
                _printCanvas.UpdateLayout();
                _printCanvas.InvalidateMeasure();

                // Add the page to the page preview collection
                _printPreviewPages.Add(page);
            }, Windows.UI.Core.CoreDispatcherPriority.High));
        }
        /// <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);
        }
예제 #14
0
        void GetPageSize(PaginateEventArgs e)
        {
            if (this.pageSize == null)
            {
                PrintPageDescription description = e.PrintTaskOptions.GetPageDescription(
                    (uint)e.CurrentPreviewPageNumber);

                this.pageSize      = description.PageSize;
                this.imageableRect = description.ImageableRect;
            }
        }
예제 #15
0
 private void GeneratePrintPages(PrintPageDescription printPageDescription)
 {
     if (_type == PrintJobType.BoardingPass)
     {
         GenerateBoardingPassPage(printPageDescription);
     }
     else if (_type == PrintJobType.Receipt)
     {
         GenerateReceiptPages(printPageDescription);
     }
 }
예제 #16
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]);
            }
        }
예제 #17
0
        private void PreparePrintPage(PrintPageDescription printPageDescription, FrameworkElement page, FrameworkElement rootElement)
        {
            page.DataContext = _reservation;

            SetContentSizeAndMargins(printPageDescription, page, rootElement);

            _printPages.Add(page);
            PrintingRoot.Children.Add(page);

            PrintingRoot.InvalidateMeasure();
            PrintingRoot.UpdateLayout();
        }
예제 #18
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);
        }
예제 #19
0
        private void AddPrintPages(PrintPageDescription printPageDescription)
        {
            if (_type == PrintJobType.BoardingPass)
            {
                CreateBoardingPassPage(printPageDescription, _reservationForPrinting);
            }

            else if (_type == PrintJobType.Receipt)
            {
                CreateReceiptPages(printPageDescription, _reservationForPrinting, null);
            }
        }
예제 #20
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);
        }
예제 #21
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);
        }
예제 #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  </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();
        }
예제 #23
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);
        }
예제 #24
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);
        }
예제 #25
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);
        }
        void OnPaginate(object sender, PaginateEventArgs args)
        {
            PrintPageDescription pageDesc = args.PrintTaskOptions.GetPageDescription(0);

            // Get the Bitmap
            (border.Child as Image).Source = getBitmap();

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

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

            this.SetPreviewPageCount(1, PreviewPageCountType.Final);
        }
예제 #27
0
        private void PrintDocument_PrintTaskOptionsChanged(CanvasPrintDocument sender, CanvasPrintTaskOptionsChangedEventArgs args)
        {
            PrintPageDescription pageDesc = args.PrintTaskOptions.GetPageDescription(1);
            Vector2 newPageSize           = pageDesc.PageSize.ToVector2();

            if (_pageSize == newPageSize)
            {
                // We've already figured out the pages and the page size hasn't changed,
                // so there's nothing left for us to do here.
                return;
            }

            _pageSize = newPageSize;
            sender.InvalidatePreview();

            sender.SetPageCount(1);
            args.NewPreviewPageNumber = 1;
        }
예제 #28
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);
        }
예제 #29
0
        /// <summary>
        /// This function creates and adds one print preview page to the internal cache of print preview
        /// pages stored in printPreviewPages.
        /// </summary>
        /// <param name="printPageDescription">Printer's page description</param>
        protected virtual void AddOnePrintPreviewPage(int printPageToAdd, PrintPageDescription printPageDescription, string ScoutName, string MeritBadge)
        {
            // XAML element that is used to represent to "printing page"
            FrameworkElement page;

            // Check if this is the first page
            if (printPageToAdd == 1)
            {
                // add the front side
                page = new PageOneToPrint(ScoutName);
            }
            else
            {
                // if not add the back side here
                page = new PageTwoToPrint(ScoutName, MeritBadge);
            }

            // Set "paper" width
            page.Width  = printPageDescription.PageSize.Width;
            page.Height = printPageDescription.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(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);

            // Set-up "printable area" on the "paper"
            printableArea.Width = page.Width - marginWidth;
            //printableArea.Height = page.Height - marginHeight;
            printableArea.Height = page.Height - 11.18;     // DEO - manually set top margin

            // Add the (newly created) page to the print canvas 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.
            PrintCanvas.Children.Add(page);
            PrintCanvas.InvalidateMeasure();
            PrintCanvas.UpdateLayout();

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

            return;
        }
예제 #30
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);
        }