Class OoxmlSaveOptions

Class OoxmlSaveOptions

Namespace: Aspose.Words.Saving
Assembly: Aspose.Words.dll (25.12.0)

Can be used to specify additional options when saving a document into the Aspose.Words.SaveFormat.Docx, Aspose.Words.SaveFormat.Docm, Aspose.Words.SaveFormat.Dotx, Aspose.Words.SaveFormat.Dotm or Aspose.Words.SaveFormat.FlatOpc format.

To learn more, visit the Specify Save Options documentation article.

public class OoxmlSaveOptions : SaveOptions

Inheritance

object SaveOptions OoxmlSaveOptions

Inherited Members

SaveOptions.CreateSaveOptions(SaveFormat) , SaveOptions.CreateSaveOptions(string) , SaveOptions.SaveFormat , SaveOptions.ExportGeneratorName , SaveOptions.TempFolder , SaveOptions.PrettyFormat , SaveOptions.UseAntiAliasing , SaveOptions.UseHighQualityRendering , SaveOptions.DmlRenderingMode , SaveOptions.DmlEffectsRenderingMode , SaveOptions.ImlRenderingMode , SaveOptions.DefaultTemplate , SaveOptions.UpdateFields , SaveOptions.UpdateLastSavedTimeProperty , SaveOptions.UpdateLastPrintedProperty , SaveOptions.UpdateCreatedTimeProperty , SaveOptions.MemoryOptimization , SaveOptions.UpdateAmbiguousTextFont , SaveOptions.Dml3DEffectsRenderingMode , SaveOptions.ProgressCallback , SaveOptions.AllowEmbeddingPostScriptFonts , SaveOptions.CustomTimeZoneInfo , object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()

Examples

Shows how to set an OOXML compliance specification for a saved document to adhere to.

Document doc = new Document();
                                                                                                DocumentBuilder builder = new DocumentBuilder(doc);

                                                                                                // If we configure compatibility options to comply with Microsoft Word 2003,
                                                                                                // inserting an image will define its shape using VML.
                                                                                                doc.CompatibilityOptions.OptimizeFor(MsWordVersion.Word2003);
                                                                                                builder.InsertImage(ImageDir + "Transparent background logo.png");

                                                                                                Assert.That(((Shape)doc.GetChild(NodeType.Shape, 0, true)).MarkupLanguage, Is.EqualTo(ShapeMarkupLanguage.Vml));

                                                                                                // The "ISO/IEC 29500:2008" OOXML standard does not support VML shapes.
                                                                                                // If we set the "Compliance" property of the SaveOptions object to "OoxmlCompliance.Iso29500_2008_Strict",
                                                                                                // any document we save while passing this object will have to follow that standard. 
                                                                                                OoxmlSaveOptions saveOptions = new OoxmlSaveOptions
                                                                                                {
                                                                                                    Compliance = OoxmlCompliance.Iso29500_2008_Strict,
                                                                                                    SaveFormat = SaveFormat.Docx
                                                                                                };

                                                                                                doc.Save(ArtifactsDir + "OoxmlSaveOptions.Iso29500Strict.docx", saveOptions);

                                                                                                // Our saved document defines the shape using DML to adhere to the "ISO/IEC 29500:2008" OOXML standard.
                                                                                                doc = new Document(ArtifactsDir + "OoxmlSaveOptions.Iso29500Strict.docx");

                                                                                                Assert.That(((Shape)doc.GetChild(NodeType.Shape, 0, true)).MarkupLanguage, Is.EqualTo(ShapeMarkupLanguage.Dml));

Constructors

OoxmlSaveOptions()

Initializes a new instance of this class that can be used to save a document in the Aspose.Words.SaveFormat.Docx format.

public OoxmlSaveOptions()

Examples

Shows how to set an OOXML compliance specification for a saved document to adhere to.

