import java.io.FileOutputStream;
import java.util.HashMap;
import com.lowagie.text.pdf.AcroFields;
import com.lowagie.text.pdf.PRIndirectReference;
import com.lowagie.text.pdf.PdfDictionary;
import com.lowagie.text.pdf.PdfName;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfStamper;
import com.lowagie.text.pdf.PdfString;
public class MainClass {
public static void main(String[] args) throws Exception {
PdfReader reader = new PdfReader("2.pdf");
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream("3.pdf"));
AcroFields form = stamper.getAcroFields();
HashMap fields = form.getFields();
AcroFields.Item field = (AcroFields.Item) fields.get("PushMe");
PRIndirectReference ref = (PRIndirectReference) field.widget_refs.iterator().next();
PdfDictionary object = (PdfDictionary) reader.getPdfObject(ref.getNumber());
PdfDictionary action = (PdfDictionary) object.get(PdfName.A);
PdfDictionary file = (PdfDictionary) action.get(PdfName.F);
file.put(PdfName.F, new PdfString("http://yourserver/form.jsp"));
stamper.close();
}
}
|