我正在开发一些应该能够在我的应用程序中读取 PDF 的内容,并且我想将 PDF 视图放入我的自定义布局中。我更喜欢Android PDF Viewer,但当我执行zoomIn、zoomOut时,它花费了太多时间。
所以目前我应该使用MuPDF开源项目集成到我的项目中,它是基于JNI的,我不习惯它。
我正在使用 Cygwin 构建本机代码库。因此,我不清楚一些事情:
-
如何将MuPDF集成到我的项目中(根据我的问题标题)?
-
一旦我成功集成它,那么如何将 PDF 阅读器放入我的自定义视图(以 XML 或编程方式)?
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)?
发布评论
评论(6)
我的应用程序中有查看寻呼机。我需要在视图分页器中的每个片段上显示 pdf 文件。有没有办法从
mupdf
获取 pdf 视图?通常我们如下调用mupdf
所以如果我在我的应用程序中使用
mupdf
我必须在每个片段上调用 MuPDFActivity
。我认为它不正确方式?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?star18bit
给出的答案几乎概括了这一点,但即使如此,我也遇到了很多问题。就像
make
命令对我不起作用,我必须使用 Visual Studio 构建它。所以我列出了所有必备软件。就像蚂蚁一样。此外,我们还需要在 PATH 中添加 sdk 文件夹的tools
和platform-tools
文件夹。另外,我必须在
Core2.mk
文件中进行更改,与Core.mk
中的更改相同。我无法在这里提供所有信息,因为信息很多,所以我参考此链接获取完整信息:http://howtojava.net/tutorials/android/integrate-mupdf-with-android-in-windows-7
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
我不知道如何使用 cygwin 在 Windows 中执行此操作,因为我使用 Ubuntu 进行开发。但我认为程序应该是一样的。
http://code.google.com/p/mupdf/downloads/list ?q=source
Compilethumb : mupdfthirdparty <= jbig2.c
在 /home/yury/programming/android/workspace/mupdf-0.9/android/jni/../../thirdparty/jbig2dec/os_types.h:53 包含的文件中,
来自/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:错误:重新定义 typedef 'int8_t'
/home/yury/programming/android/workspace/mupdf-0.9/android/jni/../../thirdparty/jbig2dec/os_types.h:47:注意:之前的“int8_t”声明在这里
解决方案解释如下:mupdf for android:ndk-build问题(错误:typedef的重新定义....)
但是,您可以简单地注释文件 /thirdparty/jbig2dec/os_types.h 中类型定义的行
,之后您将收到两个库:一个是静态的,另一个是为您的 Android 应用程序共享的。
这是第一个问题的答案。 android/Readme.txt 文件中还有一个很棒的分步指南。
现在回答第二个问题。
在 Android 应用程序中,您可以找到测试项目。有 3 个文件:
只需复制项目中的最后两个文件即可。请参阅 MuPDFActivity.java 中的示例,了解如何在 Activity 中嵌入 mupdf 布局。在此文件中,它的完成方式如下:
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.
http://code.google.com/p/mupdf/downloads/list?q=source
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:
Android应用程序中PDF查看器的一些源代码文件。检查链接并尝试一下:
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/(死链接)
http://open-app.org/2011/02/pdf-viewer-a-simple-open-source-pdf-viewer-for-android/(死链接)
http://androidunderground.blogspot.com/2011/08/pdf-viewer-has-colors-and-speed-but.html(死链接)
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)
这是我在 Mac(2012 年,intel i5)上实现的方法:
步骤 1:获取 mupdf-1.2-source.zip
第 2 步:获取 android-ndk-mac-64
步骤 3:解压它们在新文件夹中调用
Android-pdf
并将解压缩文件夹重命名为mupdf
和android-ndk
(您可以随意称呼它们)第 4 步:打开终端并使用命令:
cd
直到进入android-pdf
文件夹第5步:cd
mupdf
然后命令:make
(运行所有脚本大约需要 40 秒)步骤 6:cd
android
(在mupdf
目录中。)步骤 7:打开 finder 进入文件夹
Android-您创建的 pdf
比android-ndk
将文件调用ndk-build
拖到终端命令行并输入(基本上添加 ndk-build 的路径以在 mupdf lib 上操作。)几秒后。你应该在
mupdf > 中有一个新文件夹安卓>库> ...
在你的 android 项目中使用它。如何在现有 Eclipse 项目中使用 MuPDF:
改变
MUPDF_ROOT := ..
以
改变
MY_ROOT := ../..
更改为
更改所有
..
LOCAL_C_INCLUDES 中的内容以
改变
MY_ROOT := ../..
更改为
更改全部
..
将LOCAL_C_INCLUDES 中
在 '' 标签之间粘贴
中的所有活动列表
AndroidManifest.xml
在 /android 文件夹内,您应该从 mupdf 内的 AndroidManifest.xml 的工作副本复制。MuPDF 现在位于您现有的 Eclipse 项目中。要使用它,请在应用程序中调用
com.artifex.mupdf.ChoosePDFActivity.class
。这是 MuPDF 的主类。要打开带有前缀文件的 pdf:
Uri uri = Uri.parse("pdf 文件路径");
Intent意图 = new Intent(context, MuPDFActivity.class);
intent.setAction(Intent.ACTION_VIEW);
intent.setData(uri);
context.startActivity(intent);
希望这有帮助:)
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 :)
检查此项目 eBookDroid
Check this project eBookDroid