Document doc = new Document();
                                                                                                DocumentBuilder builder = new DocumentBuilder(doc);

                                                                                                // If we configure compatibility options to comply with Microsoft Word 2003,
                                                                                                // inserting an image will define its shape using VML.
                                                                                                doc.CompatibilityOptions.OptimizeFor(MsWordVersion.Word2003);
                                                                                                builder.InsertImage(ImageDir + "Transparent background logo.png");

                                                                                                Assert.That(((Shape)doc.GetChild(NodeType.Shape, 0, true)).MarkupLanguage, Is.EqualTo(ShapeMarkupLanguage.Vml));

                                                                                                // The "ISO/IEC 29500:2008" OOXML standard does not support VML shapes.
                                                                                                // If we set the "Compliance" property of the SaveOptions object to "OoxmlCompliance.Iso29500_2008_Strict",
                                                                                                // any document we save while passing this object will have to follow that standard. 
                                                                                                OoxmlSaveOptions saveOptions = new OoxmlSaveOptions
                                                                                                {
                                                                                                    Compliance = OoxmlCompliance.Iso29500_2008_Strict,
                                                                                                    SaveFormat = SaveFormat.Docx
                                                                                                };

                                                                                                doc.Save(ArtifactsDir + "OoxmlSaveOptions.Iso29500Strict.docx", saveOptions);

                                                                                                // Our saved document defines the shape using DML to adhere to the "ISO/IEC 29500:2008" OOXML standard.
                                                                                                doc = new Document(ArtifactsDir + "OoxmlSaveOptions.Iso29500Strict.docx");

                                                                                                Assert.That(((Shape)doc.GetChild(NodeType.Shape, 0, true)).MarkupLanguage, Is.EqualTo(ShapeMarkupLanguage.Dml));

OoxmlSaveOptions(SaveFormat)

Initializes a new instance of this class that can be used to save a document in the Aspose.Words.SaveFormat.Docx, Aspose.Words.SaveFormat.Docm, Aspose.Words.SaveFormat.Dotx, Aspose.Words.SaveFormat.Dotm or Aspose.Words.SaveFormat.FlatOpc format.

public OoxmlSaveOptions(SaveFormat saveFormat)

Parameters

saveFormat SaveFormat

Can be Aspose.Words.SaveFormat.Docx, Aspose.Words.SaveFormat.Docm, Aspose.Words.SaveFormat.Dotx, Aspose.Words.SaveFormat.Dotm or Aspose.Words.SaveFormat.FlatOpc.

Examples

Shows how to support legacy control characters when converting to .docx.

Document doc = new Document(MyDir + "Legacy control character.doc");

                                                                                   // When we save the document to an OOXML format, we can create an OoxmlSaveOptions object
                                                                                   // and then pass it to the document's saving method to modify how we save the document.
                                                                                   // Set the "KeepLegacyControlChars" property to "true" to preserve
                                                                                   // the "ShortDateTime" legacy character while saving.
                                                                                   // Set the "KeepLegacyControlChars" property to "false" to remove
                                                                                   // the "ShortDateTime" legacy character from the output document.
                                                                                   OoxmlSaveOptions so = new OoxmlSaveOptions(SaveFormat.Docx);
                                                                                   so.KeepLegacyControlChars = keepLegacyControlChars;

                                                                                   doc.Save(ArtifactsDir + "OoxmlSaveOptions.KeepLegacyControlChars.docx", so);

                                                                                   doc = new Document(ArtifactsDir + "OoxmlSaveOptions.KeepLegacyControlChars.docx");

                                                                                   Assert.That(doc.FirstSection.Body.GetText(), Is.EqualTo(keepLegacyControlChars ? "\u0013date \\@ \"MM/dd/yyyy\"\u0014\u0015\f" : "\u001e\f"));

Properties

Compliance

Specifies the OOXML version for the output document. The default value is Aspose.Words.Saving.OoxmlCompliance.Ecma376_2006.

public OoxmlCompliance Compliance { get; set; }

Property Value

OoxmlCompliance

Examples

Shows how to insert DML shapes into a document.

Document doc = new Document();
                                                          DocumentBuilder builder = new DocumentBuilder(doc);

                                                          // Below are two wrapping types that shapes may have.
                                                          // 1 -  Floating:
                                                          builder.InsertShape(ShapeType.TopCornersRounded, RelativeHorizontalPosition.Page, 100,
                                                                  RelativeVerticalPosition.Page, 100, 50, 50, WrapType.None);

                                                          // 2 -  Inline:
                                                          builder.InsertShape(ShapeType.DiagonalCornersRounded, 50, 50);

                                                          // If you need to create "non-primitive" shapes, such as SingleCornerSnipped, TopCornersSnipped, DiagonalCornersSnipped,
                                                          // TopCornersOneRoundedOneSnipped, SingleCornerRounded, TopCornersRounded, or DiagonalCornersRounded,
                                                          // then save the document with "Strict" or "Transitional" compliance, which allows saving shape as DML.
                                                          OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(SaveFormat.Docx);
                                                          saveOptions.Compliance = OoxmlCompliance.Iso29500_2008_Transitional;

                                                          doc.Save(ArtifactsDir + "Shape.ShapeInsertion.docx", saveOptions);

