MuPDF 开源PDF库编译过程记录

2024-02-26 11:08

本文主要是介绍MuPDF 开源PDF库编译过程记录,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

最近工作中需要开发一个PDF阅读的功能,开始选择了Android-pdfview开源组件,但是有些PDF文件打开会crash,这个开源组件没有提供jni代码,只能在java层进行捕获,还是无法解决打不开某些pdf文件的问题;只能另寻他家;在网上转了一圈,貌似可行的开源库有pdfbox,iText和MuPDF;最终选择MuPDF做尝试;从github找到了一个demo,运行了一下,前面打不开的pdf文件,使用该库可以代码,并且该库的加载速度和流畅性都由于前者;特意观察了一下内存,发现并没有耗内存的情况,可以放心尝试了;

抱着学习的态度,暂时不选择直接使用这个demo,尝试从MuPDF官网下载原代码自己编译(对NDK这块我还是比较生疏的,只写过一些简单的库);

下面主要记录一下MuPDF源代码编译过程以及遇到的问题和解决办法;

先贴出官网编译指导:

Set up an Android build environment

Download and install the Android SDK. Run the android tool to install the platform tools. Add the tools and platform-tools directories inside the SDK directory to your PATH.

Download and install the Android NDK (r6 or later). Use the 32-bit target NDK if targeting a 32-bit platform! Add the NDK directory to your PATH.

Make sure you have both JDK and ANT installed.

You will also need git and a regular development environment (gcc and gnu make).

Prepare the source

Check out a copy of the mupdf source from git:

~/src $ git clone git://git.ghostscript.com/mupdf.git

Check out the third party library submodules:

~/src/mupdf $ git submodule update --init

Populate the generated directory with the necessary files:

~/src/mupdf $ make generate

Build and debug

Change into the platform/android/viewer directory and edit the local properties configuration file.

~/src/mupdf $ cd platform/android/viewer
~/src/mupdf/platform/android/viewer $ cp local.properties.sample local.properties
~/src/mupdf/platform/android/viewer $ nano local.properties

Build the native code libraries:

~/src/mupdf/platform/android/viewer $ ndk-build

Build the java application:

~/src/mupdf/platform/android/viewer $ ant debug

Install the app on the device or emulator:

~/src/mupdf/platform/android/viewer $ ant debug install

Copy some files onto the device for the app to read:

~/src/mupdf/platform/android/viewer $ adb push .../file.pdf /mnt/sdcard/Download/file.pdf

To see debug messages from the emulator:

~/src/mupdf/platform/android/viewer $ adb logcat

Good luck!


基本的编译流程就是按官网指导来,但是也有一些需要特意说明的地方;

1、我是在windows上编译的,所以必须安装cygwin,选择“devel”和“shells”进行安装(gcc and gnu make);因为只有安装了cygwin,才能执行make命令;

2,在执行ndk-build时遇到了问题,报错了;参考http://www.gezila.com/tutorials/11080.html文章,但是还是报错;最终的解决办法:

首先,修改local.properties文件内容为

sdk.dir=C:\\Documents and Settings\\Administrator\\android-sdks\\platforms\\android-10

   ndk.dir=C:\\android-ndk-r8b

   分别是android sdk 路径和ndk 路径;

再就是看mupdf\platform\android\viewer\jni下的Application.mk文件最下面的内容:

# If the ndk is r8b then workaround bug by uncommenting the following line
#NDK_TOOLCHAIN_VERSION=4.4.3
# If the ndk is newer than r8c, try using clang.
#NDK_TOOLCHAIN_VERSION=clang3.1

对照自己的ndk版本,选择放开哪一行代码,但不是必须的;

我的ndk版本是r10e,所以一开始选择放开NDK_TOOLCHAIN_VERSION=clang3.1,但是不行报错了,如下:

$ ndk-build
Android NDK: WARNING:jni/Android.mk:mupdfcore: LOCAL_LDLIBS is always ignored fo         r static libraries
[armeabi-v7a] Cygwin         : Generating dependency file converter script
[armeabi-v7a] Compile        : mupdf_java <= mupdf.c
/bin/sh: /cygdrive/d/Android/android-ndk-r10e/toolchains/arm-linux-androideabi-c         lang3.1/prebuilt/windows/bin/arm-linux-androideabi-gcc: No such file or director         y
/cygdrive/d/Android/android-ndk-r10e/build/core/build-binary.mk:464: recipe for          target 'obj/local/armeabi-v7a/objs/mupdf_java/mupdf.o' failed
make: *** [obj/local/armeabi-v7a/objs/mupdf_java/mupdf.o] Error 127
对照报错日志看了下我的ndk目录,发现确实没有
android-ndk-r10e/toolchains/arm-linux-androideabi-c         lang3.1/
这个目录,然后就想到Application.mk中放开的那段代码了,就是这段代码指定的这个目录;所以我尝试又把这段代码注释掉,再编译竟然通过了;

