How to make annotations like highlighting, strikethrough, underlining, drawing, adding text, etc. In android to view pdf?

  • Many applications, such as RepliGo, Aldiko, Mantano, ezPdf in the Android market, make this kind of annotation in their PDF application, shown in the figure below.
  • I tried in many ways to implement this annotation, but I failed. I have a pdf viewer for Android and a separate java code for annotations using iText to draw lines.
  • My question is: can I implement iText in android. If possible, which package do I need to import?
  • Also, some line drawing applications use the canvas method. Is it possible to enable this canvas method in android instead of using annotation ?. The goal would be to have the same features as annotations.
  • In the image below (RepliGo PDF Reader), what code did they use for annotations? enter image description here
+69
java android pdf pdf-generation pdf-annotations
Feb 06 '12 at 7:11
source share
2 answers

It seems your question is what methods allow users to annotate a PDF file in android / java, so for you this is one of the methods, although this may not be the best solution.

I would like to point out that there is really no need to edit the actual PDF file so that users can add and view annotations. Your application can simply store data for annotations separately, store these annotations for each file and load them when the file is downloaded.

This means that it will not create a new PDF file with annotations placed in it, but instead, it simply saves the user data for each PDF file downloaded into your application and shows when the user downloads the PDF file again. (So ​​it seems to be annotated).

Example:

  • Read PDF text, text formatting and images in your application.
  • Display document (e.g. word processor)
  • Allow user to edit and comment on document
  • Saving changes and annotations in the application (and not in the PDF file)
  • When reloading a file, apply previously saved changes and annotations.

Your annotation class might look something like this:

class Annotations implements Serializable { public Annotations() { annotations = new HashSet<Annotation>(); } public ArrayList<Annotation> getAnnotations() { return new ArrayList<Annotation>(annotations); } public Annotation annotate(int starpos, int endpos) { Annotation a = new Annotation(startpos, endpos); annotations.add(a); return a; } public void unannotate(Annotation a) { annotations.remove(a); } static enum AnnotationTypes { HIGHLIGHT, UNDERLINE; } class Annotation { int startPos, endPos; AnnotationTypes type; Color color; Annotation(int start, int end) { startPos = start; endPos = end; } public void update(int start, int end) { startPos = start; endPos = end; } public void highlight(int red, int green, int blue) { type = AnnotationTypes.HIGHLIGHT; color = new Color(red, green, blue); } public void underline(int red, int green, int blue) { type = AnnotationTypes.UNDERLINE; color = new Color(red, green, blue); } // getters ... } private Set<Annotation> annotations; } 

So, you just save the data for displaying annotations here, and when you upload the file and its corresponding (serialized) Annotations object, you can use each annotation to influence the display of characters between startPos and endPos in your document.

Although I used int for the two positions startPos and endPos , you could also use two or more variables to refer to array indexes, SQLite database table indexes, char positions for simple text documents; regardless of your implementation, you can simply change this so that you know where to start annotating and where to end annotation with this AnnotationType object.

In addition, you can configure property change listeners to trigger methods to update your display / view when changing annotation properties.

+6
May 05 '12 at 16:31
source share

A pdf annotation is open source and a good point to start with https://code.google.com/p/pdf-annotation/

0
Jan 29 '14 at 8:00
source share



All Articles