(.Net, Aspose.PDF 21.9) Cannot Create or Delete FormFields/Signatures after converting Word doc to PDF

Hello, I’m attempting to take these steps in this order:

1. Using Aspose.Words, I convert a word document into a PDF. This is successful, and preserves the form-fields. I pass this result as a memory stream to step 2.
2. Using Aspose.PDF, I'm iterating through the form-fields on the resulting PDF, looking for any text fields with a field.FullName value containing a specific prefix (e.g. "sig_"). Once found, I delete + re-create the field as a SignatureField.
3. Pass the document back as a memory stream to an API endpoint.

The problem I'm having is that for some reason, the Aspose.PDF action results (meaning, the SignatureFields) are not present on the resulting document. The memorystream grows in size between the Aspose.Word return and the Aspose.PDF return, so something is happening to it, but no actual fields are removed or created despite my best efforts. I'm also not receiving any exceptions. 


Here's my code:

//This is the Aspose.Words call, seems to work fine
public Stream convertToPDFWithFormFields(Stream pdfHolderStream)
{
System.IO.Stream returnStream = new MemoryStream();

                try
                {
                    Aspose.Words.Saving.PdfSaveOptions options = new 
                    Aspose.Words.Saving.PdfSaveOptions();
                    options.PreserveFormFields = true;
                    //Aspose.Words.LoadOptions lOptions = new Aspose.Words.LoadOptions();
                    Aspose.Words.Document docxDoc = new 
                     Aspose.Words.Document(pdfHolderStream);
                    
                    docxDoc.Save(returnStream, options);
                    convertPDFFormFieldToSignatureField(returnStream);


                }
                catch (Exception ex)
                {

                }


                return returnStream;

            }

//This is my Aspose.PDF code example:
public Stream convertPDFFormFieldToSignatureField(Stream pdfHolderStream)
{
System.IO.Stream returnStream = new MemoryStream();

            try
            {
                Aspose.Pdf.Document pdf = new Aspose.Pdf.Document(pdfHolderStream);

               
                //Iterate through the form fields in the PDF and convert them to signable signature fields
                foreach(Field field in pdf.Form.Fields)
                {
                    if(field.FullName.Contains("sig_"))
                    {
                        // copy over attributes
                        int pageIndex = field.PageIndex;
                        // Delete the original Text field from the document
                        pdf.Form.Delete(field);
                        SignatureField signatureField = new SignatureField(pdf.Pages[pageIndex], 
                        field.GetRectangle(false));
                        
                        signatureField.PartialName = field.Name;

                        // Add a new Signature field to document
                        pdf.Form.Add(signatureField, pageIndex);


                    }

                }
                pdf.Save(returnStream);
            }
            catch (Exception ex)
            {

            }


            return returnStream;

}

Is there perhaps some conflict or .option flag I'm missing in the Aspose.Word call that is preventing me from editing the resulting PDF at runtime?

@CanadaLifeImaging

Can you please share your sample source Word document with us? We will test the scenario in our environment and address it accordingly.

Sure, here’s a test document I’ve tried to upload via dropping the file into the reply box here:

Test doc.docx (803.6 KB)

Please keep in mind that the form fields at the bottom on page 5 are supposed to be turned into two signature fields, with the rest being normal text formfields. Let me know if you need anything else.

@CanadaLifeImaging

We used Aspose.PDF for .NET 21.9 and your code snippet to test the scenario in our environment. We were unable to notice any issue. For your kind reference, attached is the sample output PDF obtained at our end. Would you please try using the latest version of the API and let us know in case you still face any issue?

pdf_mod.pdf (111.8 KB)

Hey @asad.ali, thanks for confirming that. Your PDF did actually work in our process, which is great, but is also very confusing if you used the same code I provided. We’re very confused as to how our .Net code could somehow executing differently for you than it is for us. Just to confirm we’re on the same version, we are actually using .Net 21.9 Aspose.Word and Aspose.PDF libraries with the associated licenses as well.

Did you use exactly the code that I provided or did you have to make adjustments? If you did make adjustments, would it be possible for you to provide us with that code to compare?

@CanadaLifeImaging

We used the same code snippet which you have shared with us. We also used 21.9 version of the APIs. Only difference was that we saved the document to a physical path instead of memory stream. Can you please try using the physical path to save output PDF and let us know if it makes any difference at your side?

Found the issue, though I’m not sure how it worked for you guys. Turns out that chained call to the PDF signature conversion method here:

Was not actually passing back the correct memory stream, as it appeared to be returning the same one that was provided to it as a param despite calling the .Save() method. I removed the chaining and made sure to explicitly call and pass back each return to make the handling more clear and that ended up fixing it.

@CanadaLifeImaging

It is nice to hear that you have sorted your issue out. As shared earlier, we tested the file using file paths instead of streams which was why the issue was not replicated at our end. Please keep using our API and feel free to create a new topic in case you need any kind of assistance.