Cannot print pdf files from WebView

dpreznikdpreznik Member ✭✭
edited March 20 in Xamarin.Forms

Dear experts,

I have a Xamarin.Forms UWP application that uses WebView to display pdf files. I took the solution for it here:

https://github.com/xamarin/recipes/tree/master/Recipes/xamarin-forms/Controls/display-pdf

For some reason, printing functionality doesn't work. An exception is thrown on this line in preview.js file:

Printer.startPrint();

Unhandled exception at line 357, column 1 in res://edgehtml.dll/preview.js
0x8000ffff - JavaScript runtime error: Unexpected call to method or property access.

Could you please advise on this?

Thanks,

Best Answer

Answers

  • yelinzhyelinzh Member, Xamarin Team Xamurai
    edited March 21

    Try to use the xamarin print method.

    var printMgr = (PrintManager)GetSystemService(Context.PrintService);
    printMgr.Print("Razor HMTL Hybrid", webView.CreatePrintDocumentAdapter(), null);
    

    The method in the sample uses pdf.js to achieving print, it seems needs some permissson. You can make a thorough inquiry of pdf.js.

  • dpreznikdpreznik Member ✭✭

    @yelinzh said:
    Try to use the xamarin print method.

    var printMgr = (PrintManager)GetSystemService(Context.PrintService);
    printMgr.Print("Razor HMTL Hybrid", webView.CreatePrintDocumentAdapter(), null);
    

    The method in the sample uses pdf.js to achieving print, it seems needs some permissson. You can make a thorough inquiry of pdf.js.

    Thank you for your answer.
    The solution to which I referred in my question does let me display pdf in WebView on UWP.
    It seems to me that your code is written in C#. I don't understand where I should call it from. The existing Print button calls a javascript function. Please clarify.
    Thank you.

Sign In or Register to comment.