I am working on some stuff that should be able to read PDF in my app and I want to put PDF view in my custom layout. I had preferred Android PDF Viewer but when I performed zoomIn, zoomOut it takes too much time.
So currently I am supposed to use MuPDF open source project to integrate in my project, it's based on JNI and I am not used to it.
I am using Cygwin to build the library for native code. Hence I am unclear with few things:
how to integrate the MuPDF in my project (as per my question title)?
once I will succeed to integrated it then how can I put PDF reader in my custom view (in the XML or programmaticaly)?
This is How I achieve on my mac (2012, intel i5):
Step 1 : Get mupdf-1.2-source.zip
Step 2 : Get android-ndk-mac-64
Step 3 : unzip both of them in new folder call
Android-pdf
and rename unzip folder tomupdf
andandroid-ndk
(you can call them whatever you like)Step 4 : open Terminal and use command :
cd
until you are inandroid-pdf
folderStep 5 : cd
mupdf
than command:make
(will take about 40 sec. to run all scripts)Step 6 : cd
android
(withinmupdf
dir.)Step 7 : open finder go to folder
Android-pdf
that you created thanandroid-ndk
drag file callndk-build
into terminal command line and enter (basically adding a path to ndk-build to operate on mupdf lib.)and after few sec. you should have new folder inside
mupdf > android > libs > ...
use that in your android project.How to use MuPDF with your EXISTING Eclipse project:
Change
MUPDF_ROOT := ..
to
Change
MY_ROOT := ../..
to
Change all the
..
in LOCAL_C_INCLUDES to
Change
MY_ROOT := ../..
to
Change all the
..
in LOCAL_C_INCLUDES to
In between the '' tags paste all the list of activities from
AndroidManifest.xml
inside the /android folder, You should copy from your working copy of AndroidManifest.xml inside mupdf.MuPDF in now in your existing Eclipse project. To use it, call up
com.artifex.mupdf.ChoosePDFActivity.class
in your application. This is the main class for MuPDF.To open pdf with pre-fix file:
Uri uri = Uri.parse("path to pdf file");
Intent intent = new Intent(context, MuPDFActivity.class);
intent.setAction(Intent.ACTION_VIEW);
intent.setData(uri);
context.startActivity(intent);
Hope this help :)
Check this project eBookDroid
I have view pager in my application. I need to show pdf files on each fragment in view pager.is there way to get a pdf view from
mupdf
? normally we callmupdf
as belowSo if i use
mupdf
for my app i have to callMuPDFActivity
on each fragment.I think its not a correct way?Some of the source code files for PDF viewer in Android application. Check the links and try it:
http://code.google.com/p/apv/source/browse/
http://code.google.com/p/android-pdf/
http://code.google.com/p/droidreader/
http://andpdf.sourceforge.net/
http://soft.udm4.com/downloading/pdf_viewer_open_source_code_in_android/ (dead link)
http://open-app.org/2011/02/pdf-viewer-a-simple-open-source-pdf-viewer-for-android/ (dead link)
http://androidunderground.blogspot.com/2011/08/pdf-viewer-has-colors-and-speed-but.html (dead link)
The answer given by
star18bit
pretty much sums it up, but even folllowing that I faced a lot of issues.Like the
make
command didn't work for me and I had to build it using Visual Studio. So I listed all the pre-req softwares. Like ANT. Also we need to add the sdk folder'stools
andplatform-tools
folders in PATH.Also, I had to do the changes in
Core2.mk
file, the same ones inCore.mk
. I can't give all the information here, cause it is a lot, so I referring this link for complete information:http://howtojava.net/tutorials/android/integrate-mupdf-with-android-in-windows-7
I don't know how to do this in Windows using cygwin, because I'm using Ubuntu for the development. But I think the procedure should be the same.
Compile thumb : mupdfthirdparty <= jbig2.c In file included from /home/yury/programming/android/workspace/mupdf-0.9/android/jni/../../thirdparty/jbig2dec/os_types.h:53, from /home/yury/programming/android/workspace/mupdf-0.9/android/jni/../../thirdparty/jbig2dec/jbig2.c:22: /home/yury/software/android-ndk-r6b/platforms/android-8/arch-arm/usr/include/stdint.h:48: error: redefinition of typedef 'int8_t' /home/yury/programming/android/workspace/mupdf-0.9/android/jni/../../thirdparty/jbig2dec/os_types.h:47: note: previous declaration of 'int8_t' was here
The solution is explained here: mupdf for android: ndk-build problem (error: redefinition of typedef....) However, you can simply comment the lines of the definition of types in the file /thirdparty/jbig2dec/os_types.h
After that you will receive two libraries: one static and one shared for your android application.
This was the answer on the first question. Also there is a great step-by-step guide in the android/Readme.txt file.
Now the answer on the second question. In the application for android you can find test project. There are 3 files:
Simply copy the last two files in your project. And see an example in MuPDFActivity.java how you can embed mupdf layout in your activity. In this file it is done like: