Click or drag to resize

SaveOptions Class

Represents a base class for saving options of various file formats.
Inheritance Hierarchy
SystemObject
  SautinSoft.DocumentSaveOptions
    More

Namespace: SautinSoft.Document
Assembly: SautinSoft.Document (in SautinSoft.Document.dll) Version: 2024.7.18
Syntax
public abstract class SaveOptions

The SaveOptions type exposes the following members.

Properties
 NameDescription
Public propertyContentType Gets the content-type for this specific file format as defined in the RFC 2616.
Public propertyStatic memberCode exampleDocxDefault Gets the default saving options for Microsoft Word file format.
Public propertyStatic memberCode exampleHtmlFixedDefault Gets the default saving options for fixed HyperText Markup Language (HTML) format.
Public propertyStatic memberCode exampleHtmlFlowingDefault Gets the default saving options for flowing HyperText Markup Language (HTML) format.
Public propertyStatic memberImageDefault Gets the default saving options for Image format (PDF). Default image format: multipage TIF.
Public propertyStatic memberCode examplePdfDefault Gets the default saving options for Adobe Portable Document format (PDF).
Public propertyStatic memberCode exampleRtfDefault Gets the default saving options for Rich Text (RTF) format.
Public propertyStatic memberCode exampleTxtDefault Gets the default saving options for Plain Text (TXT) format.
Public propertyStatic memberXmlDefault Gets the default saving options for XML format.
Public propertyStatic memberXpsDefault Gets the default saving options for XPS format.
Top
Example

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

How to save a document in a desired 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/

            SaveToFile();
            SaveToStream();
        }

        /// <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.php
        /// </remarks>
        static void SaveToFile()
        {
            // Assume we already have a document 'dc'.
            DocumentCore dc = new DocumentCore();
            dc.Content.End.Insert("Hey Guys and Girls!");

            string filePath = @"Result.docx";

            // The file format will be detected automatically from the file extension: ".docx".
            dc.Save(filePath);

            // 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 PDF using MemoryStream.
        /// </summary>
        /// <remarks>
        /// Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/save-document.php
        /// </remarks>
        static void SaveToStream()
        {
            // There variables are necessary only for demonstration purposes.
            byte[] fileData = null;
            string filePath = @"Result.pdf";

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

            // Let's save our document to a MemoryStream.
            using (MemoryStream ms = new MemoryStream())
            {
                // 2nd parameter: we've explicitly set to save our document in PDF format.
                dc.Save(ms, new PdfSaveOptions());
                // Important for Linux: Install MS Fonts
                // sudo apt install ttf-mscorefonts-installer -y

                fileData = ms.ToArray();
            }

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

Module Sample
    Sub Main()
        SaveToFile()
        SaveToStream()
    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.php
    ''' </remarks>
    Sub SaveToFile()
        ' Assume we already have a document 'dc'.
        Dim dc As New DocumentCore()
        dc.Content.End.Insert("Hey Guys and Girls!")

        Dim filePath As String = "Result.docx"

        ' The file format will be detected automatically from the file extension: ".docx".
        dc.Save(filePath)

        ' 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 PDF using MemoryStream.
    ''' </summary>
    ''' <remarks>
    ''' Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/save-document.php
    ''' </remarks>
    Sub SaveToStream()
        ' There variables are necessary only for demonstration purposes.
        Dim fileData() As Byte = Nothing
        Dim filePath As String = "Result.pdf"

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

        ' Let's save our document to a MemoryStream.
        Using ms As New MemoryStream()
            ' 2nd parameter: we've explicitly set to save our document in PDF format.
            dc.Save(ms, New PdfSaveOptions())

            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
Inheritance Hierarchy