// Stamper is already created
private void ChangeTextFieldOnMasterPage(PdfStamper stamper, String newData )
{
try {
AcroFields form = stamper.getAcroFields();
XfaForm xfaForm = form.getXfa();
// IT MUST BE an XFA FORM!
if( xfaForm !=null && xfaForm.isXfaPresent()){
// Controls of a Master page are copied to all pages. You must find them.
// This is what Master Page does exactly in a PDF file
int numpages = stamper.getReader().getNumberOfPages();
for( int i=0; i<numpages; i++){
// XML tree to your text field on the given page
String strKeyField = "form1[0].#pageSet[0].Page1[" + i + "].MyTextField[0]";
form.setField(strKeyField, newData);
// You can change other properties here
// form.setFieldProperty(strKeyField, "textcolor", BaseColor.GRAY, null);
// form.setFieldProperty(strKeyField, "bgcolor", BaseColor.RED, null);
// form.setFieldProperty(strKeyField, "setfflags", PdfFormField.FF_READ_ONLY, null);
}
xfaForm.setChanged( true );
xfaForm.setXfa( stamper.getWriter() );
}
}
catch (DocumentException de)
{
}
catch (IOException e)
{
}
}
private void ChangeTextFieldOnMasterPage(PdfStamper stamper, String newData )
{
try {
AcroFields form = stamper.getAcroFields();
XfaForm xfaForm = form.getXfa();
// IT MUST BE an XFA FORM!
if( xfaForm !=null && xfaForm.isXfaPresent()){
// Controls of a Master page are copied to all pages. You must find them.
// This is what Master Page does exactly in a PDF file
int numpages = stamper.getReader().getNumberOfPages();
for( int i=0; i<numpages; i++){
// XML tree to your text field on the given page
String strKeyField = "form1[0].#pageSet[0].Page1[" + i + "].MyTextField[0]";
form.setField(strKeyField, newData);
// You can change other properties here
// form.setFieldProperty(strKeyField, "textcolor", BaseColor.GRAY, null);
// form.setFieldProperty(strKeyField, "bgcolor", BaseColor.RED, null);
// form.setFieldProperty(strKeyField, "setfflags", PdfFormField.FF_READ_ONLY, null);
}
xfaForm.setChanged( true );
xfaForm.setXfa( stamper.getWriter() );
}
}
catch (DocumentException de)
{
}
catch (IOException e)
{
}
}
<?xfa generator="AdobeLiveCycleDesignerES_V9.0.0.0.20091029.1.612548" APIVersion="3.1.9277.0"?>
<xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/" timeStamp="2010-07-14T23:19:07Z" uuid="7b2544ce-7914-45ef-8a04-06c61ab070d0">
<template xmlns="http://www.xfa.org/schema/xfa-template/2.8/">
<subform name="form1" layout="tb" locale="en_US">
<pageSet>
<pageArea name="Page1" id="Page1" numbered="0">
<contentArea x="0.25in" y="0.25in" w="203.2mm" h="266.7mm"/>
<medium stock="letter" short="215.9mm" long="279.4mm"/>
<field name="MyTextField" y="273.05mm" x="6.35mm" w="203.2mm" h="5.2331mm">
<ui>
<textEdit/>
</ui>
<font typeface="Myriad Pro">
<fill>
<color value="153,153,153"/>
</fill>
</font>
<margin topInset="0.5mm" bottomInset="0.5mm" leftInset="0.5mm" rightInset="0.5mm"/>
<para hAlign="center"/>
<bind match="global"/>
</field>
</pageArea>
</pageSet>
.................
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
<annots/>
</xfdf></xdp:xdp>