Hi,
Should also note the XML data will be coming from a String and not a file.
Hi Steve,
Hi Steve,
You may also try using the following code to fill data inside XFA form fields.
C#
FileStream fs = new FileStream(@"D:\pdftest\OrderReceived.pdf", FileMode.Open, FileAccess.ReadWrite);
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(fs);
// Fill out the Person 1 (Sol-licitant) form fields
pdfDocument.Form.XFA["lblStorePhone"] = 0092;
pdfDocument.Save();
fs.Close();
As originally mentioned, I need to fill the XFA from Java and not C#. So this example does not help me.
Hi Steve,
Please accept my apologies for any confusion caused. The following code snippet can be used to fill data inside a PDF form. You can download the latest Aspose.Pdf for Java 4.2.1 and evaluate our component. For further information, you can check Fill Form Field in a PDF Document.
Java
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import com.aspose.pdf.Document;
public class FillPdfForm {
public static void main(String[] args) {
try {
// Load the PDF document
FileInputStream fs = new FileInputStream("D:/pdftest/OrderReceived.pdf");
Document pdfDocument = new Document(fs);
// Fill out the form field
pdfDocument.getForm().get_Item("lblStorePhone").setValue("0092");
// Save the filled out document
FileOutputStream fos = new FileOutputStream("c:/pdftest/FilledForm.pdf");
pdfDocument.save(fos);
// Close the input and output streams
fs.close();
fos.close();
System.out.println("Form filled and saved successfully.");
} catch (IOException e) {
e.printStackTrace();
}
}
}
Thanks for the Java sample.
Hi Steve,
In order to fill the information inside all the fields, you may consider traversing all the fields and fill the data inside them. Besides this, if the data to be filled inside PDF form is present in XFDF file, you may consider using the following code to import the data inside the Form.
In case the data is saved in XML file, you may consider using form.importXml(..) method.
[Java]
// Assign input and output PDF documents
com.aspose.pdf.facades.Form form = new com.aspose.pdf.facades.Form("c:/pdftest/InputTemplate.pdf", "c:/pdftest/InputTemplate_Form_ImportXml.pdf");
// Select a xml file with contents of the form
String xfdfFile = "c:/pdftest/InputXFDF.xfdf";
// Import the values from the XML to the output PDF form
form.importXfdf(new java.io.FileInputStream(xfdfFile));
// save the output PDF document and release the object
form.save();
[quote user=“codewarior”]
Hi Steve,
issue as PDFNEWNET-33758 in our issue tracking system. We will
further look into the details of this problem and will keep you updated on the
status of correction. Please be patient and spare us little time. We are sorry
for this inconvenience.