Shows how to configure a list to restart numbering at each section.

Document doc = new Document();
                                                                              DocumentBuilder builder = new DocumentBuilder(doc);

                                                                              doc.Lists.Add(ListTemplate.NumberDefault);

                                                                              Aspose.Words.Lists.List docList = doc.Lists[0];
                                                                              docList.IsRestartAtEachSection = restartListAtEachSection;

                                                                              // The "IsRestartAtEachSection" property will only be applicable when
                                                                              // the document's OOXML compliance level is to a standard that is newer than "OoxmlComplianceCore.Ecma376".
                                                                              OoxmlSaveOptions options = new OoxmlSaveOptions
                                                                              {
                                                                                  Compliance = OoxmlCompliance.Iso29500_2008_Transitional
                                                                              };

                                                                              builder.ListFormat.List = docList;

                                                                              builder.Writeln("List item 1");
                                                                              builder.Writeln("List item 2");
                                                                              builder.InsertBreak(BreakType.SectionBreakNewPage);
                                                                              builder.Writeln("List item 3");
                                                                              builder.Writeln("List item 4");

                                                                              doc.Save(ArtifactsDir + "OoxmlSaveOptions.RestartingDocumentList.docx", options);

                                                                              doc = new Document(ArtifactsDir + "OoxmlSaveOptions.RestartingDocumentList.docx");

                                                                              Assert.That(doc.Lists[0].IsRestartAtEachSection, Is.EqualTo(restartListAtEachSection));

Shows how to set an OOXML compliance specification for a saved document to adhere to.

Document doc = new Document();
                                                                                                DocumentBuilder builder = new DocumentBuilder(doc);

                                                                                                // If we configure compatibility options to comply with Microsoft Word 2003,
                                                                                                // inserting an image will define its shape using VML.
                                                                                                doc.CompatibilityOptions.OptimizeFor(MsWordVersion.Word2003);
                                                                                                builder.InsertImage(ImageDir + "Transparent background logo.png");

                                                                                                Assert.That(((Shape)doc.GetChild(NodeType.Shape, 0, true)).MarkupLanguage, Is.EqualTo(ShapeMarkupLanguage.Vml));

                                                                                                // The "ISO/IEC 29500:2008" OOXML standard does not support VML shapes.
                                                                                                // If we set the "Compliance" property of the SaveOptions object to "OoxmlCompliance.Iso29500_2008_Strict",
                                                                                                // any document we save while passing this object will have to follow that standard. 
                                                                                                OoxmlSaveOptions saveOptions = new OoxmlSaveOptions
                                                                                                {
                                                                                                    Compliance = OoxmlCompliance.Iso29500_2008_Strict,
                                                                                                    SaveFormat = SaveFormat.Docx
                                                                                                };

                                                                                                doc.Save(ArtifactsDir + "OoxmlSaveOptions.Iso29500Strict.docx", saveOptions);

                                                                                                // Our saved document defines the shape using DML to adhere to the "ISO/IEC 29500:2008" OOXML standard.
                                                                                                doc = new Document(ArtifactsDir + "OoxmlSaveOptions.Iso29500Strict.docx");

                                                                                                Assert.That(((Shape)doc.GetChild(NodeType.Shape, 0, true)).MarkupLanguage, Is.EqualTo(ShapeMarkupLanguage.Dml));

CompressionLevel

Specifies the compression level used to save document. The default value is Aspose.Words.Saving.CompressionLevel.Normal.

public CompressionLevel CompressionLevel { get; set; }

Property Value

CompressionLevel

Examples

Shows how to specify the compression level to use while saving an OOXML document.

