基于Web的Gmail显示连续的空格,但不打印它

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

通过.NET应用程序,我正在生成HTML电子邮件。 HTML代码如下所示:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="TX26_HTM 26.0.630.500" name="GENERATOR">
<title></title>
</head>
<body style="font-family:'Arial';font-size:12pt;text-align:left;">
<p lang="en-US" style="text-indent:0pt;margin-top:0pt;margin-bottom:0pt;font-family:'Courier New';font-size:10pt;color:#008000;white-space:pre">  AA1887¬ DFWPHX  715A  900A 757   0/ 0/ 0   0/ 0/12   0/ 0/ 0   47/ 47/176   0/ 0/ 0/ 7  R/F</p>
</body>
</html>

电子邮件必须具有固定宽度的字体,并保留连续的空格,因为这对于可读性很重要。当我将此电子邮件发送到Gmail并在浏览器中查看时,看起来应该是:

enter image description here

现在,当我单击“打印”按钮时,它将呈现可打印的版本。看起来可以保留颜色,但不能保留连续的空格:

enter image description here

我尝试了空白标签的变体,但印刷版本没有任何差异。所以我的问题... Gmail使用的标签在打印呈现时会保留连续的空白吗?

html printing gmail whitespace
1个回答
0
投票

感谢@EGC。由于我使用的是HTML Agility Pack,因此我实现了快速而肮脏的功能。根据我的阅读,使用InnerHtml代替内部文本不是一个好主意。但是出于我的目的,输出是严格定义的。

'get all the <p> nodes
Dim xpP As String = "//p"
Dim pNodes As HtmlNodeCollection = htmlDocument.DocumentNode.SelectNodes(xpP)
If pNodes IsNot Nothing Then
    For Each pNode As HtmlNode In pNodes
        'replace inner text white space with NBSP
        pNode.InnerHtml = pNode.InnerText.Replace(" ", "&nbsp;")
    Next pNode
End If
© www.soinside.com 2019 - 2024. All rights reserved.