/// <summary> /// This function creates and adds one print page to the internal cache of print pages /// pages stored in printPages. /// </summary> /// <param name="lastRTBOAdded">Last RichTextBlockOverflow element added in the current content</param> /// <param name="printPageDescription">Printer's page description</param> protected RichTextBlockOverflow AddOnePrintPage(RichTextBlockOverflow lastRTBOAdded, PrintPageDescription printPageDescription) { // XAML element that is used to represent to "printing page" FrameworkElement page; // The link container for text overflowing in this page RichTextBlockOverflow textLink; // Check if this is the first page ( no previous RichTextBlockOverflow) if (lastRTBOAdded == null) { // If this is the first page add the specific scenario content page = firstPage; //Hide footer since we don't know yet if it will be displayed (this might not be the last page) - wait for layout StackPanel footer = (StackPanel)page.FindName("Footer"); footer.Visibility = Visibility.Collapsed; } else { // Flow content (text) from previous pages page = new ContinuationPage(lastRTBOAdded); } // 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 = firstPage.Width - marginWidth; printableArea.Height = firstPage.Height - marginHeight; // 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(); // Find the last text container and see if the content is overflowing textLink = (RichTextBlockOverflow)page.FindName("ContinuationPageLinkedContainer"); // Check if this is the last page if ((!textLink.HasOverflowContent) && (textLink.Visibility == Windows.UI.Xaml.Visibility.Visible)) { StackPanel footer = (StackPanel)page.FindName("Footer"); footer.Visibility = Visibility.Visible; } // Add the page to the print page collection printPages.Add(page); return(textLink); }
/// <summary> /// This function creates and adds one print preview page to the internal cache of print preview /// pages stored in printPreviewPages. /// </summary> /// <param name="lastRTBOAdded">Last RichTextBlockOverflow element added in the current content</param> /// <param name="printPageDescription">Printer's page description</param> protected virtual RichTextBlockOverflow AddOnePrintPreviewPage(RichTextBlockOverflow lastRTBOAdded, PrintPageDescription printPageDescription) { // XAML element that is used to represent to "printing page" FrameworkElement page; // The link container for text overflowing in this page RichTextBlockOverflow textLink; // Check if this is the first page ( no previous RichTextBlockOverflow) if (lastRTBOAdded == null) { // If this is the first page add the specific scenario content page = firstPage; //Hide footer since we don't know yet if it will be displayed (this might not be the last page) - wait for layout StackPanel footer = (StackPanel)page.FindName("Footer"); footer.Visibility = Windows.UI.Xaml.Visibility.Collapsed; } else { // Flow content (text) from previous pages page = new ContinuationPage(lastRTBOAdded); } // 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 = firstPage.Width - marginWidth; printableArea.Height = firstPage.Height - marginHeight; // Add the (newley 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(); // Find the last text container and see if the content is overflowing textLink = (RichTextBlockOverflow)page.FindName("ContinuationPageLinkedContainer"); // Check if this is the last page if (!textLink.HasOverflowContent && textLink.Visibility == Windows.UI.Xaml.Visibility.Visible) { StackPanel footer = (StackPanel)page.FindName("Footer"); footer.Visibility = Windows.UI.Xaml.Visibility.Visible; } // Add the page to the page preview collection printPreviewPages.Add(page); return textLink; }