Skip to content

Commit cbac413

Browse files
ooxml compiliance java guide
1 parent 818ecc0 commit cbac413

1 file changed

Lines changed: 347 additions & 0 deletions

File tree

Lines changed: 347 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,347 @@
1+
---
2+
id: assembly-basic-usage-ooxml-compliance
3+
url: assembly/java/basic-usage-ooxml-compliance
4+
linktitle: Specify OOXML Compliance
5+
title: Specify OOXML Compliance Level for Word Documents
6+
weight: 19
7+
description: "Control the OOXML compliance level (Ecma, Transitional, or Strict) when saving Word documents to OOXML formats using GroupDocs.Assembly for Java."
8+
keywords: OOXML compliance, OoxmlCompliance, Ecma, Transitional, Strict, DOCX compliance, Word document compliance, ISO/IEC 29500
9+
productName: GroupDocs.Assembly for Java
10+
hideChildren: False
11+
---
12+
13+
## Overview
14+
15+
GroupDocs.Assembly for Java allows you to control the OOXML compliance level when saving Word documents to OOXML formats (DOCX, DOCM, DOTX, DOTM, FlatOpc, etc.). You can explicitly specify the compliance level or let the system automatically preserve the original document's compliance level.
16+
17+
The main classes involved are:
18+
- [LoadSaveOptions](https://reference.groupdocs.com/assembly/java/groupdocs.assembly/loadsaveoptions/) - contains the OoxmlCompliance property
19+
- [DocumentAssembler](https://reference.groupdocs.com/assembly/java/groupdocs.assembly/documentassembler/) - assembles documents with specified compliance
20+
21+
Here are the steps to specify OOXML compliance:
22+
23+
* Create LoadSaveOptions for your output format
24+
* Set the OoxmlCompliance property to the desired compliance level (or leave null for automatic preservation)
25+
* Use DocumentAssembler with the LoadSaveOptions to assemble the document
26+
* The output document will be saved with the specified compliance level
27+
28+
{{< alert style="info" >}}
29+
The OoxmlCompliance property only applies to OOXML formats (DOCX, DOCM, DOTX, DOTM, FlatOpc, etc.) and is ignored for other file formats. When set to null (default), the system automatically preserves the original document's compliance level if it was Transitional, otherwise uses Strict compliance.
30+
{{< /alert >}}
31+
32+
## Available OOXML Compliance Levels
33+
34+
The `OoxmlCompliance` enumeration provides three compliance levels:
35+
36+
- **Ecma**: Specifies ECMA-376 compliance level
37+
- **Transitional**: Specifies ISO/IEC 29500:2008 Transitional compliance level (commonly used for compatibility)
38+
- **Strict**: Specifies ISO/IEC 29500:2008 Strict compliance level (fully compliant with the standard)
39+
40+
## Specify Explicit OOXML Compliance Level
41+
42+
You can explicitly set the OOXML compliance level when assembling a document:
43+
44+
```java
45+
import com.groupdocs.assembly.*;
46+
47+
public static void specifyExplicitCompliance() throws Exception
48+
{
49+
DocumentAssembler assembler = new DocumentAssembler();
50+
51+
// Create LoadSaveOptions with explicit OOXML compliance
52+
LoadSaveOptions options = new LoadSaveOptions(FileFormat.DOCX);
53+
options.setOoxmlCompliance(OoxmlCompliance.STRICT); // or OoxmlCompliance.ECMA, OoxmlCompliance.TRANSITIONAL
54+
55+
// Data object (Java has no anonymous types; use a POJO or Map)
56+
CompanyData data = new CompanyData();
57+
data.setCompanyName("ABC Corp");
58+
data.setYear(2026);
59+
60+
assembler.assembleDocument("Template.docx", "Output.docx", options,
61+
new DataSourceInfo(data, "company"));
62+
}
63+
64+
// Simple POJO for the data source (getters required for assembly engine)
65+
static class CompanyData
66+
{
67+
private String companyName;
68+
private int year;
69+
70+
public String getCompanyName() { return companyName; }
71+
public void setCompanyName(String value) { this.companyName = value; }
72+
public int getYear() { return year; }
73+
public void setYear(int value) { this.year = value; }
74+
}
75+
```
76+
77+
## Use Transitional Compliance
78+
79+
For maximum compatibility with older Office versions, use Transitional compliance:
80+
81+
```java
82+
import com.groupdocs.assembly;
83+
84+
public static void useTransitionalCompliance() throws Exception
85+
{
86+
DocumentAssembler assembler = new DocumentAssembler();
87+
88+
LoadSaveOptions options = new LoadSaveOptions(FileFormat.DOCX);
89+
options.setOoxmlCompliance(OoxmlCompliance.TRANSITIONAL);
90+
91+
OrderData data = new OrderData();
92+
data.setCustomerName("John Doe");
93+
data.setOrderNumber("ORD-12345");
94+
95+
assembler.assembleDocument("Template.docx", "Output.docx", options,
96+
new DataSourceInfo(data, "order"));
97+
}
98+
99+
// POJO for the data source
100+
static class OrderData
101+
{
102+
private String customerName;
103+
private String orderNumber;
104+
105+
public String getCustomerName() { return customerName; }
106+
public void setCustomerName(String value) { this.customerName = value; }
107+
public String getOrderNumber() { return orderNumber; }
108+
public void setOrderNumber(String value) { this.orderNumber = value; }
109+
}
110+
```
111+
112+
## Use Ecma Compliance
113+
114+
For ECMA-376 standard compliance:
115+
116+
```java
117+
import com.groupdocs.assembly.*;
118+
119+
public static void useEcmaCompliance() throws Exception
120+
{
121+
DocumentAssembler assembler = new DocumentAssembler();
122+
123+
LoadSaveOptions options = new LoadSaveOptions(FileFormat.DOCX);
124+
options.setOoxmlCompliance(OoxmlCompliance.ECMA);
125+
126+
ReportData data = new ReportData();
127+
data.setReportTitle("Monthly Report");
128+
data.setMonth("January 2026");
129+
130+
assembler.assembleDocument("Template.docx", "Output.docx", options,
131+
new DataSourceInfo(data, "report"));
132+
}
133+
134+
// POJO for the data source
135+
static class ReportData
136+
{
137+
private String reportTitle;
138+
private String month;
139+
140+
public String getReportTitle() { return reportTitle; }
141+
public void setReportTitle(String value) { this.reportTitle = value; }
142+
public String getMonth() { return month; }
143+
public void setMonth(String value) { this.month = value; }
144+
}
145+
```
146+
147+
## Automatic Preservation of Original Compliance
148+
149+
When `OoxmlCompliance` is not explicitly set (default `null`), the system automatically preserves the original document's compliance level if it was Transitional:
150+
151+
```java
152+
import com.groupdocs.assembly.*;
153+
154+
public static void preserveOriginalCompliance() throws Exception
155+
{
156+
DocumentAssembler assembler = new DocumentAssembler();
157+
158+
// OoxmlCompliance is null by default - original compliance will be preserved
159+
LoadSaveOptions options = new LoadSaveOptions(FileFormat.DOCX);
160+
// options.getOoxmlCompliance() is null - automatic preservation
161+
162+
DocumentData data = new DocumentData();
163+
data.setTitle("Document Title");
164+
data.setContent("Document content");
165+
166+
// Output document will maintain Transitional compliance from template if it was Transitional
167+
assembler.assembleDocument("Template_Transitional.docx", "Output.docx", options,
168+
new DataSourceInfo(data, "document"));
169+
}
170+
171+
// POJO for the data source
172+
static class DocumentData
173+
{
174+
private String title;
175+
private String content;
176+
177+
public String getTitle() { return title; }
178+
public void setTitle(String value) { this.title = value; }
179+
public String getContent() { return content; }
180+
public void setContent(String value) { this.content = value; }
181+
}
182+
```
183+
184+
## Using with Different OOXML Formats
185+
186+
The OoxmlCompliance property works with all OOXML formats:
187+
188+
```java
189+
import com.groupdocs.assembly.*;
190+
191+
public static void useWithDifferentFormats() throws Exception
192+
{
193+
DocumentAssembler assembler = new DocumentAssembler();
194+
195+
ItemData data = new ItemData();
196+
data.setName("Test Document");
197+
data.setValue(100);
198+
199+
// DOCX format
200+
LoadSaveOptions docxOptions = new LoadSaveOptions(FileFormat.DOCX);
201+
docxOptions.setOoxmlCompliance(OoxmlCompliance.STRICT);
202+
assembler.assembleDocument("Template.docx", "Output.docx", docxOptions,
203+
new DataSourceInfo(data, "item"));
204+
205+
// DOCM format (macro-enabled)
206+
LoadSaveOptions docmOptions = new LoadSaveOptions(FileFormat.DOCM);
207+
docmOptions.setOoxmlCompliance(OoxmlCompliance.TRANSITIONAL);
208+
assembler.assembleDocument("Template.docm", "Output.docm", docmOptions,
209+
new DataSourceInfo(data, "item"));
210+
211+
// DOTX format (template)
212+
LoadSaveOptions dotxOptions = new LoadSaveOptions(FileFormat.DOTX);
213+
dotxOptions.setOoxmlCompliance(OoxmlCompliance.STRICT);
214+
assembler.assembleDocument("Template.dotx", "Output.dotx", dotxOptions,
215+
new DataSourceInfo(data, "item"));
216+
}
217+
218+
// POJO for the data source
219+
static class ItemData
220+
{
221+
private String name;
222+
private int value;
223+
224+
public String getName() { return name; }
225+
public void setName(String value) { this.name = value; }
226+
public int getValue() { return value; }
227+
public void setValue(int value) { this.value = value; }
228+
}
229+
```
230+
231+
## Using with Streams
232+
233+
You can also specify OOXML compliance when working with streams:
234+
235+
```java
236+
import com.groupdocs.assembly.*;
237+
import java.io.*;
238+
239+
public static void useComplianceWithStreams() throws Exception
240+
{
241+
DocumentAssembler assembler = new DocumentAssembler();
242+
243+
LoadSaveOptions options = new LoadSaveOptions(FileFormat.DOCX);
244+
options.setOoxmlCompliance(OoxmlCompliance.STRICT);
245+
246+
CompanyData data = new CompanyData();
247+
data.setCompany("My Company");
248+
data.setYear(2024);
249+
250+
try (InputStream templateStream = new FileInputStream("Template.docx");
251+
OutputStream outputStream = new FileOutputStream("Output.docx"))
252+
{
253+
assembler.assembleDocument(templateStream, outputStream, options,
254+
new DataSourceInfo(data, "company"));
255+
}
256+
}
257+
258+
// POJO for the data source
259+
static class CompanyData
260+
{
261+
private String company;
262+
private int year;
263+
264+
public String getCompany() { return company; }
265+
public void setCompany(String value) { this.company = value; }
266+
public int getYear() { return year; }
267+
public void setYear(int value) { this.year = value; }
268+
}
269+
```
270+
271+
## Compliance Level Behavior
272+
273+
Understanding how compliance levels work:
274+
275+
- **When explicitly set**: The specified compliance level is used when saving to OOXML formats
276+
- **When null (default)**:
277+
- If the original document had Transitional compliance, it is preserved
278+
- Otherwise, Strict compliance is used
279+
- **For non-OOXML formats**: The property is ignored (e.g., PDF, HTML, RTF)
280+
281+
```java
282+
import com.groupdocs.assembly.*;
283+
284+
public static void demonstrateComplianceBehavior() throws Exception
285+
{
286+
DocumentAssembler assembler = new DocumentAssembler();
287+
288+
DocData data = new DocData();
289+
data.setTitle("Test");
290+
data.setContent("Content");
291+
292+
// Explicit Strict compliance
293+
LoadSaveOptions strictOptions = new LoadSaveOptions(FileFormat.DOCX);
294+
strictOptions.setOoxmlCompliance(OoxmlCompliance.STRICT);
295+
assembler.assembleDocument("Template.docx", "Output_Strict.docx", strictOptions,
296+
new DataSourceInfo(data, "doc"));
297+
298+
// Automatic preservation (null)
299+
LoadSaveOptions autoOptions = new LoadSaveOptions(FileFormat.DOCX);
300+
// autoOptions.getOoxmlCompliance() is null - will preserve if Transitional
301+
assembler.assembleDocument("Template.docx", "Output_Auto.docx", autoOptions,
302+
new DataSourceInfo(data, "doc"));
303+
304+
// Note: For PDF output, OoxmlCompliance is ignored
305+
LoadSaveOptions pdfOptions = new LoadSaveOptions(FileFormat.PDF);
306+
pdfOptions.setOoxmlCompliance(OoxmlCompliance.STRICT); // Ignored for PDF
307+
assembler.assembleDocument("Template.docx", "Output.pdf", pdfOptions,
308+
new DataSourceInfo(data, "doc"));
309+
}
310+
311+
// POJO for the data source
312+
static class DocData
313+
{
314+
private String title;
315+
private String content;
316+
317+
public String getTitle() { return title; }
318+
public void setTitle(String value) { this.title = value; }
319+
public String getContent() { return content; }
320+
public void setContent(String value) { this.content = value; }
321+
}
322+
```
323+
324+
{{< alert style="warning" >}}
325+
The OoxmlCompliance property only affects OOXML formats. When saving to other formats like PDF, HTML, or RTF, this property is ignored. The compliance level is determined by the output format, not the template format.
326+
{{< /alert >}}
327+
328+
### Advanced Usage Topics
329+
330+
To learn more about format-specific options, document conversion settings, and advanced compliance handling, please refer to the [advanced usage section]({{< ref "assembly/java/developer-guide/advanced-usage/_index.md" >}}).
331+
332+
## More resources
333+
334+
### GitHub Examples
335+
336+
You may easily run the code above and see the feature in action in our GitHub examples:
337+
338+
* [GroupDocs.Assembly for Java examples, plugins, and showcase](https://github.com/groupdocs-assembly/GroupDocs.Assembly-for-Java)
339+
* [GroupDocs.Assembly for .NET examples, plugins, and showcase](https://github.com/groupdocs-assembly/GroupDocs.Assembly-for-.NET)
340+
* [GroupDocs.Assembly for Python via .NET examples, plugins, and showcase](https://github.com/groupdocs-assembly/GroupDocs.Assembly-for-Python-via-.NET)
341+
342+
### Free Online Apps
343+
344+
Along with the full-featured Java library, we provide simple but powerful free online apps.
345+
346+
To assemble documents from templates and data sources, you can use the online apps from the **[GroupDocs.Assembly App Product Family](https://products.groupdocs.app/assembly/family)**.
347+

0 commit comments

Comments
 (0)