When I tried to run this code I get: unreported exception COSVisitorException;
must be caught or declare to be thrownpdf.Document. save(FilledForm); 1 error.
Do you know why?
package org.apache.pdfbox.examples.acroforms;import java.io.File;
import java.io.IOException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.exceptions.*;
import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;import
org.apache.pdfbox.pdmodel.interactive.form.PDField;
import org.apache.pdfbox.pdmodel.interactive.form.PDTextbox;
public class FillTestField {
public static void main(String[] args) throws IOException { String
formTemplate = "Users/Dad/Desktop/TCRM/game plan 12-16.pdf"; String
filledForm = "Users/Dad/JavaTest/game plan 12-16.pdf"; // load
the document PDDocument pdfDocument = PDDocument
.load(new File(formTemplate),null);
// get the document catalog PDAcroForm acroForm =
pdfDocument.getDocumentCatalog().getAcroForm(); // as there might not be
an AcroForm entry a null check is necessary if (acroForm != null)
{ // Retrieve an individual field and set it's value. PDTextbox
field = (PDTextbox) acroForm.getField( "Goal" );
field.setValue("Text Entry"); // If a field is nested
within the form tree a fully qualified name // might be provided to
access the field. field = (PDTextbox) acroForm.getField(
"fieldsContainer.nestedSampleField" ); field.setValue("Text Entry");
}
// Save and close the filled out form.
pdfDocument.save(filledForm); pdfDocument.close();
}
}