PDF form field values change color to red after combining with xfdf

After combining pdf with xfdf the form fields text content changes its color to red. Please note that all fields colors are specified as Black in the source form. Form and xfdf files are attached
red color.zip (219.5 KB)

Product Aspose.PDF for Java version 25.5

Code:

    Document sourceDocument = null;

    try (ByteArrayOutputStream buffer = new ByteArrayOutputStream()) {
        sourceDocument = new Document("c:\\test\\form.pdf");

        try (InputStream stream = new BufferedInputStream(new FileInputStream("c:\\test\\data.xfdf"))) {
            XfdfReader.readFields(stream, sourceDocument);
        }

        sourceDocument.flatten();
        sourceDocument.save(buffer);

        return buffer.toByteArray();
    } finally {
        if (sourceDocument != null) {
            sourceDocument.close();
        }
    }

@alex.ray

Cause The issue of form field text changing color to red after merging a PDF with XFDF data is likely due to the default appearance settings of the form fields being overridden during the import process. This can occur if the XFDF file specifies different appearance settings or if the merging process does not retain the original field properties. Solution To resolve this issue, you can explicitly set the text color of the form fields after importing the XFDF data. Here’s how you can do that: 1. Import the XFDF data into the PDF form.
2. Iterate through the form fields and set their text color back to black. Code Here’s a code snippet demonstrating how to achieve this: ```java
import com.aspose.pdf.Document;
import com.aspose.pdf.facades.Form;
import com.aspose.pdf.facades.FormFieldFacade;
import com.aspose.pdf.Color; public byte[] mergePdfWithXfdf(String pdfPath, String xfdfPath) { Document sourceDocument = null; try (ByteArrayOutputStream buffer = new ByteArrayOutputStream()) { sourceDocument = new Document(pdfPath); // Import XFDF data try (InputStream stream = new BufferedInputStream(new FileInputStream(xfdfPath))) { Form form = new Form(sourceDocument); form.importXfdf(stream); } // Set text color of all fields to black for (String fieldName : sourceDocument.getForm().getFieldNames()) { FormFieldFacade field = sourceDocument.getForm().getFieldFacade(fieldName); field.setTextColor(Color.getBlack()); } sourceDocument.flatten(); sourceDocument.save(buffer); return buffer.toByteArray(); } finally { if (sourceDocument != null) { sourceDocument.close(); } }
}

2. If the issue persists, check the XFDF file for any conflicting appearance settings.
3. Consider updating to the latest version of Aspose.PDF for Java, as newer versions may have improvements or bug fixes related to form handling. Please implement the solution and let me know if you need further assistance!

There is no appearance for textbox fields in XFDF file - only values without any attributes except the value.

Also, we cannot change field colors to black because we don’t know if they must be black. It’s defined in the form by the form designer.

Additionally we believe that fields change their color during form flattening, not after the import. Because after importing xfdf and setting the color to black like you suggested - the fields are still red and the only action after that is flattening.

@alex.ray

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFJAVA-45107

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Hello @asad.ali !

Any update on this?

The issue is currently blocking our decision to proceed with purchasing the upgraded Aspose.PDF for Java license.

Thank you!

@alex.ray

We are afraid that the earlier logged ticket could not get resolved due to other pending issues in the queue. However, your concerns have been recorded and we will surely let you know once we make some progress in this regard. We apologize for the inconvenience.