如何在Aspose.Words中更改整个文档的RTL方向?

问题描述 投票:0回答:1

我正在尝试打开一个文本文件,然后使用以下代码将其另存为 HTML。

var doc = new Document(sourceFile);
doc.Save(targetFile, SaveFormat.Html);

源文件包含 unicode 格式的乌尔都语字符。我尝试这样做:

var doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.Font.LocaleIdBi = 1056;
builder.Font.Bidi = true;

builder.Write(File.ReadAllText(sourceFile, Encoding.UTF8));
doc.Save(targetFile, SaveFormat.Html);

但是什么也没发生,文本仍然是 LTR。

请帮忙,谢谢。

c# .net aspose aspose.words
1个回答
0
投票

您使用的代码应该按预期工作。我已经使用以下简单代码进行了测试:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Define another set of font settings for right-to-left text.
builder.Font.NameBi = "Andalus";
builder.Font.LocaleIdBi = new CultureInfo("ar-AR", false).LCID;

// We can use the Bidi flag to indicate whether the text we are about to add
// with the document builder is right-to-left. When we add text with this flag set to true,
// it will be formatted using the right-to-left set of font settings.
builder.Font.Bidi = true;
builder.Write("مرحبًا");

doc.Save(@"C:\Temp\out.html", new HtmlSaveOptions() { PrettyFormat = true });

它是 Font.Bidi 属性文档中提供的代码的简化版本。

输出的 HTML 具有正确的 RTL 方向:

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta http-equiv="Content-Style-Type" content="text/css" />
        <meta name="generator" content="Aspose.Words for .NET 23.7.0" />
        <title>
        </title>
    </head>
    <body style="font-family:'Times New Roman'; font-size:12pt">
        <div>
            <p style="margin-top:0pt; margin-bottom:0pt">
                <span style="font-family:Andalus" dir="rtl">مرحبًا</span>
            </p>
        </div>
    </body>
</html>

如果您仍然遇到问题,请将您的问题发布到Aspose.Words 支持论坛,并附上重现问题所需的文档。 Aspose.Words 支持很快就会为您提供帮助。

© www.soinside.com 2019 - 2024. All rights reserved.