package pdf.test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Map;
import com.itextpdf.text.pdf.AcroFields;
import com.itextpdf.text.pdf.AcroFields.Item;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
public class Pdf {
public static void main(String[] args) throws Exception{
File file = new File("E:\\yan.pdf");
FileInputStream input = new FileInputStream(file);
PdfReader reader = new PdfReader(input);
FileOutputStream output = new FileOutputStream("E:\\test.pdf");
PdfStamper stamper = new PdfStamper(reader, output);
AcroFields form = stamper.getAcroFields();
Map map = form.getFields();
for (String name : map.keySet()) {
try {
form.setField(name, "a");
} catch (Exception e) {
// System.out.println(name);
}
}
if (stamper != null) {
stamper.close();
}
if (reader != null) {
reader.close();
}
if (input != null) {
input.close();
}
if (output != null) {
output.close();
}
}
}