Click or drag to resize

DocxSaveOptions Class

Represents a class that stores saving options for Microsoft Word (DOCX) format.
Inheritance Hierarchy
SystemObject
  SautinSoft.DocumentSaveOptions
    SautinSoft.DocumentDocxSaveOptions

Namespace: SautinSoft.Document
Assembly: SautinSoft.Document (in SautinSoft.Document.dll) Version: 2024.11.20
Syntax
public sealed class DocxSaveOptions : SaveOptions

The DocxSaveOptions type exposes the following members.

Constructors
 NameDescription
Public methodCode exampleDocxSaveOptions Initializes a new instance of the DocumentCore class.
Top
Properties
 NameDescription
Public propertyContentType Gets the content-type for DOCX file format: application/vnd.openxmlformats.
(Overrides SaveOptionsContentType)
Public propertyEmbeddedImageFormat Gets and sets the format to embed images in the saving document. Default value: Auto.
Public propertyEmbeddedJpegQuality Gets and sets the value value indicating Jpeg quality level. Affects only to the images which embedded in Jpeg format. Default value: 90.
Public propertyFormat Gets or sets the Word file format into which to save the DocumentCore instance.
Public propertyPassword Gets or sets the password used to protect / encrypt the document.
Public propertyPreserveEmbeddedFonts Gets or sets a value indicating whether to save embedded fonts inside DOCX document or look for similar fonts installed in the system. Default value: true.
Top
Example

See Developer Guide: How to save a document in DOCX format

How to save a document in DOCX format using C#
using System.IO;
using SautinSoft.Document;

namespace Example
{
    class Program
    {

        static void Main(string[] args)
        {
            // Get your free 100-day key here:   
            // https://sautinsoft.com/start-for-free/

            SaveToDocxFile();
            SaveToDocxStream();
        }

        /// <summary>
        /// Creates a new document and saves it as DOCX file.
        /// </summary>
        /// <remarks>
        /// Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/save-document-as-docx-net-csharp-vb.php
        /// </remarks>
        static void SaveToDocxFile()
        {
            // Assume we already have a document 'dc'.
            DocumentCore dc = new DocumentCore();
            dc.Content.End.Insert("Hey from File!");

            string filePath = @"Result-file.docx";

            dc.Save(filePath, new DocxSaveOptions());

            // Important for Linux: Install MS Fonts
            // sudo apt install ttf-mscorefonts-installer -y

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(filePath) { UseShellExecute = true });

        }

        /// <summary>
        /// Creates a new document and saves it as DOCX using MemoryStream.
        /// </summary>
        /// <remarks>
        /// Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/save-document-as-docx-net-csharp-vb.php
        /// </remarks>
        static void SaveToDocxStream()
        {
            // There variables are necessary only for demonstration purposes.
            byte[] fileData = null;
            string filePath = @"Result-stream.docx";

            // Assume we already have a document 'dc'.
            DocumentCore dc = new DocumentCore();
            dc.Content.End.Insert("Hey from MemoryStream!");

            // Let's save our document to a MemoryStream.
            using (MemoryStream ms = new MemoryStream())
            {
                dc.Save(ms, new DocxSaveOptions());
                fileData = ms.ToArray();
            }
            File.WriteAllBytes(filePath, fileData);

            // Important for Linux: Install MS Fonts
            // sudo apt install ttf-mscorefonts-installer -y

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(filePath) { UseShellExecute = true });
        }
    }
}
How to save a document in DOCX format using VB.Net
Imports System
Imports System.IO
Imports SautinSoft.Document

Module Sample
    Sub Main()
        SaveToDocxFile()
        SaveToDocxStream()
    End Sub
    ''' Get your free 100-day key here:   
    ''' https://sautinsoft.com/start-for-free/
    ''' <summary>
    ''' Creates a new document and saves it as DOCX file.
    ''' </summary>
    ''' <remarks>
    ''' Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/save-document-as-docx-net-csharp-vb.php
    ''' </remarks>
    Sub SaveToDocxFile()
        ' Assume we already have a document 'dc'.
        Dim dc As New DocumentCore()
        dc.Content.End.Insert("Hey from File!")

        Dim filePath As String = "Result-file.docx"

        dc.Save(filePath, New DocxSaveOptions())

        ' Open the result for demonstration purposes.
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(filePath) With {.UseShellExecute = True})

    End Sub

    ''' <summary>
    ''' Creates a new document and saves it as DOCX using MemoryStream.
    ''' </summary>
    ''' <remarks>
    ''' Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/save-document-as-docx-net-csharp-vb.php
    ''' </remarks>
    Sub SaveToDocxStream()
        ' There variables are necessary only for demonstration purposes.
        Dim fileData() As Byte = Nothing
        Dim filePath As String = "Result-stream.docx"

        ' Assume we already have a document 'dc'.
        Dim dc As New DocumentCore()
        dc.Content.End.Insert("Hey from MemoryStream!")

        ' Let's save our document to a MemoryStream.
        Using ms As New MemoryStream()
            dc.Save(ms, New DocxSaveOptions())
            fileData = ms.ToArray()
        End Using
        File.WriteAllBytes(filePath, fileData)

        ' Open the result for demonstration purposes.
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(filePath) With {.UseShellExecute = True})
    End Sub
End Module
See Also