Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SOS Help no Document using xamarin android ?? #2

Open
mgmehdiforme opened this issue Aug 4, 2016 · 5 comments
Open

SOS Help no Document using xamarin android ?? #2

mgmehdiforme opened this issue Aug 4, 2016 · 5 comments

Comments

@mgmehdiforme
Copy link

Hello friend,

Thanks for bringing this awesome library.

Would you mind share some information about how to use it in a xamarin.android project?

thank you.

@alexrainman
Copy link
Owner

Will leave you some instructions later. Thanks

@alexrainman
Copy link
Owner

In your activity, add this two properties:

ReaderController m_vPDF = null;
Com.Radaee.Pdf.Document doc = new Com.Radaee.Pdf.Document();

Then OnCreate, add this:

Global.Init((Android.App.Activity)Context);

Global.ActiveStandard ((Android.App.Activity)Context, "Company", "Email","key");

m_vPDF = new ReaderController(Context);
doc.Close ();

// PCLstorage to get app files folder
// you can use you own implementation here to get filepath
var rootFolder = FileSystem.Current.LocalStorage.Path;
var path = System.IO.Path.Combine (rootFolder, "filename");

int ret = doc.Open( path, null);

switch (ret)
{
    case -1://need input password
        break;
    case -2://unknown encryption
        break;
    case -3://damaged or invalid format
        break;
    case -10://access denied or invalid file path
        break;
    case 0://succeeded, and continue
        break;
    default://unknown error
        break;
}

m_vPDF.Open(doc);

var layout = new LinearLayout(this);
layout.Orientation = Orientation.Vertical;

layout.AddView(m_vPDF);

SetContentView(layout);

Then on Dispose:

if (m_vPDF != null)
{
    m_vPDF.Close ();
    m_vPDF = null;
}

if (doc != null) {
    doc.Close ();
    doc = null;
}

Global.RemoveTmp ();

This was a long time ago so, maybe radaee library has changed a lot. Cant find example of the other one.

@alexrainman
Copy link
Owner

If you want to go with something more modern, take a look at this:

https://developer.xamarin.com/recipes/cross-platform/xamarin-forms/controls/display-pdf/

You can implement the same thing in a native WebView.

@alexrainman
Copy link
Owner

They use a custom renderer with each platform native WebView, so, if you follow this link, you will see how Xamarin Android do the thing:

https://developer.xamarin.com/guides/xamarin-forms/custom-renderer/hybridwebview/

@alexrainman
Copy link
Owner

This link shows you how to do it in Android:

http://blog.subodhjena.com/xamarin-displaying-pdf-files-on-android-webview/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants