A: I am using QPDFNotesView within qPDF Toolkit to display, annotate and fill PDF forms in Android. Is there a mechanism that allows to be notified when a PDF document has been changed, for instance when a form field has been updated?
A: Yes, this is possible by adding a DocumentListener, see sample code below.
Document events for which you can receive notifications are the following:
ANNOT_REMOVED, ANNOTATION_ADDED, ANNOTATION_MODIFIED, ANNOTATIONS_IMPORTED, ATTACH_ADDED, ATTACH_REMOVED, BOOKMARK_CHANGED, BOOKMARK_CREATED, DOCUMENT_CHANGED, INSERT_LAYER, PAGE_ADDED, PAGE_CONTENT_CHANGED, PAGE_MOVED, PAGE_REMOVED, PAGE_SIZE_CHANGED, PAGEANNOTS_REMOVED, PAGEFIELDS_FLATTENED, WIDGET_UPDATED.
public class MyActivity extends Activity { public QPDFNotesView notes; protected void onCreate(Bundle bundle) { super.onCreate(bundle); notes = new QPDFNotesView(this); notes.setActivity(this); setContentView(notes); notes.addDocumentListener(new DocumentListener() { @Override public void documentOpened() { // When a document is opened, add a listener to listen for changes notes.getDocument().addDocumentListener(new DocumentChangeListener() { // Document Changed Event @Override public void documentChanged(DocumentEvent de) { if (de.getEventType() == DocumentEvent.WIDGET_UPDATED) { // code to do something after the field's value has changed } } }); } @Override public void documentSaved(String previousPath) {} @Override public void zoomChanged(float zoom) {} }); } } |