Xamarin.Forms.PDFViewer
Xamarin.Forms.PDFViewer copied to clipboard
SOS Help no Document using xamarin android ??
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.
Will leave you some instructions later. Thanks
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.
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.
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/
This link shows you how to do it in Android:
http://blog.subodhjena.com/xamarin-displaying-pdf-files-on-android-webview/