在应用程序中集成 MuPDF 阅读器 [英] Integrate MuPDF Reader in an app

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

问题描述

我正在处理一些应该能够在我的应用中读取 PDF 的内容,并且我想将 PDF 视图放入我的自定义布局.我更喜欢 Android PDF 查看器,但是当我执行 zoomInzoomOut 时,它花费了太多时间.

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.

所以目前我应该使用MuPDF开源项目集成到我的项目中,它基于JNI,我不习惯.

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.

我正在使用 Cygwin 为本机代码构建库.因此我不清楚一些事情:

I am using Cygwin to build the library for native code. Hence I am unclear with few things:

  1. 如何将 MuPDF 集成到我的项目中(按照我的问题标题)?

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

一旦我成功集成了它,那么如何将 PDF 阅读器放入我的自定义视图(在 XML 中或以编程方式)?

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

推荐答案

我不知道如何使用 cygwin 在 Windows 中执行此操作,因为我使用 Ubuntu 进行开发.但我认为程序应该是一样的.

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. 在此处下载文件 mupdf-0.9-source.tar.gz:http://code.google.com/p/mupdf/downloads/list?q=来源
  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/android/
  7. 运行 ndk-build
  8. 您可能会收到以下错误:

编译拇指: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

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

之后,您将收到两个库:一个是静态库,一个是为您的 android 应用程序共享的库.

After that you will receive two libraries: one static and one shared for your android application.

StaticLibrary  : libmupdfthirdparty.a
SharedLibrary  : libmupdf.so

这是第一个问题的答案.在 android/Readme.txt 文件中还有一个很好的分步指南.

This was the answer on the first question. Also there is a great step-by-step guide in the android/Readme.txt file.

现在回答第二个问题.在 android 应用程序中,您可以找到测试项目.有3个文件:

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

只需复制项目中的最后两个文件即可.并在 MuPDFActivity.java 中查看如何在活动中嵌入 mupdf 布局的示例.在这个文件中,它是这样完成的:

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 阅读器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