如何在Android App上实现查看及编辑Pdf文件功能?

By LongLuo

需求

https://mupdf.com/

MuPdf开源编译

https://mupdf.com/docs/android-sdk.html

1
git clone --recursive git://git.ghostscript.com/mupdf-android-fitz.git
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# This is a very simple Makefile that calls 'gradlew' to do the heavy lifting.

default: debug

generate:
if [ -f jni/Makefile ]; then make -C jni generate; fi
debug: generate
./gradlew --warning-mode=all assembleDebug bundleDebug
release: generate
./gradlew --warning-mode=all assembleRelease bundleRelease
install: generate
./gradlew --warning-mode=all installDebug
lint:
./gradlew --warning-mode=all lint
archive: generate
./gradlew --warning-mode=all uploadArchives
sync: archive
rsync -av --chmod=g+w --chown=:gs-priv $(HOME)/MAVEN/com/ ghostscript.com:/var/www/maven.ghostscript.com/com/

run: install
adb shell am start -n com.artifex.mupdf.viewer.app/.LibraryActivity

tarball: release
cp app/build/outputs/apk/release/app-universal-release.apk \
mupdf-$(shell git describe --tags)-android-viewer.apk

clean:
rm -rf .gradle build
rm -rf jni/.cxx jni/.externalNativeBuild jni/.gradle jni/build jni/libmupdf/generated
rm -rf lib/.gradle lib/build
rm -rf app/.gradle app/build
1
make generate

编译libmupdf_java.so

Linux下NDK编译环境配置可以参考之前的文章Linux下Android开发环境搭建指南:

进入~/mupdf-android-viewer/jni/libmupdf/platform/java目录下,ndk-build编译:

1
~/mupdf-android-viewer/jni/libmupdf/platform/java$ndk-build APP_BUILD_SCRIPT=Android.mk APP_PROJECT_DIR=build/android APP_PLATFORM=android-16 APP_OPTIM=release APP_ABI=all

编译中出现下列错误:

1
ft2build.h: No such file or directory

出现上述信息需要安装字体支持软件freetype:

1
sudo apt-get install libfreetype6-dev

编译OK会在目录下生成下列文件:

1
2


https://github.com/longluo/AndroidPdfViewer