【问题标题】:RTF to HTML, change font-familyRTF 到 HTML,更改字体系列
【发布时间】:2013-08-30 20:54:03
【问题描述】:

我的 C# 应用程序中有一些 RTF 文本,我将其转换为 HTML,然后发送到我的 PHP 文件。 问题是;我在 PHP 中的所有文本都是 Arial,我的 RTF 的输出是 Tahoma。有什么想法可以更改字体系列吗?

这是我目前的代码:

string memoValue = inboundSet.Fields["MEMO"].Value.ToString();
if (RtfTags.IsRtfContent(memoValue))
  {     
    using (RichEditDocumentServer richServer = new RichEditDocumentServer())
      {
        string htmlText = string.Empty;
        richServer.RtfText = memoValue;
        htmlText = richServer.HtmlText;
        callDetail.Memo = htmlText;
      }
  }
else
  {
    callDetail.Memo = memoValue;
  }

在我的 PHP 文件中,我以这种方式获取值:

echo "<td>Memo:</td><td>".$value->Memo."</td>";

我也是这样尝试的:

echo "<td>Memo:</td><td class='fonttest'>".$value->Memo."</td>";

在我的 CSS 中:

.fonttest
{
    font-size:12px;
    font-family:Arial;
}

我的文字一直是这样的:

这是我的 RTF 文本的样子:

【问题讨论】:

  • 您是否尝试将Times New RomanCalibri 更改为Arial?只是我需要问的一个简单的事情:)
  • 我已经解决了。我无法手动更改 RTF,因为我无法直接访问 C# 应用程序的代码

标签: c# html rtf


【解决方案1】:

我通过这种方式解决了我的问题:

string memoValue = inboundSet.Fields["MEMO"].Value.ToString();
if (RtfTags.IsRtfContent(memoValue))
{     
  using (RichEditDocumentServer richServer = new RichEditDocumentServer())
  {
    string htmlText = string.Empty;
    richServer.RtfText = memoValue;
    CharacterProperties cp = richServer.Document.BeginUpdateCharacters(richServer.Document.Range);
    cp.FontName = "Arial";
    cp.FontSize = 12;
    richServer.Document.EndUpdateCharacters(cp);
    htmlText = richServer.HtmlText;
    callDetail.Memo = htmlText;
   }
}

【讨论】:

    【解决方案2】:

    您必须为生成的 HTML 设置字体系列。您可以通过将 CSS 样式应用于生成页面的标题来做到这一点。

    将此样式嵌入到标题中:

    "<style>body {font-family:Arial;}</style>"
    

    【讨论】:

    • 我不会转换整个页面,很可能只有 1 个句子。在我的 PHP 页面的 CSS 中,我确实有 font-family:arial,但似乎我从转换器得到的句子并不关心样式表
    猜你喜欢
    • 2013-11-14
    • 1970-01-01
    • 2019-04-26
    • 2020-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-03
    • 2011-05-26
    相关资源
    最近更新 更多