1. Windows MuPDF编译
使用如下命令将MuPDF的源码克隆到本地
git clone --recursive git://git.ghostscript.com/mupdf.git
直接用VS,打开 mupdf/platform/win32/mupdf.sln 工程文件,然后编译即可,我这边用的是VS2019 编译的x64的版本,编译中并没有报错。 编译完成后会生成 libmupdf.lib 库文件。
2. Android MuPDF编译
使用如下命令将MuPDF的源码克隆到本地
git clone --recursive git://git.ghostscript.com/mupdf-android-viewer.git
(1) 修改 mupdf-android-viewer/jni/libmupdf/platform/java 路径下的 Android.mk 文件,添加
LOCAL_SHORT_COMMANDS := true
...
LOCAL_LDFLAGS := -Wl,--gc-sections
LOCAL_LDFLAGS += $(MUPDF_EXTRA_LDFLAGS)
LOCAL_SHORT_COMMANDS := true
include $(BUILD_SHARED_LIBRARY)
(2) 修改 mupdf-android-viewer/jni/libmupdf/platform/java 路径下的 Application.mk 文件,添加
APP_SHORT_COMMANDS := true
APP_SHORT_COMMANDS := true
ifdef USE_TESSERACT
APP_STL := c++_static
endif
然后打开 AndroidStudio 直接构建即可,最后会生成 libmupdf_java.so 文件,如果找不到可以用everything找一下,我的生成目录是在 mupdf-android-viewer/app/build/intermediates/merged_native_libs/debug/out/lib 下
3. 引用 MuPDF 库
Qt的.pro文件中增加如下配置,分别添加Windows和Android库的头文件和库文件目录
win32 {
# PDF
INCLUDEPATH += $$PWD/../thirdLibs/MuPDF/win/include
CONFIG(debug, debug|release) {
LIBS += -L$$PWD/../thirdLibs/MuPDF/win/libs/Debug -llibmupdf
}
CONFIG(release, debug|release) {
LIBS += -L$$PWD/../thirdLibs/MuPDF/win/libs/Release -llibmupdf
}
}
android {
INCLUDEPATH += $$PWD/../thirdLibs/MuPDF/android/include
LIBS += -L$$PWD/../thirdLibs/MuPDF/android/libs -lmupdf_java
}
4. 解析本地PDF文件
头文件
#ifndef MUPDFWRAPERCORE_H
#define MUPDFWRAPERCORE_H
#include <QObject>
#include <QImage>
struct fz_context;
struct fz_document;
struct fz_pixmap;
class UTILS_EXPORT MuPDFWraperCore : public QObject
{
Q_OBJECT
public:
MuPDFWraperCore(QObject* parent = nullptr);
~MuPDFWraperCore();