Script - Read PDF form fields

This is a script what demonstrates how to read PDF form fields. Sample document 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);
}

 

 

Table of contents [ Hide Show ]