Script - Leer campos de formulario PDF
Este es un script que muestra cómo leer los campos de un formulario PDF. Documento de ejemplo formtempl.pdf.
import com.lowagie.text.pdf.*;import com.openkm.util.*;import com.openkm.api.*;import org.apache.commons.io.IOUtils;import java.io.InputStream;
OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class);InputStream is = null;
try { // Replace UUID of the document by yours is = okmDocument.getContent(null, "e5a84c26-f8ed-4e7a-8a05-257ea4db3569", false); PdfReader reader = new PdfReader(is); PRAcroForm form = reader.getAcroForm(); AcroFields fields = reader.getAcroFields();
if (form != null) { for (PRAcroForm.FieldInformation field : form.getFields()) { String fieldName = field.getName(); String fieldValue = fields.getField(fieldName); print("Field: " + fieldName + ", Value: " + fieldValue); } }} finally { IOUtils.closeQuietly(is);}