MuPDF Reader Integration in Application

I am working on some materials that should be able to read PDF in my application, and I want to put the PDF view in my own layout . I preferred the Android PDF Viewer , but when I ran zoomIn , zoomOut , it takes too much time .

So for now, I have to use the MuPDF open source project to integrate into my JNI based project, and I'm not used to it.

I use Cygwin to create a library for my own code. Therefore, I do not understand, with some things:

  • How to integrate MuPDF in my project (according to my question title)?

  • As soon as I manage to integrate it, how can I put the PDF-Reader in my custom view (in XML or programmatically)?

+47
android pdf android-ndk render mupdf
Dec 14 '11 at 6:53
source share
6 answers

I do not know how to do this on Windows using cygwin, because I use Ubuntu for development. But I think the procedure should be the same.

  • Download the mupdf-0.9-source.tar.gz file here: http://code.google.com/p/mupdf/downloads/list?q=source
  • Download the mupdf-thirdparty.zip file
  • Extract the sources. By default they will be extracted to the folder: mupdf-0.9 /
  • Extract the mupdf-thirdparty.zip file to the mupdf-0.9 folder /
  • Create a mupdf-0.9 project (for windows you should use VS as it is declared in readme files)
  • Then go to the mupdf-0.9 / android / folder
  • Run ndk-build
  • You may receive the following errors:

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: overdefining typedef ....) However, you can just comment on the type definition lines in the file / thirdparty / jbig 2dec / os_types.h

After that, you will get two libraries: one static and one shared for your Android application.

 StaticLibrary : libmupdfthirdparty.a SharedLibrary : libmupdf.so 

This was the answer to the first question. There is also a big step-by-step guide in the android / Readme.txt file.

Now the answer to the second question. In the Android application you can find a test project. There are 3 files:

  • MuPDFActivity.java
  • MuPDFCore.java
  • PixmapView.java

Just copy the last two files to your project. And look at an example in MuPDFActivity.java how you can embed the mupdf layout in your activity. In this file, it is done like this:

  PixmapView pixmapView; //... layout = new RelativeLayout(this); //... RelativeLayout.LayoutParams pixmapParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT); pixmapParams.addRule(RelativeLayout.ABOVE,100); layout.addView(pixmapView, pixmapParams); setContentView(layout); 
+46
Dec 21 '11 at 9:24 a.m.
source share

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 a new call to the Android-pdf folder and rename the unzip folder to mupdf and android-ndk (you can name them whatever you want)

Step 4: open a terminal and use the command: cd until you are in the Android-pdf folder

Step 5: cd mupdf than the command: make (it will take about 40 seconds to run all the scripts)

Step 6: cd android (inside mupdf dir.)

Step 7: open the search in the Android-pdf folder that you created, than android-ndk drag the ndk-build call file to the terminal command line and type in (basically adding the path to ndk-build to work with mupdf lib.)

and after a few seconds. you should have a new folder inside mupdf > android > libs > ... used in your android project.

How to use MuPDF with your EXISTING Eclipse project:

  • Copy the jni folder from the / android folder to your existing Eclipse project.
  • Copy the / thirdparty folder to the jni folder in your project.
  • Copy the / cbz folder to the "jni" folder in your project.
  • Copy the / draw folder to the jni folder in your project.
  • Copy the / fitz folder to the jni folder in your project.
  • Copy the / generated folder to the jni folder in your project.
  • Copy the / pdf folder to the "jni" folder in your project.
  • Copy the / scripts folder to the "jni" folder in your project.
  • Copy the / xps folder to the "jni" folder in your project.
  • Open "Android.mk" in the "jni" folder.
  • Edit

    MUPDF_ROOT: = ..

to

 MUPDF_ROOT := $(TOP_LOCAL_PATH) 
  • Save "Android.mk".
  • Open "Core.mk" inside the "jni" folder.
  • Edit

    MY_ROOT: = .. / ..

to

 MY_ROOT := $(LOCAL_PATH) 
  • Change everything

    ..

at LOCAL_C_INCLUDES until

 $(LOCAL_PATH) 
  • Save 'Core.mk'.
  • Open "ThirdParty.mk" inside the "jni" folder.
  • Edit

    MY_ROOT: = .. / ..

to

 MY_ROOT := $(LOCAL_PATH) 
  • Change everything

    ..

in LOCAL_C_INCLUDES for

 $(LOCAL_PATH) 
  • Save 'ThirdParty.mk'.
  • Now run "ndk-build" in the project directory "jni".
  • Copy everything to the / android / src folder in the 'src' folder in your project.
  • Copy everything to the / android / res / drawable folder in the "res / drawable" folder in your project.
  • Copy everything to the / android / res / drawable -ldpi folder in the "res / drawable-ldpi" folder in your project.
  • Copy everything to the / android / res / drawable-mdpi folder in the "res / drawable-mdpi" folder in your project.
  • Copy everything into the / android / res / layout EXCEPT main.xml folder (because if you copy an existing project, you must have your own main.xml or equivalent) in the "res / layout" folder in your project.
  • Copy everything to the / android / res / values ​​folder in the "res / values" folder in your project. If you already have "strings.xml" in an existing project, copy everything between the "tags" of your /android/res/values/strings.xml into your strings.xml project (paste between the "tags"). Like "colors.xml", if you already have "colors.xml" in an existing project, copy everything between the "/" tags in your /android/res/values/strings.xml into your strings.xml project (paste between " tags ").
  • Open "AndroidManifest.xml" in the project.
  • Between tags '' insert the entire list of actions from

    AndroidManifest.xml inside the / android folder, Copy from a working copy from AndroidManifest.xml inside mupdf.

  • MuPDF is now in your existing Eclipse project. To use it, call com.artifex.mupdf.ChoosePDFActivity.class in your application. This is the main class for MuPDF.

  • To open pdf with the pre-fix file:

    Uri uri = Uri.parse ("path to the PDF file");

    Intent intent = new Intent (context, MuPDFActivity.class);

    intent.setAction (Intent.ACTION_VIEW);

    intent.setData (URI);

    context.startActivity (intentions);

Hope this help :)

+7
Jul 18 '13 at 23:53 on
source share

Check out this eBookDroid project

EBookDroid is an open source document viewer (GPL) for Android based on VuDroid code.

Supported file in the following formats:

 PDF DjVu XPS (OpenXPS) comics books (cbz,cbr) 
+5
Dec 14 2018-11-11T00:
source share

I have a pager view in my application. Do I need to show pdf files on each fragment in the pager.is view in order to get a PDF view from mupdf ? usually we call mupdf below

 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); 

So, if I use mupdf for my application, I have to call MuPDFActivity for each fragment. I think this is not the right way?

0
Oct 03 '14 at 7:21
source share

The answer given by star18bit pretty much sums it up, but even after I run into a lot of problems.

Like the make , this did not work for me, and I had to create it using Visual Studio. Therefore, I have listed all the preliminary recommendations. Like ant. We also need to add the sdk tools and platform-tools folders to PATH.

In addition, I had to make changes to the Core2.mk file, the same in Core.mk I cannot provide all the information here because it is a lot, so I refer to this link for complete information:

http://howtojava.net/tutorials/android/integrate-mupdf-with-android-in-windows-7

0
Jan 09 '15 at 11:18
source share



All Articles