MuPDF Xamarin Android binding on Nuget

MuPDF Xamarin Android nuget package

MuPDF is a small, fast and free PDF library written in portable C, available for Android. You can use this library for its built-in PDF viewer, for rendering PDF pages to images with a high-quality, manipulating PDF files in various ways…

It supports PDF 1.7 with transparency, encryption, hyperlinks, annotations, searching and more. It also reads OpenXPS documents. It does not support interactive features such as form filling and JavaScript.

If you want to use MuPDF in your Xamarin Android application, you can use this MuPDF Xamarin Android Binding nuget package that I made.

Here are the steps I followed to create this nuget package:

  • First, building the native MuPDF library creates a Java project for Eclipse ADT,
  • Secondly, the build of the Android project produces a JAR and four .so files,
  • Finally, I use a Android library project binding for Xamarin Android, which results in a DLL that I wrapped in a nuget package.

The source code of the MuPDF Xamarin Android library is available on GitHub. MuPDF is released under the terms of the Affero GNU General Public License.

Rendering all pages of a PDF file to PNG with the MuPDF Xamarin Android library

Using the MuPDF viewer included in the MuPDF Xamarin Android library

19 thoughts on “MuPDF Xamarin Android binding on Nuget”

  1. Bonjour,
    Tout d’abord je te félicite pour ton travail.

    je débute xamarin lors de mon actuel stage et je dois afficher les documents PDF au sein de mon application en xamarin forms. J’ai vu que ta librairie permettait d’afficher les pdf dans xamarin android mais j’aimerais que tu puisses me guider pour le faire dans du xamarin forms.
    j’utilise pdfjs mais cette librairie est très lente.

    Aussi ça serais bien que tu fasses une liste de toutes les classes et fonctions nécessaires de ta librairie ainsi qu’une petite description.

    je suis sous visual studio 2015 avec la version 2 de xamarin forms.


    1. Pour utiliser la librairie avec Xamarin Forms tu dois passer par des Custom Render.
      Tu peux essayer l’approche où ton Custom Page Renderer pour Android se charge de démarrer l’activity MuPDFActivity:

      Sur le forum il est fait mention d’une autre solution où le code Xamarin.Forms communique avec le code Xamarin.Android via un messenger afin d’ouvrir l’activity:

  2. Hello, mr. Simmon.

    I am using your package of MuPDF for use in Xamarin. But I amfacing a small issue.
    It is overriding my app name in the application management screen. I mean, instead of “My App Name”, it is displaying “MuPDF”.
    How can I pass through this situation?

    Best regards,

    1. Hi Arthur,

      Thanks for using my MuPDF Xamarin Android binding.

      I have to say that the 1.1 package wasn’t perfect, I missed some points when converting the MuPDF Java Android demo app to a library project, and than converting the latter to a Xamarin Android one. I was keeping too much things from the demo’s AndroidManifest.xml such as the app name.

      The issue that you describe is now fixed in version 1.2. Please download it from Nuget.

      Warning: There is a breaking change, the .NET namespace “Com.Artifex.Mupdfdemo” has been renamed “Artifex.MuPdf”.

  3. Hello,

    I am using your nuget package in my Xamarin Android project.

    First of all, thanks for the nuget package. However, it seems the dll is very large and it is increasing my apk size. What steps should I follow to reduce that, if there are any?


    1. Hello Canbek,

      You’re absolutely right. The DLL file size is a lot bigger than in the previous release.

      This is because the size of the native .so files compiled from the MuPDF C source code has increased from MuPDF ~1.7 to 1.9.
      I just found some posts talking about this problem:

      After reading that, I ran some tests:

      – Normal Android NDK release build: 34.7 MB
      – Without Chinese, Japanese, and Korean fonts (-DNOCJK flag): 10.6 MB
      – And without Google Noto fonts (-DTOFU flag, there are fallback fonts): 2.5 MB

      That’s incredible, it’s all about fonts. We now have two .so files:

      – armeavi-v7a: 2.5 MB
      – x86: 4 MB

      In the next release, I will enable these two flags. If some people really need CJK, I think that I will make a second Nuget package.


      1. Thank you, I will keep it at 1.1 version for now, it seems to work ok. I will be waiting for the release without the fonts. Thanks again for the effort.

  4. Hi,
    I’ve been looking for an android pdf viewer for more than a year, finally some hope! I was able to load a normal pdf in MuPDFActivity, but when I tried to open a password protected file, the keyboard show up, than the app crash 🙁 So close… The behavior let me think that only a little part is missing. Did I need to configure something or this part haven’t been ported yet?

    Thanks for your work!

    1. Hi Louis-Philippe,

      Can you provide more information about the android platform and the PDF that you are trying to open?
      I haven’t had the time to test this on a real device yet but I just did it in a new solution with the Android emulator. The password textbox shows up correctly.

      Thank you for your feedback.

  5. Hi,
    I tested with a Asus Nexus 7 second gen running Lollipop and a Samsung Galaxy S2 running Kitkat and they both failed to open my password protected pdf. On the Nexus 7, the keyboard show up, but not and the S2. I can send you the file if you want to try it. I also notice that some of the button also crash the app, like the print button. Is it possible to hide buttons or the entire bar?

    Thanks for the help and have a nice day,

  6. Hi , I am able to view the pdf file using the MUPDF library. But i do not want the edit options menu(underline, copy, edit) that is given in MuPDF. How can i hide that options bar and just view the pdf (only scrolling). Is it possible?
    I do not want edit functionality.
    I am using Xamarin android native application.

    1. Hello Prabina,

      This Xamarin Android library is a port of the original Android library, which does not provide any easy way to disable toolbar buttons or the toolbar itself.
      If you really need to customize this toolbar, I can update the Java library so you could send some flags in the intent as extra data.

      But I won’t be able to do this until the week-end.


      1. Thank you Anthony. That would be a great help.
        My requirement is to view a pdf file into my own activity where i already have action bar and toolbars (at bottom).
        Can we put this pdf viewer into a fragment and add that fragment into our activity?

        1. Hi Prabina, I have created a fragment with the same logic, and I am currently testing it.
          I do not have a lot of experience with Android development in general (I use X.Forms) and maybe it is not the best way to use a fragment, but do you mind if the fragment pulls the pdf filepath from your parent activity ?
          It will be like:

          var uri = Uri.Parse(“/mnt/sdcard/some.pdf”);
          var intent = new Intent(this, typeof (YourFragmentActivity));

          StartActivity(intent); // your fragment activity contains a MuPDFFragment declared in the layout

  7. Hi , I am able to view the pdf file using the MUPDF library. But i want to hide some options menu(underline, copy, edit) that is given in MuPDF and also want to add some options. Even i want to capture image of annotation done on particular page on click of accept button. Is it possible?

    I want to add new functionality of comments also in mupdf.

    I am using Xamarin.Forms and Xamarin.Android application.

Leave a Reply