Inheritance: IPrintManager
        /// <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);
            });
        }
示例#2
0
        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);
                });
            });
        }
示例#3
0
 void manager_PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs args)
 {
     PrintTask task = null;
     task = args.Request.CreatePrintTask("Day #20 - Simple Print Job", sourceRequested =>
     {
         sourceRequested.SetSource(source);
     });
 }
示例#4
0
        /// <summary>
        /// Unwire all events as part of cleanup.
        /// </summary>
        public virtual void UnwireAllEvents() => Xamarin.Forms.Device.BeginInvokeOnMainThread(
            async() =>
        {
            try
            {
                if (_printManager != null)
                {
                    PrintManagerHelper.Instance.ClearPrintTaskRequestedHandler(_printManager);
                    //_printManager.PrintTaskRequested -= PrintTaskRequested;
                    _printManager = null;
                }

                if (_printTask != null)
                {
                    _printTask.Completed -= PrintTaskCompleted;
                    //_printTask.Previewing -= PrintTask_Previewing;
                    //_printTask.Progressing -= PrintTask_Progressing;
                    //_printTask.Submitting -= PrintTask_Submitting;

#if DEBUG
                    DecrementCompletedCount();
                    //DecrementPreviewing();
                    //DecrementProgressing();
                    //DecrementSubmitting();
#endif

                    Windows.Graphics.Printing.OptionDetails.PrintTaskOptionDetails printDetailedOptions
                        = Windows.Graphics.Printing.OptionDetails.PrintTaskOptionDetails.GetFromPrintTaskOptions(_printTask.Options);

                    if (printDetailedOptions != null)
                    {
                        printDetailedOptions.OptionChanged -= PrintDetailedOptions_OptionChanged;
#if DEBUG
                        DecrementOptionChangedCount();
#endif
                    }
                }

                if (_printDocument != null)
                {
                    _printDocument.GetPreviewPage -= GetPrintPreviewPage;
                    _printDocument.Paginate       -= CreatePrintPreviewPages;
                    _printDocument.AddPages       -= AddPrintPages;

#if DEBUG
                    DecrementGetPreviewPageCount();
                    DecrementPaginateCount();
                    DecrementAddPagesCount();
#endif
                }
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception ex)
            {
                await PrintStatusReporting.ReportExceptionSilentlyAsync(ex);
            }
#pragma warning restore CA1031 // Do not catch general exception types
        });
        /// <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("Printing Coloring Page", 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;
                    });
                };

                // Set the document source.
                sourceRequestedArgs.SetSource(printDocumentSource);
            });
        }
示例#6
0
        public virtual void RegisterForPrinting()
        {
            PrintDoc = new PrintDocument();
            PrintDoc.Paginate += CreatePrintPreviewPages;
            PrintDoc.GetPreviewPage += GetPrintPreviewPage;
            PrintDoc.AddPages += AddPrintPages;

            Printmgr = PrintManager.GetForCurrentView();

            Printmgr.PrintTaskRequested += PrintTaskRequested;
        }
        void OnPrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs args)
        { 
            var deferral = args.Request.GetDeferral();

            PrintTask printTask = args.Request.CreatePrintTask(
                "Todays Tasks",
                OnPrintTaskSourceRequestedHandler);

            printTask.Completed += OnPrintTaskCompleted;

            deferral.Complete();
        }
