How to control OOXML compliance for WordProcessing documents

Some downstream OOXML tooling supports only specific compliance levels. For example, Docx4j does not read ISO/IEC 29500:2008 Strict output, so consumers that rely on such libraries need the signed document produced in Transitional (or ECMA-376) form instead.

Starting with GroupDocs.Signature for .NET 26.6, the Signature class preserves the OOXML compliance level of the source WordProcessing document on save, and lets you override it through WordProcessingSaveOptions.

How OOXML compliance is handled

  • The source OoxmlCompliance value is detected when the document is loaded and preserved on save by default.
  • WordProcessingSaveOptions exposes a nullable OoxmlCompliance property.
    • null (default) — keep the loaded document’s compliance.
    • set — override the source value with the specified compliance level.
  • Only honoured for OOXML output formats: Docx, Docm, Dotx, Dotm and their FlatOpc variants.

Supported compliance levels

The OoxmlCompliance enum defines the levels you can request on save:

public enum OoxmlCompliance
{
    /// <summary>Specifies ECMA-376 compliance level.</summary>
    Ecma,
    /// <summary>Specifies ISO/IEC 29500:2008 Transitional compliance level.</summary>
    Transitional,
    /// <summary>Specifies ISO/IEC 29500:2008 Strict compliance level.</summary>
    Strict
}

Steps to override OOXML compliance on save

  • Create a new instance of Signature class and pass source document path or stream as a constructor parameter.
  • Instantiate required signature options (for example TextSignOptions).
  • Instantiate WordProcessingSaveOptions and set the OoxmlCompliance property to the required level (Ecma, Transitional, or Strict).
  • Call Sign method of Signature class instance and pass signature options and WordProcessingSaveOptions object to it.

Example — force ISO/IEC 29500:2008 Strict on save

using (Signature signature = new Signature(filePath))
{
    TextSignOptions signOptions = new TextSignOptions("John Smith")
    {
        Left = 100,
        Top = 100,
        Width = 200,
        Height = 60
    };

    // Force ISO 29500:2008 Strict on save regardless of the source's compliance.
    // Other allowed values: OoxmlCompliance.Ecma, OoxmlCompliance.Transitional.
    WordProcessingSaveOptions saveOptions = new WordProcessingSaveOptions(WordProcessingSaveFileFormat.Docx)
    {
        OoxmlCompliance = OoxmlCompliance.Strict
    };

    SignResult result = signature.Sign(outputFilePath, signOptions, saveOptions);
}

Example — save as Transitional for downstream compatibility

Use OoxmlCompliance.Transitional when the consumer of the signed document only reads ISO/IEC 29500:2008 Transitional (or ECMA-376) DOCX — for example when the file will be post-processed by a library that does not support Strict.

using (Signature signature = new Signature(filePath))
{
    TextSignOptions signOptions = new TextSignOptions("John Smith")
    {
        Left = 100,
        Top = 100,
        Width = 200,
        Height = 60
    };

    WordProcessingSaveOptions saveOptions = new WordProcessingSaveOptions(WordProcessingSaveFileFormat.Docx)
    {
        OoxmlCompliance = OoxmlCompliance.Transitional
    };

    signature.Sign(outputFilePath, signOptions, saveOptions);
}

Example — keep the source document’s compliance

Leave OoxmlCompliance unset (or explicitly null) to preserve whatever compliance level the loaded document was authored in.

using (Signature signature = new Signature(filePath))
{
    TextSignOptions signOptions = new TextSignOptions("John Smith")
    {
        Left = 100,
        Top = 100,
        Width = 200,
        Height = 60
    };

    // OoxmlCompliance not set => source compliance is preserved on save.
    WordProcessingSaveOptions saveOptions = new WordProcessingSaveOptions(WordProcessingSaveFileFormat.Docx);

    signature.Sign(outputFilePath, signOptions, saveOptions);
}

More resources

GitHub Examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free Online Apps

Along with the full-featured .NET library, we provide simple but powerful free online apps.

To sign PDF, Word, Excel, PowerPoint, and other documents you can use the online apps from the GroupDocs.Signature App Product Family.

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.