- Many applications like RepliGo, Aldiko, Mantano, ezPdf in android market make this type of annotation in their pdf viewer shown in the below image.
- I tried in many ways to implement this annotation but I failed. I have a pdf viewer for android and separate java code for annotations using iText for drawing lines.
- My question is can i able to implement iText in android. If it's possible, which package do I have to import?
- Also in some applications, a canvas method is used for drawing lines. Is it possible to include this canvas method in android instead of using an annotation?. The goal would be to have the same features that annotations have.
- In the below image (RepliGo PDF Reader) which kind of code did they use for annotations?

- 1,898
- 5
- 19
- 39
-
8@yadab : I just need an idea about annotation, canvas and iText whether it can be used or not. Before commenting or answering first read and try to understand the question. – BobDroid Feb 10 '12 at 06:21
-
1I am calling back my comment. – yadab Feb 16 '12 at 13:47
-
1http://developer.android.com/guide/topics/ui/custom-components.html#custom – zapl Mar 12 '12 at 16:15
-
5There are some commercial pdf SDK like [PDFTRON](http://www.pdftron.com/pdfnet/mobile/android_pdf_library.html) supporting annotation. You can also check open source android projects like: [Android PDF Viewer](http://code.google.com/p/apv/) or [APDFViewer](http://code.google.com/p/apdfviewer/). There are some related questions you might want to check too: [PDF parsing library for Android?](http://stackoverflow.com/questions/3530780/android-is-there-any-free-pdf-library-for-android) [Android : Is there any free PDF library for Android](http://stackoverflow.com/questions/4665957/pdf-parsing-libr – Lenciel Mar 20 '12 at 01:48
-
14This question is unlikely to get any useful answers because of its large scope. You should split it up into smaller, more detailed, and more specific questions. For example, "How can I create a popup window with a call-out..." or "How do I implement drag 'n' drop..." – Roman Nurik Mar 29 '12 at 16:49
-
iText may be overkill, especially for just drawing annotations on top of another PDF viewer. If you can't find an open-source PDF viewer that already does annotation (and I assume you've looked already), then find the simplest open-source PDF viewer that you can then modify to add the features you need, and just use that instead of viewer+iText. – Yusuf X Apr 26 '12 at 08:33
-
PSPDFKit for Android is another commercial solution, fully supporting annotations, forms and even digital signatures: http://pspdfkit.com/android – steipete May 17 '18 at 13:27
2 Answers
Your question seems to be what are methods to allow users to annotate over a PDF file in android/java, so here is one method for you, although it may not be the best solution.
I'd like to point out that it is not actually necessary to edit the actual PDF file just to allow users to add and view annotations. Your application could just store the data for annotations separately, store those annotations for each file, and load them when the file is loaded.
That means it won't create a new PDF file with those annotations placed it, but instead it will just store user-data for each PDF file which is loaded into your app, and display that when the user loads the PDF file again. (So it appears to be annotated).
Example:
- Read PDF file text, text-formatting & images into your app
- Display a document (like a word-processor)
- Allow the user to edit & annotate the document
- Save changes & annotation-data in your app (not the PDF file)
- When loading the file again, apply changes & annotations previously stored.
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're just storing the annotation-display data here, and when you load the file and its respective (serialized) Annotations object, you can use each annotation to affect how you display characters between the startPos
and endPos
in your document.
Although i've used int
s 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; whatever your implementation is you could just change that so that you know where to start annotating and where to end annotating with that AnnotationType.
Also, you could set up property change listeners so that when the annotation properties are changed they fire off methods to update your display/view.

- 8,244
- 7
- 55
- 95
Pdf-annotation is an open source and good point to start with https://code.google.com/p/pdf-annotation/

- 545
- 8
- 15