如果你也遇到同样的问题,可以尝试我的方法,也可以看下自己toolchains目录下的目录,对照目录尝试修改Application.mk文件中NDK_TOOLCHAIN_VERSION=clang3.1这段代码中指定的clang版本号;


先到这里!

为android平台已编译好的1.8和1.9a版本源代码即demo下载地址:https://github.com/ZhangSir/mupdf-source

这篇关于MuPDF 开源PDF库编译过程记录的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/748652

相关文章

Linux线程同步/互斥过程详解

《Linux线程同步/互斥过程详解》文章讲解多线程并发访问导致竞态条件,需通过互斥锁、原子操作和条件变量实现线程安全与同步,分析死锁条件及避免方法,并介绍RAII封装技术提升资源管理效率... 目录01. 资源共享问题1.1 多线程并发访问1.2 临界区与临界资源1.3 锁的引入02. 多线程案例2.1 为

批量导入txt数据到的redis过程

《批量导入txt数据到的redis过程》用户通过将Redis命令逐行写入txt文件,利用管道模式运行客户端,成功执行批量删除以Product*匹配的Key操作,提高了数据清理效率... 目录批量导入txt数据到Redisjs把redis命令按一条 一行写到txt中管道命令运行redis客户端成功了批量删除k

分布式锁在Spring Boot应用中的实现过程

《分布式锁在SpringBoot应用中的实现过程》文章介绍在SpringBoot中通过自定义Lock注解、LockAspect切面和RedisLockUtils工具类实现分布式锁,确保多实例并发操作... 目录Lock注解LockASPect切面RedisLockUtils工具类总结在现代微服务架构中,分布

Win10安装Maven与环境变量配置过程

《Win10安装Maven与环境变量配置过程》本文介绍Maven的安装与配置方法,涵盖下载、环境变量设置、本地仓库及镜像配置,指导如何在IDEA中正确配置Maven,适用于Java及其他语言项目的构建... 目录Maven 是什么?一、下载二、安装三、配置环境四、验证测试五、配置本地仓库六、配置国内镜像地址

Python实现网格交易策略的过程

《Python实现网格交易策略的过程》本文讲解Python网格交易策略,利用ccxt获取加密货币数据及backtrader回测,通过设定网格节点,低买高卖获利,适合震荡行情,下面跟我一起看看我们的第一... 网格交易是一种经典的量化交易策略,其核心思想是在价格上下预设多个“网格”,当价格触发特定网格时执行买

java中pdf模版填充表单踩坑实战记录(itextPdf、openPdf、pdfbox)

《java中pdf模版填充表单踩坑实战记录(itextPdf、openPdf、pdfbox)》:本文主要介绍java中pdf模版填充表单踩坑的相关资料,OpenPDF、iText、PDFBox是三... 目录准备Pdf模版方法1:itextpdf7填充表单(1)加入依赖(2)代码(3)遇到的问题方法2:pd

Python操作PDF文档的主流库使用指南

《Python操作PDF文档的主流库使用指南》PDF因其跨平台、格式固定的特性成为文档交换的标准,然而,由于其复杂的内部结构,程序化操作PDF一直是个挑战,本文主要为大家整理了Python操作PD... 目录一、 基础操作1.PyPDF2 (及其继任者 pypdf)2.PyMuPDF / fitz3.Fre

python设置环境变量路径实现过程

《python设置环境变量路径实现过程》本文介绍设置Python路径的多种方法:临时设置(Windows用`set`,Linux/macOS用`export`)、永久设置(系统属性或shell配置文件... 目录设置python路径的方法临时设置环境变量(适用于当前会话)永久设置环境变量(Windows系统

python运用requests模拟浏览器发送请求过程

《python运用requests模拟浏览器发送请求过程》模拟浏览器请求可选用requests处理静态内容,selenium应对动态页面,playwright支持高级自动化,设置代理和超时参数,根据需... 目录使用requests库模拟浏览器请求使用selenium自动化浏览器操作使用playwright

Mysql中设计数据表的过程解析

《Mysql中设计数据表的过程解析》数据库约束通过NOTNULL、UNIQUE、DEFAULT、主键和外键等规则保障数据完整性,自动校验数据,减少人工错误,提升数据一致性和业务逻辑严谨性,本文介绍My... 目录1.引言2.NOT NULL——制定某列不可以存储NULL值2.UNIQUE——保证某一列的每一