protected virtual void PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs e) { Task = e.Request.CreatePrintTask(PrintTitle, async sourceRequested => { PrintTaskOptionDetails printDetailedOptions = PrintTaskOptionDetails.GetFromPrintTaskOptions(Task.Options); printDetailedOptions.DisplayedOptions.Clear(); printDetailedOptions.DisplayedOptions.Add(StandardPrintTaskOptions.Copies); Task.Options.Orientation = PrintOrientation.Portrait; Task.Completed += async (s, args) => { if (args.Completion == PrintTaskCompletion.Failed) { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { Debug.WriteLine("Failed to print."); }); } }; await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { sourceRequested.SetSource(PrintDoc?.DocumentSource); }); }); }
/// <summary> /// This is the event handler for PrintManager.PrintTaskRequested. /// In order to ensure a good user experience, the system requires that the app handle the PrintTaskRequested event within the time specified by PrintTaskRequestedEventArgs.Request.Deadline. /// Therefore, we use this handler to only create the print task. /// The print settings customization can be done when the print document source is requested. /// </summary> /// <param name="sender">PrintManager</param> /// <param name="e">PrintTaskRequestedEventArgs</param> protected override void PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs e) { PrintTask printTask = null; printTask = e.Request.CreatePrintTask("C# Printing SDK Sample", sourceRequestedArgs => { IList<string> displayedOptions = printTask.Options.DisplayedOptions; // Choose the printer options to be shown. // The order in which the options are appended determines the order in which they appear in the UI displayedOptions.Clear(); displayedOptions.Add(Windows.Graphics.Printing.StandardPrintTaskOptions.Copies); displayedOptions.Add(Windows.Graphics.Printing.StandardPrintTaskOptions.Orientation); displayedOptions.Add(Windows.Graphics.Printing.StandardPrintTaskOptions.MediaSize); displayedOptions.Add(Windows.Graphics.Printing.StandardPrintTaskOptions.Collation); displayedOptions.Add(Windows.Graphics.Printing.StandardPrintTaskOptions.Duplex); // Preset the default value of the printer option printTask.Options.MediaSize = PrintMediaSize.NorthAmericaLegal; // Print Task event handler is invoked when the print job is completed. printTask.Completed += async (s, args) => { // Notify the user when the print operation fails. if (args.Completion == PrintTaskCompletion.Failed) { await scenarioPage.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { MainPage.Current.NotifyUser("Failed to print.", NotifyType.ErrorMessage); }); } }; sourceRequestedArgs.SetSource(printDocumentSource); }); }
void manager_PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs args) { PrintTask task = null; task = args.Request.CreatePrintTask("Day #20 - Simple Print Job", sourceRequested => { sourceRequested.SetSource(source); }); }
void OnPrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs args) { var deferral = args.Request.GetDeferral(); PrintTask printTask = args.Request.CreatePrintTask( "Todays Tasks", OnPrintTaskSourceRequestedHandler); printTask.Completed += OnPrintTaskCompleted; deferral.Complete(); }
/// <summary> /// This is the event handler for PrintManager.PrintTaskRequested. /// In order to ensure a good user experience, the system requires that the app handle the PrintTaskRequested event within the time specified by PrintTaskRequestedEventArgs.Request.Deadline. /// Therefore, we use this handler to only create the print task. /// The print settings customization can be done when the print document source is requested. /// </summary> /// <param name="sender">PrintManager</param> /// <param name="e">PrintTaskRequestedEventArgs</param> protected override void PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs e) { PrintTask printTask = null; printTask = e.Request.CreatePrintTask("C# Printing SDK Sample", sourceRequestedArgs => { PrintTaskOptionDetails printDetailedOptions = PrintTaskOptionDetails.GetFromPrintTaskOptions(printTask.Options); IList<string> displayedOptions = printDetailedOptions.DisplayedOptions; // Choose the printer options to be shown. // The order in which the options are appended determines the order in which they appear in the UI displayedOptions.Clear(); displayedOptions.Add(Windows.Graphics.Printing.StandardPrintTaskOptions.Copies); displayedOptions.Add(Windows.Graphics.Printing.StandardPrintTaskOptions.Orientation); displayedOptions.Add(Windows.Graphics.Printing.StandardPrintTaskOptions.ColorMode); // Create a new list option PrintCustomItemListOptionDetails pageFormat = printDetailedOptions.CreateItemListOption("PageContent", "Pictures"); pageFormat.AddItem("PicturesText", "Pictures and text"); pageFormat.AddItem("PicturesOnly", "Pictures only"); pageFormat.AddItem("TextOnly", "Text only"); // Add the custom option to the option list displayedOptions.Add("PageContent"); printDetailedOptions.OptionChanged += printDetailedOptions_OptionChanged; // Print Task event handler is invoked when the print job is completed. printTask.Completed += async (s, args) => { // Notify the user when the print operation fails. if (args.Completion == PrintTaskCompletion.Failed) { await scenarioPage.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { MainPage.Current.NotifyUser("Failed to print.", NotifyType.ErrorMessage); }); } }; sourceRequestedArgs.SetSource(printDocumentSource); }); }
/// <summary> /// This is the event handler for PrintManager.PrintTaskRequested. /// In order to ensure a good user experience, the system requires that the app handle the PrintTaskRequested event within the time specified by PrintTaskRequestedEventArgs.Request.Deadline. /// Therefore, we use this handler to only create the print task. /// The print settings customization can be done when the print document source is requested. /// </summary> /// <param name="sender">PrintManager</param> /// <param name="e">PrintTaskRequestedEventArgs</param> protected override void PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs e) { PrintTask printTask = null; printTask = e.Request.CreatePrintTask("C# Printing SDK Sample", sourceRequestedArgs => { // Print Task event handler is invoked when the print job is completed. printTask.Completed += async (s, args) => { // Notify the user when the print operation fails. if (args.Completion == PrintTaskCompletion.Failed) { await scenarioPage.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { MainPage.Current.NotifyUser("Failed to print.", NotifyType.ErrorMessage); }); } }; sourceRequestedArgs.SetSource(printDocumentSource); }); // Choose not to show the preview by setting the property on PrintTask printTask.IsPreviewEnabled = false; }
/// <summary> /// This is the event handler for PrintManager.PrintTaskRequested. /// In order to ensure a good user experience, the system requires that the app handle the PrintTaskRequested event within the time specified by PrintTaskRequestedEventArgs.Request.Deadline. /// Therefore, we use this handler to only create the print task. /// The print settings customization can be done when the print document source is requested. /// </summary> /// <param name="sender">PrintManager</param> /// <param name="e">PrintTaskRequestedEventArgs</param> protected override void PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs e) { PrintTask printTask = null; printTask = e.Request.CreatePrintTask("C# Printing SDK Sample", sourceRequestedArgs => { PrintTaskOptionDetails printDetailedOptions = PrintTaskOptionDetails.GetFromPrintTaskOptions(printTask.Options); IList<string> displayedOptions = printDetailedOptions.DisplayedOptions; // Choose the printer options to be shown. // The order in which the options are appended determines the order in which they appear in the UI displayedOptions.Clear(); displayedOptions.Add(Windows.Graphics.Printing.StandardPrintTaskOptions.Copies); displayedOptions.Add(Windows.Graphics.Printing.StandardPrintTaskOptions.Orientation); displayedOptions.Add(Windows.Graphics.Printing.StandardPrintTaskOptions.ColorMode); // Create a new list option PrintCustomItemListOptionDetails pageFormat = printDetailedOptions.CreateItemListOption("PageRange", "Page Range"); pageFormat.AddItem("PrintAll", "Print all"); pageFormat.AddItem("PrintSelection", "Print Selection"); pageFormat.AddItem("PrintRange", "Print Range"); // Add the custom option to the option list displayedOptions.Add("PageRange"); // Create new edit option PrintCustomTextOptionDetails pageRangeEdit = printDetailedOptions.CreateTextOption("PageRangeEdit", "Range"); // Register the handler for the option change event printDetailedOptions.OptionChanged += printDetailedOptions_OptionChanged; // Register the handler for the PrintTask.Completed event. // Print Task event handler is invoked when the print job is completed. printTask.Completed += async (s, args) => { pageRangeEditVisible = false; selectionMode = false; pageList.Clear(); // Notify the user when the print operation fails. if (args.Completion == PrintTaskCompletion.Failed) { await scenarioPage.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { MainPage.Current.NotifyUser("Failed to print.", NotifyType.ErrorMessage); }); } await scenarioPage.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { // Restore first page to its default layout. // Undo any changes made by a text selection. ShowContent(null); }); }; sourceRequestedArgs.SetSource(printDocumentSource); }); }
void ManagerPrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs args) { PrintTask task = null; task = args.Request.CreatePrintTask("Phone Information - Details", sourceRequested => { sourceRequested.SetSource(source); }); }
/// <summary> /// This is the event handler for PrintManager.PrintTaskRequested. /// </summary> /// <param name="sender">PrintManager</param> /// <param name="e">PrintTaskRequestedEventArgs </param> protected virtual void PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs e) { PrintTask printTask = null; printTask = e.Request.CreatePrintTask("C# Printing SDK Sample", sourceRequested => { // Print Task event handler is invoked when the print job is completed. printTask.Completed += async (s, args) => { // Notify the user when the print operation fails. if (args.Completion == PrintTaskCompletion.Failed) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { //rootPage.NotifyUser("Failed to print.", NotifyType.ErrorMessage); }); } }; sourceRequested.SetSource(printDocumentSource); }); }
/// <summary> /// This is the event handler for PrintManager.PrintTaskRequested. /// </summary> /// <param name="sender">PrintManager</param> /// <param name="e">PrintTaskRequestedEventArgs </param> private void PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs e) { PrintTask printTask = e.Request.CreatePrintTask("Hidden Truth", sourceRequested => sourceRequested.SetSource(printDocumentSource)); }
/// <summary> /// Does actual printing - performed, when device entry in Charms bar is selected /// </summary> private void OnPrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs args) { PrintTask printTask = args.Request.CreatePrintTask("Practitioner Mobile", async (taskArgs) => { var deferral = taskArgs.GetDeferral(); await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { taskArgs.SetSource(printDocument.DocumentSource); deferral.Complete(); }); }); }
// 当出现打印请求时,即弹出打印设备列表时 private void printManager_PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs e) { // 创建一个打印任务 PrintTask printTask = null; printTask = e.Request.CreatePrintTask("打印任务的标题", async sourceRequested => // 在打印设备列表中选择了某个打印机时 { // 打印预览页中的选项 PrintTaskOptionDetails optionDetails = PrintTaskOptionDetails.GetFromPrintTaskOptions(printTask.Options); IList<string> displayedOptions = optionDetails.DisplayedOptions; // 在打印预览页上添加系统内置支持的选项 displayedOptions.Clear(); displayedOptions.Add(StandardPrintTaskOptions.Copies); displayedOptions.Add(StandardPrintTaskOptions.Orientation); displayedOptions.Add(StandardPrintTaskOptions.MediaSize); displayedOptions.Add(StandardPrintTaskOptions.Collation); displayedOptions.Add(StandardPrintTaskOptions.Duplex); printTask.Options.MediaSize = PrintMediaSize.NorthAmericaLegal; // 在打印预览页上添加自定义选项 PrintCustomItemListOptionDetails pageFormat = optionDetails.CreateItemListOption("CustomOption", "自定义选项"); // 第1个参数:optionId;第2个参数:displayName pageFormat.AddItem("item1", "选项1"); // 第1个参数:itemId;第2个参数:displayName pageFormat.AddItem("item2", "选项2"); pageFormat.AddItem("item3", "选项3"); displayedOptions.Add("CustomOption"); optionDetails.OptionChanged += printDetailedOptions_OptionChanged; // 当打印预览页中的自定义选项的选中项发生变化时 // 告诉打印任务需要打印的内容 await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { sourceRequested.SetSource(printDocument.DocumentSource); }); // 当打印任务完成时 printTask.Completed += async (s, args) => { if (args.Completion == PrintTaskCompletion.Failed) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { }); } }; }); }
void _PrintManager_PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs args) { var printTask = args.Request.CreatePrintTask(_Title, e => e.SetSource(_PrintDocumentSource)); printTask.Completed += printTask_Completed; }
private void PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs e) { PrintTask printTask = null; printTask = e.Request.CreatePrintTask("Printing Analysis", sourceRequested => { // Print Task event handler is invoked when the print job is completed. printTask.Completed += async (s, args) => { // Notify the user when the print operation fails. if (args.Completion == PrintTaskCompletion.Failed) { // request an UI task from within print Task worker thread await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { new Windows.UI.Popups.MessageDialog("Analysis failed to print").ShowAsync(); }); } }; sourceRequested.SetSource(printDocumentSource); }); }
private void manager_PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs args) { PrintTask task = null; task = args.Request.CreatePrintTask("Print Job", sourceRequested => { sourceRequested.SetSource(this.source); }); }
/// <summary> /// This is the event handler for PrintManager.PrintTaskRequested. /// In order to ensure a good user experience, the system requires that the app handle the PrintTaskRequested event within the time specified /// by PrintTaskRequestedEventArgs->Request->Deadline. /// Therefore, we use this handler to only create the print task. /// The print settings customization can be done when the print document source is requested. /// </summary> /// <param name="sender">The print manager for which a print task request was made.</param> /// <param name="e">The print taks request associated arguments.</param> protected override void PrintTaskRequested(Windows.Graphics.Printing.PrintManager sender, Windows.Graphics.Printing.PrintTaskRequestedEventArgs e) { PrintTask printTask = null; printTask = e.Request.CreatePrintTask("C# Printing SDK Sample", sourceRequestedArgs => { PrintTaskOptionDetails printDetailedOptions = PrintTaskOptionDetails.GetFromPrintTaskOptions(printTask.Options); // Choose the printer options to be shown. // The order in which the options are appended determines the order in which they appear in the UI printDetailedOptions.DisplayedOptions.Clear(); printDetailedOptions.DisplayedOptions.Add(Windows.Graphics.Printing.StandardPrintTaskOptions.MediaSize); printDetailedOptions.DisplayedOptions.Add(Windows.Graphics.Printing.StandardPrintTaskOptions.Copies); // Create a new list option. PrintCustomItemListOptionDetails photoSize = printDetailedOptions.CreateItemListOption("photoSize", "Photo Size"); photoSize.AddItem("SizeFullPage", "Full Page"); photoSize.AddItem("Size4x6", "4 x 6 in"); photoSize.AddItem("Size5x7", "5 x 7 in"); photoSize.AddItem("Size8x10", "8 x 10 in"); // Add the custom option to the option list. printDetailedOptions.DisplayedOptions.Add("photoSize"); PrintCustomItemListOptionDetails scaling = printDetailedOptions.CreateItemListOption("scaling", "Scaling"); scaling.AddItem("ShrinkToFit", "Shrink To Fit"); scaling.AddItem("Crop", "Crop"); // Add the custom option to the option list. printDetailedOptions.DisplayedOptions.Add("scaling"); // Set default orientation to landscape. printTask.Options.Orientation = PrintOrientation.Landscape; // Register for print task option changed notifications. printDetailedOptions.OptionChanged += PrintDetailedOptionsOptionChanged; // Register for print task Completed notification. // Print Task event handler is invoked when the print job is completed. printTask.Completed += async(s, args) => { await scenarioPage.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { ClearPageCollection(); // Reset image options to default values. this.photoScale = Scaling.ShrinkToFit; this.photoSize = PhotoSize.SizeFullPage; // Reset the current page description currentPageDescription = null; // Notify the user when the print operation fails. if (args.Completion == PrintTaskCompletion.Failed) { MainPage.Current.NotifyUser("Failed to print.", NotifyType.ErrorMessage); } }); }; // Set the document source. sourceRequestedArgs.SetSource(printDocumentSource); }); }
private void PrintingExample_PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs args) { var printTask = args.Request.CreatePrintTask("Win2D Printing Example", (createPrintTaskArgs) => { createPrintTaskArgs.SetSource(printDocument); }); var detailedOptions = PrintTaskOptionDetails.GetFromPrintTaskOptions(printTask.Options); var pageRange = detailedOptions.CreateItemListOption("PageRange", "Page Range"); pageRange.AddItem("PrintAll", "Print All"); pageRange.AddItem("PrintFirstPage", "Print Only First Page"); var displayedOptions = printTask.Options.DisplayedOptions; displayedOptions.Clear(); displayedOptions.Add(StandardPrintTaskOptions.MediaSize); displayedOptions.Add(StandardPrintTaskOptions.Orientation); displayedOptions.Add("PageRange"); }
/// <summary> /// This is the event handler for PrintManager.PrintTaskRequested. /// </summary> private void PrintManager_PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs e) { PrintTask printTask = null; printTask = e.Request.CreatePrintTask("Printing DEMO.", sourceRequested => { // Print Task event handler is invoked when the print job is completed. printTask.Completed += async (s, args) => { // Notify the user when the print operation fails. if (args.Completion == PrintTaskCompletion.Failed) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { this.OnStatusChanged(new PrintServiceEventArgs("Sorry, failed to print.")); }); } }; sourceRequested.SetSource(printDocumentSource); }); }
private void OnPrintManagerPrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs args) { var printTask = args.Request.CreatePrintTask("Sample Document", OnPrintTaskSourceRequested); GenerateOptions(printTask); }
// #3 - User selects printer void OnPrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs args) { // This gets invoked as soon as the Devices pane is shown PrintTask task = args.Request.CreatePrintTask( this.Child.Title, // what you see in the spooler async (taskArgs) => { // This is invoked on a background thread when the Print // button is clicked var deferral = taskArgs.GetDeferral(); await page.Dispatcher.RunAsync( CoreDispatcherPriority.Normal, () => { // This must run on the main thread taskArgs.SetSource(doc.DocumentSource); deferral.Complete(); }); }); }