Unable to Import Xfdf with Aspose.PDF


#1

Hi,
We are currently evaluating Aspose.PDF for implementation. We have PDF forms created in Adobe experience manager. Our approach is to generate a XFDF and attach it to new forms. The form has some dynamic fields. (Clicking a button will add new row.). During our trial we could see ImportXfdf method not importing any data into PDF.

We filled the PDF first, extract the data as XFDF and attach the XFDF with new empty forms.

Script to generate the XFDF:
public static void GenertateXFDF()
{
Aspose.Pdf.Facades.Form form_test = new Aspose.Pdf.Facades.Form();
form_test.BindPdf(@"\FillXFAFields_OwnVersion.pdf");
FileStream fs = new FileStream(@"\FillXFAFields_export.xfdf", FileMode.Create, FileAccess.Write);
form_test.ExtractXfaData(fs);
fs.Close();
}

Script to Apply the XFDF to new File:
public static void BindXFDF2PDF()
{
const string SOURCE_XFDF_PATH = @"\FillXFAFields_export.xfdf";
const string SORUCE_PDF_PATH = @"\FillXFAFields.pdf";
const string DESTINATION_PDF_PATH = @"\Final_Filled_Output.pdf";
Aspose.Pdf.Facades.Form form_1 = new Facades.Form(SORUCE_PDF_PATH, DESTINATION_PDF_PATH);
System.IO.FileStream xmlInputStream = new FileStream(SOURCE_XFDF_PATH, FileMode.Open);
byte[] buff = new byte[xmlInputStream.Length];
xmlInputStream.Read(buff, 0, (int)xmlInputStream.Length);
MemoryStream ms = new MemoryStream(buff);
form_1.ImportXfdf(ms);
form_1.Save();
}

We used the sample file FillXFAFields.pdf (available in aspose github) for our trial. Let me know if you need more details.

Thanks & Regards,
Mohamed Dhameem


#2

@mohameddhameem

Would you kindly make sure that you are using a valid license while testing the scenario. In case you do not have one, please consider applying for 30-days temporary license over our website. If you still face any issue, please feel free to let us know.


#3

@asad.ali

Thanks for the quick reply. we have attached 30-days temporary license. but still the problem persist. the generated output pdf is empty. Please let us know if you need the original PDF with xfdf files and code.

Regards,
Mohamed Dhameem


#4

@mohameddhameem

Yes, please share the sample PDF document with us which you are using at your end. We will test the scenario in our environment and address it accordingly.


#5

@asad.ali

Please find attached files used for the testing. CSharp.zip (1.7 KB)
FillablePDF.zip (281.5 KB)

Kindly let us know if you need more information.

Thanks & Regards,
Mohamed Dhameem


#6

@mohameddhameem

The sample XFDF file is XML based and you need to use ImportXml() method in order to fill the fields. Please use following code snippet in order to achieve correct output:

Aspose.Pdf.Facades.Form form_1 = new Facades.Form();
form_1.BindPdf(dataDir + "FillXFAFields_OwnVersion.pdf");
form_1.ImportXml(new FileStream(dataDir + "FillXFAFields_export.xfdf", FileMode.Open));
form_1.Save(dataDir + "outputfilled.pdf");

In case you still face any issue, please feel free to let us know.