本文介绍了集成MuPDF读者在一个应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一些东西,应该是能读 PDF 在我的应用程序,我希望把PDF查看我的自定义布局。我有preferred Android的PDF查看器但是当我执行 zoomIn zoomOut 它需要太多的时间

所以,目前我应该使用 MuPDF 开源项目,在我的项目集成,它是基于 JNI ,我不使用它。

我使用的 Cygwin的建图书馆本地code。因此,我不清楚有几件事情:

  1. 如何整合在 MuPDF 在我的项目(​​按照我的问题标题)?

  2. 有一次我一定会成功集成到它,然后我怎样才能把PDF阅读器在我的自定义视图(在XML或programmaticaly)?

解决方案

我不知道如何使用cygwin的Windows中做到这一点,因为我使用Ubuntu的开发。但我认为程序应该是一样的。

  1. 点击这里下载文件mupdf-0.9-source.tar.gz:<一href="http://$c$c.google.com/p/mupdf/downloads/list?q=source">http://$c$c.google.com/p/mupdf/downloads/list?q=source
  2. 下载文件mupdf-thirdparty.zip
  3. 提取来源。默认情况下,他们将提取到的文件夹:mupdf-0.9 /
  4. 解压缩文件mupdf-thirdparty.zip到该文件夹​​mupdf-0.9 /
  5. 生成项目mupdf-0.9(适用于Windows,你应该使用VS,因为它是在自述文件中声明)
  6. 然后转到文件夹mupdf-0.9 /安卓/
  7. 运行NDK建造
  8. 您可以得到以下错误:

编译大拇指:mupdfthirdparty&LT; = 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:注意:previous的中int8_t的声明在这里

该解决方案在此说明:mupdf为Android:NDK建造问题(错误:重新定义的typedef ....)但是,你可以简单地评论在文件/thirdparty/jbig2dec/os_types.h的类型定义

的行

之后,你将收到两个库:一个静态和一个共享的Andr​​oid应用程序

  STATICLIBRARY:libmupdfthirdparty.a
SharedLibrary:libmupdf.so
 

这是第一个问题的答案。也有一个很大的一步一步的指导,在android / Readme.txt文件。

现在对第二个问题的答案。在应用为Android,你可以找到测试项目。有3个文件:

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

只要最后两个文件复制在你的项目。并查看MuPDFActivity.java一个例子,你如何嵌入mupdf布局在您的活动。在这个文件很喜欢做的:

  PixmapView pixmapView;
// ...
布局=新RelativeLayout的(这一点);
// ...
    RelativeLayout.LayoutParams pixmapParams =
                      新RelativeLayout.LayoutParams(
                                RelativeLayout.LayoutParams.FILL_PARENT,
                                RelativeLayout.LayoutParams.FILL_PARENT);
    pixmapParams.addRule(RelativeLayout.ABOVE,100);
    layout.addView(pixmapView,pixmapParams);

    的setContentView(布局);
 

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:

  1. how to integrate the MuPDF in my project (as per my question title)?

  2. once I will succeed to integrated it then how can I put PDF reader in my custom view (in the XML or programmaticaly)?

解决方案

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.

  1. Download the file mupdf-0.9-source.tar.gz here:http://code.google.com/p/mupdf/downloads/list?q=source
  2. Download the file mupdf-thirdparty.zip
  3. Extract the sources. By default they will be extracted to the folder: mupdf-0.9/
  4. Extract the file mupdf-thirdparty.zip into the folder mupdf-0.9/
  5. Build the project mupdf-0.9 (For windows you should use VS as it is declared in the readme files)
  6. Then go to the folder mupdf-0.9/android/
  7. Run ndk-build
  8. You can get the following errors:

Compile thumb : mupdfthirdparty <= jbig2.cIn 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.

StaticLibrary  : libmupdfthirdparty.a
SharedLibrary  : libmupdf.so

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:

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

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:

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

这篇关于集成MuPDF读者在一个应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 13:30