|
Hello,
I am using PDFStamper to fill in the form fields in
a PDF document. However I would like to flatten only filled in
fields.
Here is the code I am using right
now!
// A PDF document that has the
Form defined
// I created a form in the word document
// and converted the word document to
// PDF and saved it InputForm.pdf
String
in_pdf = "InputForm.pdf";
// After filling in the
form I want to save
//
the filled in document as
OutputDoc.pdf
String out_pdf = "OutputDoc.pdf";
// Reference to the reader
instance
PdfReader reader = new PdfReader(in_pdf);
// Get the stamper, so
that you can set field
values
PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(out_pdf));
// Reference to
fields
AcroFields form = stamp.getAcroFields();
// The form has 10 fields that need input
// The field names are Description 01
// through Description 10
form.setField("Description01", "Desc
01");
form.setField("Description03", "Desc 03"); form.setField("Description05", "Desc 05"); form.setField("Description07", "Desc 07"); form.setField("Description09", "Desc 09");
// Flattening the fields
// At this point it is flattening all the fields
// i.e. It is flattening fields named Description01 through Description
10
// But since I filled only Description01, 03, 05, 07, 09
// I should let the user fill rest of the fields
// i.e. fields named Description02, 04, 06, 08, 10
stamp.setFormFlattening(true);
stamp.close(); System.out.println("Done."); The form has 10 fields that need
input. The field names are Description 01 through Description 10.
Using the above code, it is flattening all the
fields i.e. It is flattening
fields named Description01 through Description 10. But since I filled only
Description01, 03, 05, 07, 09 - I should let the user fill rest of the
fields i.e. fields named Description02, 04, 06, 08,
10
Can some one suggest an idea on how to do
this?
Thanks,
Rav |