示例#8
0
        /// <summary>
        ///
        /// </summary>
        /// <returns>true if no immediate errors detected, false if an immediate error detected. Note that a true return value does not mean that printing completed successfully, just that it didn't fail immediately</returns>
        protected async Task <bool> RegisterForPrintingAsync()
        {
            try
            {
                _printDocument       = new Windows.UI.Xaml.Printing.PrintDocument();
                _printDocumentSource = _printDocument.DocumentSource;

                _printDocument.Paginate       += CreatePrintPreviewPages;
                _printDocument.GetPreviewPage += GetPrintPreviewPage;
                _printDocument.AddPages       += AddPrintPages;
#if DEBUG
                IncrementAddPagesCount();
                IncrementGetPreviewPageCount();
                IncrementPaginateCount();
#endif

                _printManager = Windows.Graphics.Printing.PrintManager.GetForCurrentView();
                if (!(_printManager is null))
                {
                    PrintManagerHelper.Instance.SetPrintTaskRequestedHandler(
                        _printManager,
                        PrintTaskRequested);
                    return(true);
                }
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception ex)
            {
                await PrintStatusReporting.ReportExceptionAsync(ex);
            }
#pragma warning restore CA1031 // Do not catch general exception types

            if (!(_printDocument is null))
            {
                _printDocument.Paginate       -= CreatePrintPreviewPages;
                _printDocument.GetPreviewPage -= GetPrintPreviewPage;
                _printDocument.AddPages       -= AddPrintPages;
            }

#if DEBUG
            DecrementPaginateCount();
            DecrementGetPreviewPageCount();
            DecrementAddPagesCount();
#endif

            await PrintStatusReporting.ReportErrorAsync(
                CrossPrinting.PrintingMessages.FailedToRegisterForPrinting);

            return(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("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);
            });
        }
        public async Task<PrintTaskCompletion> PrintAsync(string title, IList<UIElement> pages)
        {
            _ResetEvent = new ManualResetEventSlim();

            var completionTask = Task<PrintTaskCompletion>.Run(() =>
            {
                _ResetEvent.Wait();

                return _PrintTaskCompletionValue;
            });

            _Title = title;
            _Pages = pages;

            _PrintManager = PrintManager.GetForCurrentView();
            _PrintManager.PrintTaskRequested += _PrintManager_PrintTaskRequested;
            
            await PrintManager.ShowPrintUIAsync();
            
            return await completionTask;
        }
示例#11
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            //printer
            document = new PrintDocument();
            source = document.DocumentSource;

            document.Paginate += printDocument_Paginate;
            document.GetPreviewPage += printDocument_GetPreviewPage;
            document.AddPages += printDocument_AddPages;

            //za wsqka stranica ot koqto iska6 da printira6 pi6e6 menigyr za printiraneto 
            manager = PrintManager.GetForCurrentView();
            manager.PrintTaskRequested += manager_PrintTaskRequested;


            pages = new List<UIElement>();

            PrepareContent();
            
        }
        /// <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;
        }
 void printManager_PrintTaskInitializing(PrintManager sender, PrintTaskInitializingEventArgs args)
 {
     args.Request.InitializePrintTask(_DocumentSource, "MetroFlickr");
 }
 void ManagerPrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs args)
 {
     PrintTask task = null;
     task = args.Request.CreatePrintTask("Phone Information - Details", sourceRequested =>
     {
         sourceRequested.SetSource(source);
     });
 }
示例#15
0
        /// <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);
            });
        }
 public PrintManagerEvents(PrintManager This)
 {
     this.This = This;
 }
示例#17
0
 /// <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));
 }
示例#18
0
 private void manager_PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs args)
 {
     PrintTask task = null;
     task = args.Request.CreatePrintTask("Print Job", sourceRequested =>
     {
         sourceRequested.SetSource(this.source);
     });
 }
 private void OnPrintManagerPrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs args)
 {
     var printTask = args.Request.CreatePrintTask("Sample Document", OnPrintTaskSourceRequested);
     GenerateOptions(printTask);
 }
        /// <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);
            });
        }
 /// <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();
                 });
         });
 }
        /// <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);
            });
        }
        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); 
                }); 
        }
示例#24
0
        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");
        }
 void _PrintManager_PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs args)
 {
     var printTask = args.Request.CreatePrintTask(_Title, e => e.SetSource(_PrintDocumentSource));
     printTask.Completed += printTask_Completed;
 }
示例#26
0
        // 当出现打印请求时,即弹出打印设备列表时
        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, () =>
                        {

                        });
                    }
                };
            });
        }
示例#27
0
 // #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();
                 });
         });
 }