This example demonstrates how to append a right-to-left supported text to a document.
There are alots of languages, Some language are written in left to right direction, while some are written in top to bottum. Some language scritps are used right to left scripts like :
- Arabic
- Aramaic
- Dhivehi/Maldivian
- Hebrew
- Persian/Farsi
- Urdu
Here we will see Right to left scripting
We have versions of this representation in words ,using dropdown you can make a choice within the following
- Word Doc
- Word Docx
- Word ML
- RTF
- MS Text format
- E-book format
- DLS based xml file format
- HTML
After clicking a generate button will launch a file with above choosen version of word with right to left orientation language .
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Text;
using OfficeComponent.Word;
namespace OfficeComponent.Samples
{
class RightToLeftDocumentSupportExample : WordExampleBase
{
public RightToLeftDocumentSupportExample(string commonDataPath, string outputDir)
: base(commonDataPath, outputDir)
{
}
public RightToLeftDocumentSupportExample(string commonDataPath, string outputDir, string xmlFile)
: base(commonDataPath, outputDir, xmlFile)
{
}
public override string Execute()
{
WordDocument document = new WordDocument();
document.EnsureMinimum();
// Read Arabic text from a file.
string content;
using (StreamReader reader = new StreamReader(CommonDataPath + "\\Test List.txt"))
{
content = reader.ReadToEnd();
}
// Append it to the document.
document.LastParagraph.ParagraphFormat.Bidi = true;
TextRange text = document.LastParagraph.AppendText(content);
text.CharacterFormat.Bidi = true;
text.CharacterFormat.FontSizeBidi = 15;
string fileName = Path.Combine(OutputDir, this.GetType().Name + "_" + Guid.NewGuid().ToString() + GetExtension(SaveAsFormat));
// Save the document.
document.Save(fileName, SaveAsFormat);
// Close the document.
document.Close();
return fileName;
}
}
}
Imports System.Drawing.Imaging
Imports System.IO
Imports System.Text
Imports OfficeComponent.Word
Namespace OfficeComponent.Samples
Friend Class RightToLeftDocumentSupportExample
Inherits WordExampleBase
Public Sub New(ByVal commonDataPath As String, ByVal outputDir As String)
MyBase.New(commonDataPath, outputDir)
End Sub
Public Sub New(ByVal commonDataPath As String, ByVal outputDir As String, ByVal xmlFile As String)
MyBase.New(commonDataPath, outputDir, xmlFile)
End Sub
Public Overrides Function Execute() As String
Dim document As New WordDocument()
document.EnsureMinimum()
' Read Arabic text from a file.
Dim content As String
Using reader As New StreamReader(CommonDataPath & "\Test List.txt")
content = reader.ReadToEnd()
End Using
' Append it to the document.
document.LastParagraph.ParagraphFormat.Bidi = True
Dim text As TextRange = document.LastParagraph.AppendText(content)
text.CharacterFormat.Bidi = True
text.CharacterFormat.FontSizeBidi = 15
Dim fileName As String = Path.Combine(OutputDir, Me.GetType().Name & "_" & Guid.NewGuid().ToString() & GetExtension(SaveAsFormat))
' Save the document.
document.Save(fileName, SaveAsFormat)
' Close the document.
document.Close()
Return fileName
End Function
End Class
End Namespace