Search code examples
androidmupdf

How to add geometry annotations to PDF files using MuPDF


I'm developing an app for Android that needs to work extensively with PDF files, and mupdf http://www.mupdf.com/ proved to work well with this task. I was also able to modify the Java and C source files to accept different color "Ink Annotations" and different line thickness. (The code version 1.6 downloaded from the website only allows for red colored ink annotations with a fixed line width).

Now I want to add geometry annotations such as rectangles and circles and lines. Both the Java and C code files have "Annotation Types" that correspond to these annotations, but I can't figure out which functions to call nor what exactly needs to be added to do this.

Is there a way to add this to the current version of muPDF (1.6)? If so, could you please point me in the correct direction?


Solution

  • In pdf-annot-edit.c there are functions such as pdf_set_markup_annot_quadpoints and pdf_set_ink_annot_list. You will need to add equivalent functions for the extra types of annotations that you wish to support.

    Also appearance streams need to be generated for each extra annotation type. For that, look at pdf_update_ink_appearance in pdf-appearance.c. Your functions are likely to be similar, creating a display list for the annotation and then calling pdf_set_annot_appearance.