Skip to main content

SaveResult Class

Contains form field name conflicts that the API resolved when it saved a PDF document.

Declaration

public class SaveResult extends JavaObject

Remarks

PdfDocument.save methods return a SaveResult object (for example, PdfDocument.save(stream, options)).

If multiple form fields in the document have the same full name, the API can rename the fields before it saves the document. The SaveOptions.setFieldNameConflictResolution(value) method specifies which name conflicts the API resolves. Call the getResolvedFieldNameConflicts() method to get renamed fields.

Refer to the following help topic for additional information: Save PDF Documents.

Example

Rename Form Fields with Duplicate Names on Save

The following code snippet adds two form fields with the same name to a document, saves the document, and displays names of the kept and renamed fields:

import java.io.*;
import java.nio.file.*;
import com.devexpress.docs.pdf.*;
import com.devexpress.system.drawing.*;

public class Main {
    public static void main(String[] args) throws Exception {
        try (PdfDocument document = new PdfDocument()) {
            Page page = document.getPages().add(595, 842);

            // Add two form fields with the same name.
            TextBoxField firstField = new TextBoxField("Name");
            TextBoxField secondField = new TextBoxField("Name");
            document.getFields().add(firstField);
            document.getFields().add(secondField);
            page.getAnnotations().add(new TextBoxWidgetAnnotation(firstField, new RectangleF(50, 700, 150, 20)));
            page.getAnnotations().add(new TextBoxWidgetAnnotation(secondField, new RectangleF(50, 670, 150, 20)));

            SaveOptions options = new SaveOptions();
            options.setFieldNameConflictResolution(FieldNameConflictResolution.RENAME_NEW_CONFLICTS);

            Files.createDirectories(Path.of("output"));
            try (OutputStream stream = Files.newOutputStream(Path.of("output", "Document.pdf"))) {
                SaveResult result = document.save(stream, options);
                for (FormFieldNameConflict conflict : result.getResolvedFieldNameConflicts())
                    System.out.println(conflict.getTargetField().getName() + " -> " + conflict.getRenamedField().getName());
            }
        }
    }
}

Inherited Members

com.devexpress.system.JavaObject.clone()
com.devexpress.system.JavaObject.equals(java.lang.Object)
com.devexpress.system.JavaObject.hashCode()
com.devexpress.system.JavaObject.initFields()
com.devexpress.system.JavaObject.memberwiseClone()
com.devexpress.system.JavaObject.toString()
java.lang.Object.finalize()
java.lang.Object.getClass()
java.lang.Object.notify()
java.lang.Object.notifyAll()
java.lang.Object.wait()
java.lang.Object.wait(long)
java.lang.Object.wait(long,int)

Inheritance

Object
com.devexpress.system.JavaObject
SaveResult

SaveResult(List<FormFieldNameConflict> resolvedFieldNameConflicts)

Initializes a new instance of the SaveResult class with the specified resolved form field name conflicts.

Declaration

public SaveResult(List<FormFieldNameConflict> resolvedFieldNameConflicts)

Parameters

Name Type Description
resolvedFieldNameConflicts java.util.List<FormFieldNameConflict>

Resolved form field name conflicts.

Methods

getResolvedFieldNameConflicts() Method

Returns form field name conflicts that the API resolved when it saved a document.

Declaration

public List<FormFieldNameConflict> getResolvedFieldNameConflicts()

Returns

Type Description
java.util.List<FormFieldNameConflict>

Resolved form field name conflicts. The list is empty if the API did not rename form fields.

Remarks

The SaveOptions.setFieldNameConflictResolution(value) method specifies which name conflicts the API resolves.

Each FormFieldNameConflict object in the list contains the renamed field and the field that keeps the original name. The API replaces each renamed field in the document with a renamed copy. Call the FormFieldNameConflict.getRenamedField() method to get the copy.