Asked  10 Months ago    Answers:  5   Viewed   7 times

I am working on Xamarin Forms - UWP. I want to display local PDF file in webview control. I followed these 2 links :-

Xamarin Forms UWP - Display PDF

It opens the pdf file but content is all blank. Can anyone please help me in what I may be missing?

Thanks in advance!

Here is my code:- CustomWebView.cs

public class CustomWebView : WebView
        public static readonly BindableProperty UriProperty = BindableProperty.Create(propertyName: "Uri",
                returnType: typeof(string),
                declaringType: typeof(CustomWebView),
                defaultValue: default(string));

        public string Uri
            get { return (string)GetValue(UriProperty); }
            set { SetValue(UriProperty, value); }

<ContentPage xmlns=""

    <local:CustomWebView Uri="samplepdf.pdf" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" />

[assembly: ExportRenderer(typeof(PdfViewer.CustomWebView), typeof(CustomWebViewRenderer))]
namespace PdfViewer.UWP
    public class CustomWebViewRenderer : WebViewRenderer
        protected override void OnElementChanged(ElementChangedEventArgs<WebView> e)

            if (e.NewElement != null)
                var customWebView = Element as CustomWebView;
                Control.Source = new Uri(string.Format("ms-appx-web:///Assets/pdfjs/web/viewer.html?file={0}", string.Format("ms-appx-web:///Assets/Content/{0}", WebUtility.UrlEncode(customWebView.Uri))));

UWP - Assets - pdfjs structure



Looks like something happened with Asset folder files. When was updated from nuget repository it worked.

Saturday, August 21, 2021

I have a pdf in the raw folder and I am trying to open it in a webview using "" to open it in the webview.

That has never been possible.

Is there a better way to load a local pdf inside my app without having it take up the entire activity page?

The best thing is to not load it inside your app at all. Use the user's preferred PDF viewing app, via ACTION_VIEW.

Beyond that, you could use a slightly modified version of PDF.js on Android 4.4+. Or, use AndroidPdfViewer on a wider range of Android versions, though it makes your APK a lot bigger. See this blog post for more context on these and other (worse) options.

Also, here are sample apps demonstrating:

  • PDF.js:
  • AndroidPdfViewer:
Thursday, August 5, 2021

The plugin you used is too old. You could use ImageCropper.Forms.Fix.v2 instead.

Add the code below in your MainActivity:

   protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        base.OnActivityResult(requestCode, resultCode, data);
        Stormlion.ImageCropper.Droid.Platform.OnActivityResult(requestCode, resultCode, data);

Add the code in tag of AndroidManifest.xaml:

<activity android:name="com.theartofdev.edmodo.cropper.CropImageActivity" android:theme="@style/Base.Theme.AppCompat" />

Code behind:

 new ImageCropper()
            //                PageTitle = "Test Title",
            //                AspectRatioX = 1,
            //                AspectRatioY = 1,
            Success = (imageFile) =>
                Device.BeginInvokeOnMainThread(() =>
                    image.Source = ImageSource.FromFile(imageFile);

When you click the button, it would pop up a window. If you want to take photo, choose the Take Photo. Please note, you need to add the CAMERA permission.

<uses-permission android:name="android.permission.CAMERA" />

Or you could select the image from the device to crop.


Wednesday, September 1, 2021

Is it possible to open a local PDF file using Google Docs + webview?

Only if you upload the PDF somewhere on the Internet where Google Docs can access it, or perhaps arrange for somebody else to upload the PDF somewhere on the Internet where Google Docs can access it (e.g., Google Drive).

Thursday, September 23, 2021

As of Xamarin Forms 2.3.1, WebViewRenderer for Windows RT simply ignores the BaseUrl ( However, there is a fix for this on the 2.3.2 branch:

Saturday, December 25, 2021
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :