Here is a sample code in Android showing how to launch QPDFNotesView and add a document listener that implements the documentOpened() method, allowing to do something each time a PDF document is open.
In this sample, when a PDF is open and it is an interactive PDF form, all interactive form fields are set to read only. It also outputs field names for fields that are marked as required to the log. This will deactivate the filling of form fields in QPDFNotesView and dialogs will not popup when clicking on form fields. Note that if the document saved, the form fields will be saved with the read-only flag.
package com.qoppa; import android.app.Activity; import android.os.Bundle; import android.util.Log; import java.util.Vector; import com.qoppa.android.pdf.form.FormField; import com.qoppa.notes.QPDFNotesView; import com.qoppa.notes.settings.JavaScriptSettings; import com.qoppa.viewer.listeners.DocumentListener; public class FormFieldActivity 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() { // get acroform Acroform acroform = notes.getDocument().getAcroForm(); if(acroform != null) { // get a vector of all the document fields Vector fields = acroform.getFieldList(); FormField currentField; // loop through all the fields for (int i = 0; i < fields.size(); i++) { currentField =(FormField) fields.get(i); // set the field to read only currentField.setReadOnly(true); // if the field is required, log its name if (currentField.isRequired()) { Log.e("REQUIRED_FIELD", currentField.getFullFieldName()); } } } } @Override public void documentSaved(String previousPath){} @Override public void zoomChanged(float zoom){} }); } } |