PDF.Java: how to clone a template

As we have to convert milions of XFA and XFDF files into a PDF output, I thought it would be a good idea to load the corresponding PDF template once, clone it in memory, load the current XFDF and save the output to enhance performance. I tried this:

    com.aspose.pdf.facades.Form form = new Form(TemplateName);

	com.aspose.pdf.facades.Form[] f = new com.aspose.pdf.facades.Form[9];
	
	for (i=0;i<10;i++) {
		
		f[i] = SerializationUtils.clone(form);

However, I’ve got a compile error saying that

error: no suitable method found for clone(Form)
f[i] = SerializationUtils.clone(form);
^
method Object.clone() is not applicable
(actual and formal argument lists differ in length)
method SerializationUtils.clone(Serializable) is not applicable
(argument mismatch; Form cannot be converted to Serializable)

My question is: can I achieve my goal by other means?

@BurkLau

Thanks for contacting support.

The issue you are facing needs further investigation and for the purpose, we may need sample input file(s) from you. Could you please provide us with them so that we can test the scenario in our environment and address it accordingly.

Begeleidingsformulier_v21.zip (39.8 KB)

Please find the pdf template and two xfdf files attached.

@BurkLau

Thanks for sharing requested files.

We have tested the scenario in our environment and noticed that once a document is saved, API disposes it and it becomes no longer available for use. We tried using FileInputStream as well as loading Document into com.aspose.pdf.facades.Form object but, we did not get much success. Please check following code snippet which we have tried:

try {
    Document doc = new Document(dataDir + "Begeleidingsformulier_v21.pdf");
    com.aspose.pdf.facades.Form form = new com.aspose.pdf.facades.Form(fs);
    form.importXfdf(new FileInputStream(dataDir + "Begeleidingsformulier_v21.pdfS_CONTACT_ATT_1-5YB1LFH_1-EB4FXB_011063907.xfdf"));
    form.save(dataDir + "imported1.pdf");
    form = new com.aspose.pdf.facades.Form(fs);
    form.importXfdf(new FileInputStream(dataDir + "Begeleidingsformulier_v21.pdfS_CONTACT_ATT_1-5YB1LFH_1-EB4FXB_011063908.xfdf"));
    form.save(dataDir + "imported2.pdf");
}catch (Exception ex)
{
 ex.printStackTrace();
}

However, we have logged an investigation ticket as PDFJAVA-38578 to investigate the feasibility if a PDF template can be reused without re-initializing it. As soon as we have some definite updates against our investigation, we will let you know. Please be patient and spare us little time.

We are sorry for the inconvenience.