Changing Print Options in UWP app

Has anyone successfully followed the example in https://help.syncfusion.com/xamarin/pdf-viewer/printing-pdf-files  to change print options?

I have:

        public PrintPopUp(byte[] pdf)
        {
            InitializeComponent();
            Pdf = pdf;
            pdfViewerControl.PrintTaskRequested += PdfViewer_PrintTaskRequested;
        }


        private void PdfViewer_PrintTaskRequested(object sender, PdfViewerPrintTaskRequestedEventArgs e)
        {
            DependencyService.Get<IPrintRequestHandler>().PrintTaskRequested(sender, e);
        }

    class PrintRequestHandler : IPrintRequestHandler
    {
        public void PrintTaskRequested(object sender, PdfViewerPrintTaskRequestedEventArgs e)
        {
            PrintTask printTask = null;
            printTask = (e.Request as PrintTaskRequest).CreatePrintTask("Printing", sourceRequested =>
            {
                PrintTaskOptionDetails printDetailedOptions = PrintTaskOptionDetails.GetFromPrintTaskOptions(printTask.Options);
                IList<string> displayedOptions = printDetailedOptions.DisplayedOptions;
                displayedOptions.Add(Windows.Graphics.Printing.StandardPrintTaskOptions.CustomPageRanges);
                printTask.Options.PageRangeOptions.AllowCurrentPage = true;
                printTask.Options.PageRangeOptions.AllowAllPages = true;
                printTask.Options.PageRangeOptions.AllowCustomSetOfPages = true;
                printTask.Options.Orientation = PrintOrientation.Landscape;
                // Set the pdfViewerControl’s print document source.
                //sourceRequestedArgs.SetSource(e.PrintDocumentSource as IPrintDocumentSource);
                e.PrintTask = printTask;
            });
        }
    }

sourceRequestedArgs.SetSource is commented out - I don't know how/where sourceRequestedArgs  is initialized.

Running this gets as PdfViewer_PrintTaskRequested is exited:

A method was called at an unexpected time.

Only one PrintTask may be created when the PrintTaskRequested event is raised.



1 Reply

MA ManojKumar Arumugasamy Syncfusion Team May 18, 2023 09:28 AM UTC

Hi Neil,

We have implemented a dependency to change the print options on the UWP platform. Please find the sample at the following link:
https://www.syncfusion.com/downloads/support/directtrac/general/ze/PrintSample1686826288


Loader.
Up arrow icon