private async Task <Rectangle> PrepareWebViewForPrintingAsync() { var widthString = await _webView.InvokeScriptAsync("eval", new[] { "document.body.scrollWidth.toString()" }); int contentWidth; if (!int.TryParse(widthString, out contentWidth)) { throw new Exception(string.Format("failure/width:{0}", widthString)); } _webView.Width = contentWidth; // resize height to content var heightString = await _webView.InvokeScriptAsync("eval", new[] { "document.body.scrollHeight.toString()" }); int contentHeight; if (!int.TryParse(heightString, out contentHeight)) { throw new Exception(string.Format("failure/height:{0}", heightString)); } _webView.Height = contentHeight; WebViewBrush brush = new WebViewBrush(); brush.SetSource(_webView); brush.Stretch = Stretch.Uniform; brush.Redraw(); // Send to printer var rect = new Rectangle { Fill = brush, Width = contentWidth, Height = contentHeight }; return(rect); }
private void MakePage() { var brush = new WebViewBrush { Stretch = (Windows.UI.Xaml.Media.Stretch)Windows.UI.Xaml.Media.Stretch.Uniform }; brush.SetSource(ViewToPrint); brush.Redraw(); rectangle.Width = 800; rectangle.Height = 800; rectangle.Fill = brush; brush.Stretch = (Windows.UI.Xaml.Media.Stretch)Windows.UI.Xaml.Media.Stretch.UniformToFill; brush.AlignmentY = AlignmentY.Top; brush.AlignmentX = AlignmentX.Left; rectangle.Name = "MyWebViewRectangle"; rectangle.Visibility = Windows.UI.Xaml.Visibility.Visible; }