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();
}
}
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 afraid that the earlier logged ticket could not get resolved due to other pending issues in the queue. Nevertheless, we will surely inform you once we have some news about its fix or ETA. Please spare us some time.