Document processing is a crucial part of today's world. It's especially common to need to process documents with RTL (Right-To-Left) content, such as Arabic, Hebrew, or Persian text. Solving this problem with standard tools can be challenging, especially when accuracy and quality are critical.
In this article, we'll explore how to convert documents containing RTL content using the Document .Net from SautinSoft library in C#. We'll also explore the benefits of this approach, its suitability, and its popularity among developers.
Right-to-left (RTL) is a language property that determines the direction in which text is written, from right to left. Languages that use RTL include Arabic, Hebrew, Persian, Urdu, and others. Most RTL languages, such as Arabic and Hebrew, are bidirectional: a single sentence can alternate between right-to-left and left-to-right text directions. These languages require a special approach, as their reading and display have specific characteristics:
Processing such documents requires not only correct display but also the ability to convert them (e.g., to PDF, DOCX, HTML) for further use or publication.
Please note that for correct processing of RTL text, it is important that the source file has the correct formatting and that the library supports the required language features.
Complete code
using SautinSoft.Document;
using System;
using System.IO;
using System.Linq;
using System.Reflection.Metadata;
namespace Sample
{
class Sample
{
static void Main(string[] args)
{
// Get your free trial key here:
// https://sautinsoft.com/start-for-free/
ConvertRTLcontent();
}
/// <summary>
/// How to convert documents with Right-To-Left content.
/// </summary>
/// <remarks>
/// Details: https://sautinsoft.com/products/document/help/net/developer-guide/convert-documents-with-right-to-left-content.php
/// </remarks>
public static void ConvertRTLcontent()
{
string sourcePath = @"..\..\..\RTL.docx";
string destPath = "RTL.pdf";
// Load document with arabic, hindi, hebrew content.
DocumentCore dc = DocumentCore.Load(sourcePath);
// Save the document as PDF.
dc.Save(destPath, new PdfSaveOptions());
// Show the source and the dest documents.
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(sourcePath) { UseShellExecute = true });
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(destPath) { UseShellExecute = true });
}
}
}Imports SautinSoft.Document
Imports System
Imports System.IO
Imports System.Linq
Imports System.Reflection.Metadata
Namespace Sample
Friend Class Sample
Shared Sub Main(ByVal args() As String)
' Get your free trial key here:
' https://sautinsoft.com/start-for-free/
ConvertRTLcontent()
End Sub
''' <summary>
''' How to convert documents with Right-To-Left content.
''' </summary>
''' <remarks>
''' Details: https://sautinsoft.com/products/document/help/net/developer-guide/convert-documents-with-right-to-left-content.php
''' </remarks>
Public Shared Sub ConvertRTLcontent()
Dim sourcePath As String = "..\..\..\RTL.docx"
Dim destPath As String = "RTL.pdf"
' Load document with arabic, hindi, hebrew content.
Dim dc As DocumentCore = DocumentCore.Load(sourcePath)
' Save the document as PDF.
dc.Save(destPath, New PdfSaveOptions())
' Show the source and the dest documents.
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(sourcePath) With {.UseShellExecute = True})
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(destPath) With {.UseShellExecute = True})
End Sub
End Class
End Namespace
If you need a new code example or have a question: email us at support@sautinsoft.com or ask at Online Chat (right-bottom corner of this page) or use the Form below: