As the company mobile app to add an attachment to view the function, need to view the PDF file, found many third-party tools on the Internet, and finally chose Mupdf.
More third-party tools to view the Great God Summary: http://www.cnblogs.com/pokeGame/archive/2011/06/02/2068575.html
Mupdf Introduction:
Lightweight, high-quality PDF/XPS/CBZ viewer on Android devices.
The renderer on the mupdf is designed for high quality anti-aliasing images, which present the spacing between text and text at high-quality pixel-level accuracy to achieve the highest level of display fidelity and reproduce the display of printed paper on the device screen.
The mupdf is compact, fast, but fully functional. It can support the transparency of PDF files, encryption, hyperlinks in files, annotations, search and many other functions, users can also use it to check xps/openxps files. The mupdf is modular and can be incorporated by software integrators if the user is very eager for certain features.
Preparatory work:
In the Androi project to introduce Mupdf, the first to have a compiled package, you can download the source code at the following address compilation: Git://git.ghostscript.com/mupdf.git, the compilation process is very complex, I failed many times, I do not know exactly where there is a problem.
So I'm using someone else to compile it: Http://pan.baidu.com/s/1CHp3M
With the compiled package, everything is simple, and now we are introducing mupdf.
Introduction steps:
- Copy the Jni,libs,obj folder to the app folder, copy the Res folder to the App\src\main folder, copy the Src\com folder to the App\src\main\java\ folder, and overwrite the original file
- Add in Build.gradle in app
// add the. So file in the Libs apk sourcesets { main { = ['libs'] } }
All codes are as follows:
Apply plugin: ' Com.android.application '
Android {
Compilesdkversion 24
Buildtoolsversion "24.0.2"
Defaultconfig {
ApplicationID "Com.example.admin.pdfread_test2"
Minsdkversion 17
Targetsdkversion 24
Versioncode 1
Versionname "1.0"
Testinstrumentationrunner "Android.support.test.runner.AndroidJUnitRunner"
}
Buildtypes {
Release {
Minifyenabled false
Proguardfiles getdefaultproguardfile (' proguard-android.txt '), ' Proguard-rules.pro '
}
}
Add the. So file in the Libs apk
sourcesets {
Main {
Jnilibs.srcdirs = [' Libs ']
}
}
}
dependencies {
Compile Filetree (dir: ' Libs ', include: [' *.jar '])
Androidtestcompile (' com.android.support.test.espresso:espresso-core:2.2.2 ', {
Exclude group: ' Com.android.support ', module: ' Support-annotations '
})
Compile ' com.android.support:appcompat-v7:24.2.1 '
Testcompile ' junit:junit:4.12 '
}
- Androidmanifest.xml Configuring Mupdfactivity and SD card access rights
<ActivityAndroid:name= "Com.artifex.mupdf.MuPDFActivity"><Intent-filter> <ActionAndroid:name= "Android.intent.action.MAIN" /> <categoryAndroid:name= "Android.intent.category.LAUNCHER" /></Intent-filter></Activity><!--jnilibs.srcdirs = [' Libs '] -<!--SD card access rights -<uses-permissionAndroid:name= "Android.permission.READ_EXTERNAL_STORAGE" /><!--Read -
- Call Mupdf to display a PDF file
String Workstation_datafileurl = Getapplicationcontext (). Getfilesdir (). GetAbsolutePath () + "/sample.pdf"; = Uri.parse (workstation_datafileurl); LOG.D ("Mydebug", Workstation_datafileurl); New Intent (mainactivity. this, mupdfactivity. class ); Intent.setaction (Intent.action_view); Intent.setdata (URI); StartActivity (intent);
- Configure your style to have such a configuration in the Values.xml file:
<stylename= "Apptheme"Parent= "Theme.AppCompat.Light.DarkActionBar"> <!--Customize your theme here. - <Itemname= "Colorprimary">@color/colorprimary</Item> <Itemname= "Colorprimarydark">@color/colorprimarydark</Item> <Itemname= "Coloraccent">@color/coloraccent</Item> </style>
To configure your style, configure the corresponding color in the Colors.xml file
- Compile execution, error when compiling: "The package R does not exist", the introduction of the package can be
Introduction of Mupdf in Android projects