package myPack;
import java.io.IOException;
import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
import org.apache.pdfbox.pdmodel.interactive.form.PDField;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
import org.apache.pdfbox.exceptions.COSVisitorException;
import org.apache.pdfbox.examples.AbstractExample;
public class SetField extends AbstractExample
{
public void setField( PDDocument pdfDocument,
String name, String value ) throws IOException
{
PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();
PDAcroForm acroForm = docCatalog.getAcroForm();
PDField field = acroForm.getField( name );
if( field != null )
{
field.setValue( value );
}
else
{
System.err.println( "No field found with name:" + name );
}
public static void main(String[] args) throws IOException, COSVisitorException
{
SetField setter = new SetField();
setter.setField( args );
}
private void setField( String[] args ) throws IOException , COSVisitorException
{
PDDocument pdf = null;
try
{
if( args.length != 3 )
{
usage();
}
else
{
SetField ex = new SetField();
pdf = PDDocument.load( args[0] );
-> ex.setField( pdf, args[1], args[2] );
pdf.save( args[0] );
}
}
finally
{
if( pdf != null )
{
pdf.close();
}
}
}
private static void usage()
{
System.err.println( "usage: org.apache.pdfbox.examples.fdf.SetField <pdf-file> <field-name> <field-value>" );
}
}
Yea...the textbox is a part of acroform...
This is the code i thot wud help me...bt then again theres a problem... the line where i have given an arrow...i dont knw wat to pass as the 2nd argument..
as in the field_name
is there any api using wich i cud list out all the field_names in an acroform..