Document doc = new Document(MyDir + "Big document.docx");

                                                                                            // When we save the document to an OOXML format, we can create an OoxmlSaveOptions object
                                                                                            // and then pass it to the document's saving method to modify how we save the document.
                                                                                            // Set the "CompressionLevel" property to "CompressionLevel.Maximum" to apply the strongest and slowest compression.
                                                                                            // Set the "CompressionLevel" property to "CompressionLevel.Normal" to apply
                                                                                            // the default compression that Aspose.Words uses while saving OOXML documents.
                                                                                            // Set the "CompressionLevel" property to "CompressionLevel.Fast" to apply a faster and weaker compression.
                                                                                            // Set the "CompressionLevel" property to "CompressionLevel.SuperFast" to apply
                                                                                            // the default compression that Microsoft Word uses.
                                                                                            OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(SaveFormat.Docx);
                                                                                            saveOptions.CompressionLevel = compressionLevel;

                                                                                            Stopwatch st = Stopwatch.StartNew();
                                                                                            doc.Save(ArtifactsDir + "OoxmlSaveOptions.DocumentCompression.docx", saveOptions);
                                                                                            st.Stop();

                                                                                            FileInfo fileInfo = new FileInfo(ArtifactsDir + "OoxmlSaveOptions.DocumentCompression.docx");

                                                                                            Console.WriteLine($"Saving operation done using the \"{compressionLevel}\" compression level:");
                                                                                            Console.WriteLine($"\tDuration:\t{st.ElapsedMilliseconds} ms");
                                                                                            Console.WriteLine($"\tFile Size:\t{fileInfo.Length} bytes");

DigitalSignatureDetails

Gets or sets Aspose.Words.Saving.DigitalSignatureDetails object used to sign a document.

public DigitalSignatureDetails DigitalSignatureDetails { get; set; }

Property Value

DigitalSignatureDetails

Examples

Shows how to sign OOXML document.

Document doc = new Document(MyDir + "Document.docx");

                                            CertificateHolder certificateHolder = CertificateHolder.Create(MyDir + "morzal.pfx", "aw");
                                            DigitalSignatureDetails digitalSignatureDetails = new DigitalSignatureDetails(
                                                certificateHolder,
                                                new SignOptions() { Comments = "Some comments", SignTime = DateTime.Now });

                                            OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
                                            saveOptions.DigitalSignatureDetails = digitalSignatureDetails;

                                            Assert.That(digitalSignatureDetails.CertificateHolder, Is.EqualTo(certificateHolder));
                                            Assert.That(digitalSignatureDetails.SignOptions.Comments, Is.EqualTo("Some comments"));

                                            doc.Save(ArtifactsDir + "OoxmlSaveOptions.DigitalSignature.docx", saveOptions);

KeepLegacyControlChars

Keeps original representation of legacy control characters.

public bool KeepLegacyControlChars { get; set; }

Property Value

bool

Examples

Shows how to support legacy control characters when converting to .docx.

Document doc = new Document(MyDir + "Legacy control character.doc");

                                                                                   // When we save the document to an OOXML format, we can create an OoxmlSaveOptions object
                                                                                   // and then pass it to the document's saving method to modify how we save the document.
                                                                                   // Set the "KeepLegacyControlChars" property to "true" to preserve
                                                                                   // the "ShortDateTime" legacy character while saving.
                                                                                   // Set the "KeepLegacyControlChars" property to "false" to remove
                                                                                   // the "ShortDateTime" legacy character from the output document.
                                                                                   OoxmlSaveOptions so = new OoxmlSaveOptions(SaveFormat.Docx);
                                                                                   so.KeepLegacyControlChars = keepLegacyControlChars;

                                                                                   doc.Save(ArtifactsDir + "OoxmlSaveOptions.KeepLegacyControlChars.docx", so);

                                                                                   doc = new Document(ArtifactsDir + "OoxmlSaveOptions.KeepLegacyControlChars.docx");

                                                                                   Assert.That(doc.FirstSection.Body.GetText(), Is.EqualTo(keepLegacyControlChars ? "\u0013date \\@ \"MM/dd/yyyy\"\u0014\u0015\f" : "\u001e\f"));

Password

Gets/sets a password to encrypt document using ECMA376 Standard encryption algorithm.

public string Password { get; set; }

Property Value

string

Examples

Shows how to create a password encrypted Office Open XML document.

