Attachments not linking to fields in XFA PDF

I’m working on inserting generated XML into an XFA pdf (formatting not controlled by me) and I’m running into an issue. I am able to successfully insert text and have radio buttons selected but cannot figure out how to insert Attachments to they appear in the attachment fields. In the below code I’m creating the FileSpecification for each attachment and inserting it into the EmbeddedFiles property. This successfully added the attachments to the PDF, but they are not linking to the XFA attachment properties. It feels like I’m doing something wrong or missing something, but I can’t figure it out.

I’m on Aspose.PDF version 24.1.0. Attached is a copy of the XML I am using, the “Document for Testing…” files are the attachments I am using (same document renamed), the XFA.pdf file is the XFA PDF I’m trying to insert attachments into, and the Generated.pdf file is the final PDF I’m able to create.

using (MemoryStream memoryStream = new MemoryStream())
{
    Stream finalPdfStream = new MemoryStream();
    string xfaPdfHrn = string.Empty;
    using (var xmlWriter = new StreamWriter(memoryStream))
    {
        xmlWriter.Write(inputXml);
        xmlWriter.Flush();
        Stream inputxmlStream = memoryStream;

        var xfaPdfDocumentStream = /*Load PDF Document Here*/;

        var pdfDocument = new Aspose.Pdf.Document(xfaPdfDocumentStream);
        var form = new Aspose.Pdf.Facades.Form(pdfDocument);

        form.ImportXml(inputxmlStream);

        List<byte[]> attachments = /*Load the attachments*/;
        foreach (var attachment in attachments)
        {
            Stream stream = new MemoryStream(attachment);
            pdfDocument.EmbeddedFiles.Add(new Aspose.Pdf.FileSpecification(stream, attachment));
        }
        form.Save(finalPdfStream);
        var finalPdf = new Aspose.Pdf.Document(finalPdfStream);
        finalPdf.Save(/*Save Location*/);
        form.Dispose();
    }
}

Document for Testing (8).pdf (81.7 KB)
Document for Testing (9).pdf (81.7 KB)
Generated.pdf (304.8 KB)
XFA.pdf (141.8 KB)

Forgot the XML, here it is:

<?xml version="1.0" encoding="utf-8"?>
<xfa:data xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
    <grantwrapper:GrantApplicationWrapper xmlns:grantwrapper="http://apply.grants.gov/system/MetaGrantApplicationWrapper">
        <grant:GrantApplication xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:att="http://apply.grants.gov/system/Attachments-V1.0"
            xmlns:glob="http://apply.grants.gov/system/Global-V1.0"
            xmlns:globlib="http://apply.grants.gov/system/GlobalLibrary-V2.0"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:schemaLocation="http://apply.grants.gov/system/MetaGrantApplication https://trainingapply.grants.gov/apply/opportunities/schemas/applicant/PKG00093166.xsd"
            xmlns:grant="http://apply.grants.gov/system/MetaGrantApplication">
            <grant:Forms>
                <grant:PHS398_ResearchPlan_5_0 xmlns:PHS398_ResearchPlan_5_0="http://apply.grants.gov/forms/PHS398_ResearchPlan_5_0-V5.0"
                    xmlns:xs="http://www.w3.org/2001/XMLSchema"
                    xmlns:codes="http://apply.grants.gov/system/UniversalCodes-V2.0" xsi:schemaLocation="http://apply.grants.gov/forms/PHS398_ResearchPlan_5_0-V5.0 https://trainingapply.grants.gov/apply/forms/schemas/PHS398_ResearchPlan_5_0-V5.0.xsd" PHS398_ResearchPlan_5_0:FormVersion="5.0">
                    <PHS398_ResearchPlan_5_0:ResearchPlanAttachments>
                        <PHS398_ResearchPlan_5_0:SpecificAims>
                            <PHS398_ResearchPlan_5_0:attFile>
                                <att:FileName>Document_for_Testing_(8).pdf</att:FileName>
                                <att:MimeType>application/pdf</att:MimeType>
                                <att:FileLocation att:href="Document_for_Testing_(8).pdf" />
                                <glob:HashValue glob:hashAlgorithm="SHA-1">7MmUzWGHjbVdjbd1CdJyJAPwpIg=</glob:HashValue>
                            </PHS398_ResearchPlan_5_0:attFile>
                        </PHS398_ResearchPlan_5_0:SpecificAims>
                        <PHS398_ResearchPlan_5_0:ResearchStrategy>
                            <PHS398_ResearchPlan_5_0:attFile>
                                <att:FileName>Document_for_Testing_(9).pdf</att:FileName>
                                <att:MimeType>application/pdf</att:MimeType>
                                <att:FileLocation att:href="Document_for_Testing_(9).pdf" />
                                <glob:HashValue glob:hashAlgorithm="SHA-1">7MmUzWGHjbVdjbd1CdJyJAPwpIg=</glob:HashValue>
                            </PHS398_ResearchPlan_5_0:attFile>
                        </PHS398_ResearchPlan_5_0:ResearchStrategy>
                    </PHS398_ResearchPlan_5_0:ResearchPlanAttachments>
                </grant:PHS398_ResearchPlan_5_0>
            </grant:Forms>
        </grant:GrantApplication>
    </grantwrapper:GrantApplicationWrapper>
</xfa:data>

@jon5555

We need to investigate this feature further in details. Hence, an investigation ticket has been logged as PDFNET-57756 in our issue management system. We will further look into its details and keep you posted with the status of its rectification. Please be patient and spare us some time.

We are sorry for the inconvenience.

@asad.ali
Ok. Thank you. Please do let me know if/when you find something.

@jon5555

Sure, we will inform you once we have some updates regarding ticket resolution.