Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Research MuPdf(一)——Android Open Source Version #230

Open
soapgu opened this issue Nov 17, 2023 · 0 comments
Open

Research MuPdf(一)——Android Open Source Version #230

soapgu opened this issue Nov 17, 2023 · 0 comments
Labels

Comments

@soapgu
Copy link
Owner

soapgu commented Nov 17, 2023

  • 熟悉而又陌生的MuPdf

说起MuPdf,其实这个库曾经听说过并使用过很久了。最早要追溯到我写WPF的时候就用到了。那个时候还是通过DllImport的方式来调用VC的核心库来实现的。由于当时已经有人帮我封装好主要的API了。所以对MuPdf这个库本身来说,还是比较陌生的。算是
图片

  • 从安卓pdf应用角度重新认识MuPdf

事实上MuPdf已经出了AppKit,上次我看了以后发现这是一个闭源的组件,demo给的是水印版本。顿时没了兴致。
说好的开源精神在哪里?节操哪?(还让我怎么白嫖?)

不过这次由于还是要探索一下这个组件的功能,所以重新开始学习下

  • 其实“白嫖”版本还是有的!

上次我浏览MuPdf官网的时候,AppKit被放在很显眼的位置(挣钱嘛不寒颤),我想当然的认为就没有免费版了。
其实你打开MuPdf的Document。
图片
实际上开源的安卓Lib还不只一个,有两个!

  • mupdf-android-viewer

The main viewer app. This code is difficult to work with, but has the most features and pre-renders neighboring pages into a page cache for faster page turning performance.

  • mupdf-android-viewer-mini

This is a minimalist viewer which has fewer features but is designed to be easy to understand and modify. It does not (currently) have high-resolution zooming, and it does not use the swipe gesture to flip pages (it requires the user to tap on the side of the screen to flip pages).

  • mupdf-android-viewer

先从开源部分开始入手,那么选mupdf-android-viewer还是mupdf-android-viewer-mini那?都是老司机了肯定选mupdf-android-viewer啦。

$ git clone git://git.ghostscript.com/mupdf-android-viewer.git

使用Android Studio编译,然而jni并不是“本地”的

dependencies {
	implementation 'androidx.appcompat:appcompat:1.1.+'
	if (file('../jni/build.gradle').isFile())
		api project(':jni')
	else
		api 'com.artifex.mupdf:fitz:1.23.5'
}

需要执行git submodule update --init

  • 具体参考文档 mupdf android viewer README
  • 另外注意这个报错,Unknown host CPU architecture: arm64,需要设置NDK的版本适当高一点,我这里是设置的25.2.9519653,使用默认的ndk-bundle是不行的,会出现找不到platform的报错
图片

这些工作做完后,demo程序就构建完成了!

  • 开源版安卓MuPdf功能梳理

还是从表面入手解析。

  • pdf文档加载
  • pdf浏览(缩放、翻页等,单页模式不支持连续翻页)
  • 目录大纲
  • 内容搜索

其中前面属于基本功能,第三个内容比较有价值,至少在商业项目中有客户提出类似需求

  • 开源版安卓MuPdf项目结构梳理

可以参考官网文档说明Working on the MuPDF Library

图片

还是比较清晰的架构,当然还有一些第三方的类库这里就不画出来了

  • C#相关支持回顾

酸腐一下,孔子曰:
图片

其实WPF这条路走的和安卓有异曲同工之妙
都是需要一个中间件项目来连接,区别在于安卓的纽带是JNI
而WPF用的是dllimport

当然WPF还多走一步,由于C#只能运行VC环境编译的dll才能用。
好在适配这么麻烦的活还是有“活雷锋”的!

图片 更新频率超高,人气不错。专门做mupdf的windows适配,完美
@soapgu soapgu changed the title Research MuPdf Research MuPdf(一) Nov 18, 2023
@soapgu soapgu changed the title Research MuPdf(一) Research MuPdf(一)——Android Open Source Version Nov 20, 2023
@soapgu soapgu added the 安卓 安卓 label Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant