pymupdf / PyMuPDF

PyMuPDF is a high performance Python library for data extraction, analysis, conversion & manipulation of PDF (and other) documents.
https://pymupdf.readthedocs.io
GNU Affero General Public License v3.0
5.44k stars 511 forks source link

Question : Can PyMuPDF work in Android in a Python App? #665

Closed AxellLim00 closed 4 years ago

AxellLim00 commented 4 years ago

I Tried Building the app into an APK using Buildozer and it was successful, but when I launched the app, it crashed on launch and it reported:

python ImportError: dlopen failed: "/data/data/org.test.ehpaperless/files/app/_python_bundle/site-packages/fitz/_fitz.so" is for EM_X86_64 (62) instead of EM_AARCH64 (183)

So I was wondering if PyMuPDF supports Python for Android or not? since EM_X86_64 means that it requires x86 environment.

If it does, how do I change the .so file so it is runnable on ARM?

JorjMcKie commented 4 years ago

The provided wheels are for x64 architectures only (if not MS Windows). So you must compile PyMuPDF from sources. Needless to mention that MuPDF must also have been generated with this bitness. Other than that, there is no reason why it shouldn't work - there is no restriction inside PyMuPDF as per the Python bitness, and it does run on MS WIndows 32bit.

AxellLim00 commented 4 years ago

Thank you for responding and answering my question. From what I understand, it's that there are no .so files for the ARM architectures, since the wheels built for it are for x64 architectures only?

JorjMcKie commented 4 years ago

since the wheels built for it are for x64 architectures only?

The wheels I am preparing are for Windows 32bit / 64bit, Mac OSX 64bit and Linux 64bit. For Windows, I am using my own machine, for OSX and Linux, I am using the Travis CI services.

FelipeBortolini1 commented 2 years ago

I am getting the same problem, can I use PyMuPDF in android app developed with Kivy nowadays?

domdrag commented 1 year ago

Not fully related, but this might help someone. You might want to check out pdfplumber and/or PyPDF2 packages. I originally wanted to use PyMuPDF for converting PDF to PNG in my Android app and stumbled upon the same issue. Then realized this could also be done with pdfplumber which is a pure python package. My guess would be the packages share a great deal of features. Also quoting from their github page :

pymupdf is substantially faster than pdfminer.six (and thus also pdfplumber) and can generate and modify PDFs, but the library requires installation of non-Python software (MuPDF). It also does not enable easy access to shape objects (rectangles, lines, etc.), and does not provide table-extraction or visual debugging tools.

JorjMcKie commented 1 year ago

Well the comments in pdfplumber are not (no longer) correct:

  1. Vector graphics (what they call "shapes") can be extracted since medieval times - and much faster, more completely and correctly than with pdfminer.
  2. Tables can be located and extracted with the same precision as with pdfplumber and at least 5 times faster.
  3. Those two points also apply to all document types supported by PyMuPDF: XPS; and e-books in EPUB / MOBI / CBZ / FB2 formats.

So remains the question whether there are wheels installable on Android. We are publishing wheels for ARM architectures, @julian-smith-artifex-com - any comment from your side?

julian-smith-artifex-com commented 1 year ago

Sorry, we do not build wheels for Android.

[We do build ARM wheels for 64-bit Linux and 64-bit MacOS.]

If Android wheels are built in the standard Python way with a frontend such as pip that uses PyMuPDF's setup.py script, then it may be possible.

But PyMuPDF needs MuPDF, and the Android build for MuPDF (https://mupdf.readthedocs.io/en/latest/android-library.html) looks like it uses Gradle, so i suspect it might be quite difficult to get everything to build correctly.

Alternatively, https://github.com/kivy/python-for-android looks like it might provide a way to handle things in a more standard Python way, so maybe take a look at it?