Class WordDocument
Represents the root element of the rich text contents in Syncfusion.DocumentEditor.Portable library.
Inheritance
Implements
Namespace: Syncfusion.EJ2.DocumentEditor
Assembly: Syncfusion.EJ2.DocumentEditor.dll
Syntax
public class WordDocument : Object, ISerializable
Constructors
WordDocument()
Initializes a new instance of the WordDocument class.
Declaration
public WordDocument()
WordDocument(SerializationInfo, StreamingContext)
Initializes a new instance of the WordDocument class.
Declaration
protected WordDocument(SerializationInfo info, StreamingContext context)
Parameters
Type | Name | Description |
---|---|---|
System.Runtime.Serialization.SerializationInfo | info | The System.Runtime.Serialization.SerializationInfo to populate with data. |
System.Runtime.Serialization.StreamingContext | context | The destination (see System.Runtime.Serialization.StreamingContext) for this serialization. |
Properties
OptimizeSfdt
Gets or sets a value indicating whether to reduce the resultant SFDT file size by minifying the file content. The default value is true.
Declaration
public bool OptimizeSfdt { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | 'True' if the resultant SFDT file size is reduced by minifying the file content. Otherwise 'False'. |
Examples
The following code example demonstrates how to generate the Sfdt without optimization in Syncfusion Word Processor (Document editor) component.
WordDocument document = WordDocument.Load(stream, GetFormatType(type.ToLower()));
//Disables the optimized sfdt.
document.OptimizeSfdt = false;
document.Dispose();
Methods
add_MetafileImageParsed(MetafileImageParsedEventHandler)
Declaration
public static void add_MetafileImageParsed(MetafileImageParsedEventHandler value)
Parameters
Type | Name | Description |
---|---|---|
MetafileImageParsedEventHandler | value |
ComputeHash(String, String, Int32)
Compute SHA 512 hash for restrict editing
Declaration
public static string[] ComputeHash(string passwordBase64, string saltBase64, int spinCount)
Parameters
Type | Name | Description |
---|---|---|
System.String | passwordBase64 | Base64 string of passowrd |
System.String | saltBase64 | Base64 string of salt |
System.Int32 | spinCount | Spin count |
Returns
Type | Description |
---|---|
System.String[] | Returns the array of System.String represents the password and salt value. |
Dispose()
Releases all resources used by the WordDocument instance.
Declaration
public void Dispose()
GetObjectData(SerializationInfo, StreamingContext)
Populates a System.Runtime.Serialization.SerializationInfo with the data needed to serialize the target object.
Declaration
protected virtual void GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
Type | Name | Description |
---|---|---|
System.Runtime.Serialization.SerializationInfo | info | The System.Runtime.Serialization.SerializationInfo to populate with data. |
System.Runtime.Serialization.StreamingContext | context | The destination (see System.Runtime.Serialization.StreamingContext) for this serialization. |
Exceptions
Type | Condition |
---|---|
System.Security.SecurityException | The caller does not have the required permission. |
Load(WordDocument)
Loads the SFDT document from the specified Syncfusion.DocIO.DLS.WordDocument instance.
Declaration
public static WordDocument Load(WordDocument wordDocument)
Parameters
Type | Name | Description |
---|---|---|
Syncfusion.DocIO.DLS.WordDocument | wordDocument | The Syncfusion.DocIO.DLS.WordDocument instance. |
Returns
Type | Description |
---|---|
WordDocument | The WordDocument instance. |
Remarks
This overload accepts the Syncfusion.DocIO.DLS.WordDocument instance as parameter for loading SFDT document. By passing this instance, you can directly perform DocIO's built-in functionalities (like mail merge, update fields) before converting the document to SFDT. It reduces intermediate DOCX conversion.
Also allows you open the document from all file formats supported by Syncfusion Word library (DocIO).
Examples
The following code example demonstrates how to perform mail merge using Syncfusion Word library (DocIO) and convert the resultant document to SFDT for opening it in Syncfusion Word Processor (Document editor) component in client-side.
WordDocument sfdtDocument;
//Opens the input document as DocIO WordDocument instance.
using (Syncfusion.DocIO.DLS.WordDocument docIODocument = new Syncfusion.DocIO.DLS.WordDocument(stream, Syncfusion.DocIO.FormatType.Docx))
{
//Performs mail merge.
//You can add any required DocIO's logic here.
docIODocument.MailMerge.Execute(GetRecords());
//Converts DocIO DOM to SFDT DOM.
sfdtDocument = WordDocument.Load(docIODocument);
}
//Serializes SFDT DOM to SFDT string.
string sfdt = Newtonsoft.Json.JsonConvert.SerializeObject(sfdtDocument);
//Disposes the SFDT document.
sfdtDocument.Dispose();
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The input Word document instance cannot be null. |
Load(Stream, FormatType)
Loads the stream with the specified FormatType
Declaration
public static WordDocument Load(Stream stream, FormatType type)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | stream | The input stream. |
FormatType | type | The format type. |
Returns
Type | Description |
---|---|
WordDocument | The WordDocument instance. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The input stream cannot be null. |
LoadString(String, FormatType)
Load the string
Declaration
public static WordDocument LoadString(string inputString, FormatType type)
Parameters
Type | Name | Description |
---|---|---|
System.String | inputString | The input string |
FormatType | type | The Format type |
Returns
Type | Description |
---|---|
WordDocument | The WordDocument instance. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The input string cannot be null. |
remove_MetafileImageParsed(MetafileImageParsedEventHandler)
Declaration
public static void remove_MetafileImageParsed(MetafileImageParsedEventHandler value)
Parameters
Type | Name | Description |
---|---|---|
MetafileImageParsedEventHandler | value |
Save(String)
Saves the specified SFDT text as the new instance of Syncfusion.DocIO.DLS.WordDocument class.
Declaration
public static WordDocument Save(string sfdtText)
Parameters
Type | Name | Description |
---|---|---|
System.String | sfdtText | The SFDT text. |
Returns
Type | Description |
---|---|
Syncfusion.DocIO.DLS.WordDocument | The Syncfusion.DocIO.DLS.WordDocument instance. |
Remarks
This overload returns the Syncfusion.DocIO.DLS.WordDocument instance for the specified SFDT. Using this instance, you can directly perform DocIO's built-in functionalities (like mail merge, update fields) before saving the document. It reduces intermediate saving to stream and opening it again.
Also allows you save the document in all file formats supported by Syncfusion Word library (DocIO).
Examples
The following code example demonstrates how to perform mail merge using Syncfusion Word library (DocIO) for Syncfusion Word Processor (Document editor) component's SDFT document and save the final document as DOCX in server-side.
//Converts the SFDT document to DocIO WordDocument instance.
using (Syncfusion.DocIO.DLS.WordDocument docIODocument = WordDocument.Save(sfdt))
{
//You can add or modify any required DocIO's logic here.
//Performs mail merge.
docIODocument.MailMerge.Execute(GetRecords());
//You can add or modify logic to save the document in any file formats supported by DocIO.
//Saves the final document as DOCX in server-side.
docIODocument.Save(docxStream, Syncfusion.DocIO.FormatType.Docx);
}
Exceptions
Type | Condition |
---|---|
System.ArgumentException | The input SFDT text cannot be null. |
Save(String, FormatType)
Saves the sfdt text with the specified FormatType.
Declaration
public static Stream Save(string sfdtText, FormatType formatType)
Parameters
Type | Name | Description |
---|---|---|
System.String | sfdtText | The SFDT text. |
FormatType | formatType | The format type. |
Returns
Type | Description |
---|---|
System.IO.Stream | Returns the Stream which as document data. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | The input text cannot be null. |
UpdateActions(List<ActionInfo>)
Update remote actions to the document.
Declaration
public void UpdateActions(List<ActionInfo> actions)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.List<ActionInfo> | actions | Specifies the remote operations |
Events
MetafileImageParsed
Throws event when a metafile image is parsed on importing a Word document. This event is used to add an equivalent raster image as a fallback.
Declaration
public static event MetafileImageParsedEventHandler MetafileImageParsed
Event Type
Type |
---|
MetafileImageParsedEventHandler |
Examples
The following code example demonstrates how to hook MetafileImageParsed event for creating a fallback raster image from a metafile image using any third-party image converter while converting Word document to SFDT.
//Hooks MetafileImageParsed event.
WordDocument.MetafileImageParsed += OnMetafileImageParsed;
//Converts DocIO DOM to SFDT DOM.
WordDocument sfdtDocument = WordDocument.Load(docIODocument);
//Unhooks MetafileImageParsed event.
WordDocument.MetafileImageParsed -= OnMetafileImageParsed;
//Serializes SFDT DOM to SFDT string.
string sfdt = Newtonsoft.Json.JsonConvert.SerializeObject(sfdtDocument);
//Disposes the SFDT document.
sfdtDocument.Dispose();
//Converts Metafile to raster image.
private static void OnMetafileImageParsed(object sender, MetafileImageParsedEventArgs args)
{
//You can write your own method definition for converting metafile to raster image using any third-party image converter.
args.ImageStream = ConvertMetafileToRasterImage(args.MetafileStream);
}