How to open PDF file in Xamarin.Forms

Can anyone help me to open PDF file in Xamarin.Forms . I'm developing a mobile app using Xamarin.Forms.

Best Answer

Answers

  • Hello MitchMilam,

    Thanks for considering my query.

    I've tried these link but there is no luck-

    1) http://stackoverflow.com/questions/25328159/xamarin-forms-open-pdf
    2) http://stackoverflow.com/questions/27193557/xamarin-forms-open-an-android-intent

    There are some methods which are not supported in android project.

    Kindly provide me a zip file of working sample if possible.

    Thanks in advance.

  • Here is the error I'm getting when using http://stackoverflow.com/questions/27193557/xamarin-forms-open-an-android-intent.

    Java.Lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at --- End of managed exception stack trace ---
    at java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
    at Caused by: java.lang.reflect.InvocationTargetException
    at at java.lang.reflect.Method.invoke(Native Method)
    at at java.lang.reflect.Method.invoke(Method.java:372)
    at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
    at ... 1 more
    at Caused by: md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable: System.NullReferenceException: Object reference not set to an instance of an object
    at at Xamarin.Forms.Platform.Android.FormsApplicationActivity.OnPrepareOptionsMenu (Android.Views.IMenu)
    at Android.App.Activity.n_OnPrepareOptionsMenu_Landroid_view_Menu_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/1780/3518c4ce/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.App.Activity.cs:4151
    at at (wrapper dynamic-method) object.55bd698f-a13d-4d0d-bdb5-898eede2ba52 (intptr,intptr,intptr)
    at at md5530bd51e982e6e7b340b73e88efe666e.FormsApplicationActivity.n_onPrepareOptionsMenu(Native Method)
    at at md5530bd51e982e6e7b340b73e88efe666e.FormsApplicationActivity.onPrepareOptionsMenu(FormsApplicationActivity.java:110)
    at at android.app.Activity.onPreparePanel(Activity.java:2848)
    at at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:576)
    at at com.android.internal.policy.impl.PhoneWindow.doInvalidatePanelMenu(PhoneWindow.java:917)
    at at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:258)
    at at android.os.Handler.handleCallback(Handler.java:739)
    at at android.os.Handler.dispatchMessage(Handler.java:95)
    at at android.os.Looper.loop(Looper.java:135)
    at at android.app.ActivityThread.main(ActivityThread.java:5312)
    at ... 4 more

  • KaaminichaudharyKaaminichaudhary USMember
    edited June 2015

    I've completed this in Xamarin.Android, here is code

    using Uri = Android.Net.Uri;
    string downloadsPath = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads).AbsolutePath;
    string filePath = "sample.pdf";
    string fullPath = Path.Combine(downloadsPath,filePath);
    Java.IO.File file= new Java.IO.File(fullPath);
    Uri path=Uri.FromFile(file);
    Intent i =new Intent(Intent.ActionView);
    i.SetDataAndType(path,"application/pdf");
    i.SetFlags(ActivityFlags.ClearTop);
    StartActivity(i);

    But my question is, can we write native code in PCL so that we don't need to write code which is platform specific.

    Any Help

Sign In or Register to comment.