Java Android PDF 查看器库或 muPDF 库教程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19478168/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 17:36:21  来源:igfitidea点击:

Android PDF Viewer Library or muPDF library tutorials

javaandroidpdfmupdf

提问by dmacan23

I'm trying to read pdf files in my android application. I don't want to use the default pdf reader and simply open a new intent because I need my own GUI, and want to use the first page as a cover. Therefore I need to make my own pdf reader. I did some research and came across muPDF and Android PDF Viewer Library.

我正在尝试在我的 android 应用程序中读取 pdf 文件。我不想使用默认的 pdf 阅读器而只是打开一个新的意图,因为我需要自己的 GUI,并且想使用第一页作为封面。因此我需要制作自己的pdf阅读器。我做了一些研究,发现 muPDF 和Android PDF Viewer Library

  1. I tried to follow tutorial to implement Android PDF Viewer Library, from the github description. But the problem is that it loads pdf file forever. Do I need to do something else than just the steps in the description?

  2. I can't find any tutorials for the muPDF library, are there any? How to implement it?

  3. If there is no useful answer for the previous two questions, are there any good pdf library out there with tutorials and good documentation?

  1. 我试图按照教程来实现 Android PDF 查看器库,来自 github 描述。但问题是它永远加载pdf文件。除了描述中的步骤之外,我还需要做其他事情吗?

  2. 我找不到关于 muPDF 库的任何教程,有吗?如何实施?

  3. 如果前两个问题没有有用的答案,是否有任何带有教程和良好文档的好的 pdf 库?

Thank you, hopefully, I will be able to solve my problem

谢谢,希望能解决我的问题

回答by Librelio

MuPDF is a very good library, you can definitely use it. If you need a complete example of Android app using MuPDF, I suggest you to take a look at this customizable magazine app on Github.

MuPDF 是一个非常好的库,你绝对可以使用它。如果您需要使用 MuPDF 的完整 Android 应用示例,我建议您查看Github上这个可定制的杂志应用。

回答by valleymanbs

