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.