Hey guys i have been trying to print my Webview using the tutorial Jerry Nixon gave on How do I print WebView content in a Windows Store App? and the tutorial from "windows 8 apps with xaml and c#" by Adam Nathan, i have attached the code below from his example:
using System;
using Windows.Graphics.Printing;
using Windows.Graphics.Printing.OptionDetails;
using Windows.UI;
using Windows.UI.Core;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Printing;
namespace Chapter19
{
public sealed partial class MainPage : Page
{
// Supports printing pages, where each page is a UIElement
PrintDocument doc = new PrintDocument();
public MainPage()
{
InitializeComponent();
// Attach handlers to relevant events
doc.GetPreviewPage += OnGetPreviewPage;
doc.AddPages += OnAddPages;
PrintManager printManager = PrintManager.GetForCurrentView();
printManager.PrintTaskRequested += OnPrintTaskRequested;
}
// Prepare the print preview pages
void OnGetPreviewPage(object sender, GetPreviewPageEventArgs e)
{
this.doc.SetPreviewPageCount(2, PreviewPageCountType.Final);
if (e.PageNumber == 1)
{
this.doc.SetPreviewPage(1, new Viewbox
{
Child = new Button
{
Content = "PAGE 1!",
Background = new SolidColorBrush(Colors.Red)
}
});
}
else
{
this.doc.SetPreviewPage(2, new Viewbox
{
Child = new Button
{
Content = "PAGE 2!",
Background = new SolidColorBrush(Colors.Red)
}
});
}
}
// Prepare the real pages
void OnAddPages(object sender, AddPagesEventArgs e)
{
this.doc.AddPage(new Viewbox
{
Child = new Button
{
Content = "PAGE 1!",
Background = new SolidColorBrush(Colors.Red)
}
});
this.doc.AddPage(new Viewbox
{
Child = new Button
{
Content = "PAGE 2!",
Background = new SolidColorBrush(Colors.Red)
}
});
this.doc.AddPagesComplete();
}
// Prepare and perform the printing
void OnPrintTaskRequested(PrintManager sender,
PrintTaskRequestedEventArgs args)
{
// This gets invoked as soon as the Devices pane is shown
PrintTask task = args.Request.CreatePrintTask("Document Title",
async (taskArgs) =>
{
// This is invoked on a background thread when the Print
// button is clicked
var deferral = taskArgs.GetDeferral();
await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
// This must run on the main thread
taskArgs.SetSource(doc.DocumentSource);
deferral.Complete();
});
});
// Show custom options
PrintTaskOptionDetails details =
PrintTaskOptionDetails.GetFromPrintTaskOptions(task.Options);
details.DisplayedOptions.Clear();
details.DisplayedOptions.Add(StandardPrintTaskOptions.MediaSize);
// A custom text option
PrintCustomTextOptionDetails option1 = details.CreateTextOption(
"CustomId1", "Header");
details.DisplayedOptions.Add("CustomId1");
// A custom list option
PrintCustomItemListOptionDetails option2 = details.CreateItemListOption(
"CustomId2", "Contents");
option2.AddItem("customItemId1", "As Seen on Screen");
option2.AddItem("customItemId2", "Summary View");
option2.AddItem("customItemId3", "Full Details");
option2.AddItem("customItemId4", "Multiple Columns");
details.DisplayedOptions.Add("CustomId2");
// Handle options changes
details.OptionChanged += OnOptionChanged;
}
void OnOptionChanged(PrintTaskOptionDetails sender, PrintTaskOptionChangedEventArgs args)
{
// TODO: Handle custom options
}
}
}
the problem i am having is that i am struggling to get "MywebviewPages" that jerry generated onto the "this.doc.SetPreviewPage" and "this.doc.AddPage" from Nathans example. Due to lack of PDF api's on winRT i am forced to use webview since its the only way to have tables. please help