first of all, if you want to use MUPDF inside an existing android app project you can follow the guide you find at this link(all credits go to the author, I didn't write this).

首先,如果您想在现有的 android 应用程序项目中使用 MUPDF,您可以按照您在此链接中找到的指南进行操作(所有功劳归作者所有,我没有写这个)。

I am trying as well to integrate a very simple PDF reading/printing solution inside my app and i am struggling to strip down/simplify the MuPdf application demo you get by following that guide. I already managed (somehow) to remove annotation and file-picking features, but i would really need some help as well to get all the job done. There's really a lot of stuff and absolutely no documentation about this. I am simply trying to read the code and figure out what is needed and what is not, removing features one by one and being driven by the errors you get in catlog.

我也在尝试在我的应用程序中集成一个非常简单的 PDF 阅读/打印解决方案,我正在努力剥离/简化您按照该指南获得的 MuPdf 应用程序演示。我已经设法(以某种方式)删除了注释和文件选择功能,但我真的需要一些帮助才能完成所有工作。确实有很多东西,而且绝对没有关于此的文档。我只是试图阅读代码并弄清楚什么是需要的,什么不是,一一删除功能并由您在 catlog 中获得的错误驱动。

Also, as we both (if I understood correctly your needs) need just the PDF rendering features, would be great if someone points out how to (if possible) disable some of the unnecessary features built in the MuPDF library when building it from source (as DjVu support, just as an example).

此外,由于我们俩(如果我正确理解您的需求)都只需要 PDF 渲染功能,如果有人指出如何(如果可能)在从源代码构建 MuPDF 库时禁用一些内置在 MuPDF 库中的不必要功能,那就太好了(作为 DjVu 支持,仅作为示例)。

Hope this helps, even if it is not a real answer to your question.

希望这会有所帮助,即使它不是您问题的真正答案。

回答by akauppi

This SO answerlists some steps on how to rip essential pieces from the MuPDF Java sample app to one's own.

这个 SO答案列出了一些关于如何将 MuPDF Java 示例应用程序中的基本部分翻录到自己的部分的步骤。

Preferably, I'd like to have a "ready to use" Java library I could attach to as a dependency. Is JNI preventing this or is it simply that no-one's gotten up to doing one?

最好,我希望有一个“随时可用”的 Java 库,我可以将其作为依赖项附加到。JNI 是在阻止这一点,还是只是没有人愿意做一个?

Well, jmupdfis there (mentioned in this duplicate) but that lists Windows and Linux (not specifically Android) as the tested platforms. It seems desktop and dead to me (no changes in 12 months). At least compared to the vibranceof MuPDF itself.

嗯,jmupdf在那里(在这个副本中提到),但它列出了 Windows 和 Linux(不是专门的 Android)作为测试平台。对我来说,桌面似乎已经死了(12 个月内没有变化)。至少与MuPDF 本身的活力相比。

回答by billowavetor

This is how I succeeded in building a MuPDF lib on windows with Cygwin, android-ndk

这就是我使用 Cygwin、android-ndk 在 Windows 上成功构建 MuPDF 库的方式

  1. Download MuPDF 1.3 Source from https://code.google.com/p/mupdf/downloads/listunzip to folder c:/mupdf-1.3-source

  2. Install Cygwin: Download and run Run setup-x86.exe from http://cygwin.com/install.htmlwhen installing cygwin, make sure you selected make packages and C++ compilers

  3. Make generate. open cygwin terminal, run

    cd /cygdrive/
    cd c/mupdf-1.3-source
    make generate
    
  4. Install android-ndk: download android-ndk-r9d-windows-x86.zip and unzip it to

    c:/android-ndk-r9d
    
  5. Build mupdf lib: on windows cmd console:

    • preparation:

      cd c:/mupdf-1.3-source/platform/android
      copy local.properties.sample local.properties
      

      edit local.properties, uncomment

      #sdk.dir=C:\Program Files (x86)\Android\android-sdk
      

      and change to

      sdk.dir=REAL andforid-sdk Folder
      
    • build: while still on c:/mupdf-1.3-source/platform/android, run:

      /android-ndk-r9d/ndk-build
      

      Upon the completion of the build, a folder named libs will be created under

      c:/mupdf-1.3-source/platform/android
      
  6. Create android apk. Open eclipse, create a new android project from existing code, browse to c:/mupdf-1.3-source/platform/android, now you can create a mupdf apk.

  1. https://code.google.com/p/mupdf/downloads/list下载 MuPDF 1.3 Source 解压到文件夹 c:/mupdf-1.3-source

  2. 安装 Cygwin: 安装 cygwin 时从http://cygwin.com/install.html下载并运行 Run setup-x86.exe ,确保您选择了 make 包和 C++ 编译器

  3. 使生成。打开cygwin终端,运行

    cd /cygdrive/
    cd c/mupdf-1.3-source
    make generate
    
  4. 安装android-ndk:下载android-ndk-r9d-windows-x86.zip并解压到

    c:/android-ndk-r9d
    
  5. 构建 mupdf lib:在 windows cmd 控制台上:

    • 准备:

      cd c:/mupdf-1.3-source/platform/android
      copy local.properties.sample local.properties
      

      编辑 local.properties,取消注释

      #sdk.dir=C:\Program Files (x86)\Android\android-sdk
      

      并更改为

      sdk.dir=REAL andforid-sdk Folder
      
    • 构建:在仍在c:/mupdf-1.3-source/platform/android运行时,运行:

      /android-ndk-r9d/ndk-build
      

      构建完成后,将在下面创建一个名为 libs 的文件夹

      c:/mupdf-1.3-source/platform/android
      
  6. 创建安卓apk。打开eclipse,从现有代码创建一个新的android项目,浏览到c:/mupdf-1.3-source/platform/android,现在你可以创建一个mupdf apk。

回答by pkzip

Starting with Android 5.0 you can also use Android's internal PDF rendererand for manipulating PDF you can always use iTextg- just some alternatives for the future.

从 Android 5.0 开始,您还可以使用 Android 的内部PDF 渲染器,对于处理 PDF,您始终可以使用iTextg- 只是未来的一些替代方案。