Document doc = new Document();
                                                                             DocumentBuilder builder = new DocumentBuilder(doc);
                                                                             builder.Writeln("Hello world!");

                                                                             OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
                                                                             saveOptions.Password = "MyPassword";

                                                                             doc.Save(ArtifactsDir + "OoxmlSaveOptions.Password.docx", saveOptions);

                                                                             // We will not be able to open this document with Microsoft Word or
                                                                             // Aspose.Words without providing the correct password.
                                                                             Assert.Throws<IncorrectPasswordException>(() =>
                                                                                 doc = new Document(ArtifactsDir + "OoxmlSaveOptions.Password.docx"));

                                                                             // Open the encrypted document by passing the correct password in a LoadOptions object.
                                                                             doc = new Document(ArtifactsDir + "OoxmlSaveOptions.Password.docx", new LoadOptions("MyPassword"));

                                                                             Assert.That(doc.GetText().Trim(), Is.EqualTo("Hello world!"));

Remarks

In order to save document without encryption this property should be null or empty string.

SaveFormat

Specifies the format in which the document will be saved if this save options object is used. Can be Aspose.Words.SaveFormat.Docx, Aspose.Words.SaveFormat.Docm, Aspose.Words.SaveFormat.Dotx, Aspose.Words.SaveFormat.Dotm or Aspose.Words.SaveFormat.FlatOpc.

public override SaveFormat SaveFormat { get; set; }

Property Value

SaveFormat

Examples

Shows how to set an OOXML compliance specification for a saved document to adhere to.

Document doc = new Document();
                                                                                                DocumentBuilder builder = new DocumentBuilder(doc);

                                                                                                // If we configure compatibility options to comply with Microsoft Word 2003,
                                                                                                // inserting an image will define its shape using VML.
                                                                                                doc.CompatibilityOptions.OptimizeFor(MsWordVersion.Word2003);
                                                                                                builder.InsertImage(ImageDir + "Transparent background logo.png");

                                                                                                Assert.That(((Shape)doc.GetChild(NodeType.Shape, 0, true)).MarkupLanguage, Is.EqualTo(ShapeMarkupLanguage.Vml));

                                                                                                // The "ISO/IEC 29500:2008" OOXML standard does not support VML shapes.
                                                                                                // If we set the "Compliance" property of the SaveOptions object to "OoxmlCompliance.Iso29500_2008_Strict",
                                                                                                // any document we save while passing this object will have to follow that standard. 
                                                                                                OoxmlSaveOptions saveOptions = new OoxmlSaveOptions
                                                                                                {
                                                                                                    Compliance = OoxmlCompliance.Iso29500_2008_Strict,
                                                                                                    SaveFormat = SaveFormat.Docx
                                                                                                };

                                                                                                doc.Save(ArtifactsDir + "OoxmlSaveOptions.Iso29500Strict.docx", saveOptions);

                                                                                                // Our saved document defines the shape using DML to adhere to the "ISO/IEC 29500:2008" OOXML standard.
                                                                                                doc = new Document(ArtifactsDir + "OoxmlSaveOptions.Iso29500Strict.docx");

                                                                                                Assert.That(((Shape)doc.GetChild(NodeType.Shape, 0, true)).MarkupLanguage, Is.EqualTo(ShapeMarkupLanguage.Dml));

Zip64Mode

Specifies whether or not to use ZIP64 format extensions for the output document. The default value is Aspose.Words.Saving.Zip64Mode.Never.

public Zip64Mode Zip64Mode { get; set; }

Property Value

Zip64Mode

Examples

Shows how to use ZIP64 format extensions.

Random random = new Random();
                                                    DocumentBuilder builder = new DocumentBuilder();

                                                    for (int i = 0; i < 10000; i++)
                                                    {
                                                        using (Bitmap bmp = new Bitmap(5, 5))
                                                        using (Graphics g = Graphics.FromImage(bmp))
                                                        {
                                                            g.Clear(Color.FromArgb(random.Next(0, 254), random.Next(0, 254), random.Next(0, 254)));
                                                            using (MemoryStream ms = new MemoryStream())
                                                            {
                                                                bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                                                                builder.InsertImage(ms.ToArray());
                                                            }
                                                        }
                                                    }

                                                    builder.Document.Save(ArtifactsDir + "OoxmlSaveOptions.Zip64ModeOption.docx", 
                                                        new OoxmlSaveOptions { Zip64Mode = Zip64Mode.Always });

See Also

OoxmlSaveOptions . Zip64Mode

 English