android studio pdf viewer example
In this Article today
learn android studio pdf viewer example.
Pdf view also displays information pdf surface area. follow the more information developer google this link.
In order
to let users view PDF documents in an Android app, it's normal practice to
concede this usefulness to an outsider app on the client's gadget. Thusly,
engineers won't need to manufacture their own PDF viewer without any
preparation, anyway, this isn't generally the best arrangement. Imagine a
scenario in which you need to view PDF documents straightforwardly in your app.
Fortunately, the Android SDK gives classes to deal with PDF documents in apps
running Android 5.0 or higher.
Follow the
method pdf view in android studio.
private
AdView mAdView; //Declaire variable mAdView
mAdView =
(AdView) findViewById(R.id.adView);
AdRequest adRequest = new
AdRequest.Builder()
.build();
mAdView.loadAd(adRequest);
Then You
can create Asset folder in android Studio project go to res<<and click
right click and then choose Asset folder. Then paste pdf file Asset folder.
Follow the
full source code android studio pdf viewer example:
1.build.gradle follow the code Add:
compile 'com.github.barteksc:android-pdf-viewer:2.8.2'
compile 'com.google.android.gms:play-services-ads:8.4.0'
compile 'com.github.barteksc:android-pdf-viewer:2.8.2'
2.MainActivity.java:
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.github.barteksc.pdfviewer.PDFView;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;
public class MainActivity extends AppCompatActivity {
private AdView mAdView;
InterstitialAd mInterstitialAd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
PDFView pdfView = (PDFView) findViewById(R.id.pdfView);
pdfView.fromAsset("Java Simple Hello word Programe.pdf").load();
mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.build();
mAdView.loadAd(adRequest);
}
}
3.activity_main:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.github.barteksc.pdfviewer.PDFView
android:id="@+id/pdfView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="87dp"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id"></com.google.android.gms.ads.AdView>
</RelativeLayout>
4.dimens.xml:
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>
5.create an Asset folder follow the steps:
res<<right click<<new<<Asset
6.colors.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#FF4081</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
7.styles.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="colorButtonNormal">@color/colorPrimary</item>
<item name="colorControlHighlight">@color/colorAccent</item>
</style>
</resources>
No comments:
Post a Comment