我正在尝试让我的 C# 应用程序生成表单电子邮件。我本应在周五的一个小时内完成这件事……但 Outlook 非常不听话。
似乎无论我在 MailItem 的 HTMLBody 中指定字体大小的方式如何,它都会出现略微不同的大小。字体始终按指定显示,但大小永远不对。
email.HTMLBody = "<p style='font-size:11px;font-family:Calibri;'>girl look at that body</p>";
email.HTMLBody = "<style> body { font-family:'Calibri'; font-size:11px; } </style> <body>girl look at that body</body>";
email.HTMLBody = "<html><header><style> body { font-family:'Calibri'; font-size:11px; } </style></header> <body>girl look at that body</body></html>";
email.HTMLBody = "<span style='font-size:11px;font-family:calibri;'>girl look at that body</span>";
生成 8.5 号字体。
email.HTMLBody = "<html><body><font face='Calibri' size='11px'>girl look at that body</font></body></html>";
email.HTMLBody = "<font face='Calibri' size='11px'>girl look at that body</font>";
生成 12 号字体。
所以,似乎是通过 CSS 指定 11px(或 11pt,也尝试过)字体让我得到 8.5px,通过字体标签让我得到 12px。
我对此做了一些进一步的尝试,基本上,无论如何,字体标签都会生成 12pt 字体。所以这是一个死胡同,但我知道字体标签无论如何都被弃用了。 CSS 标签会给我不同的大小,但很少是我要求的。它始终处于关闭状态,而且数量不一致。
代码中的字体大小 = 电子邮件中的字体大小:
- 12 = 9
- 13 = 10
- 14 = 10.5
- 15 = 11.5
- 16 = 12
- 17 = 13
- 18 = 13.5
- 19 = 14.5
- 20 = 15
在 CSS 中指定 14.5px 给了我想要的 11px...但是我觉得部署依赖于它的东西不太舒服。
这里有什么问题?有什么我忽略了在 CSS 中指定的吗?我需要在 MailItem 或 Outlook.Application 的其他地方进行调整吗?
最佳答案
因为你用的是11px而不是pt。 “px”代表像素,文本大小为1像素并不意味着字体大小为1磅。使用 11pt 而不是 11px。
根据此处的讨论:https://graphicdesign.stackexchange.com/questions/199/point-vs-pixel-what-is-the-difference
A pixel is a single square 'picture element' (hence pix-el), i.e. a single dot in your image. A 10x10 image is made up of a set of a set of pixels in a grid 10 wide by 10 deep, totalling 100 pixels.
The 'point' (pt) on the other hand is a unit of length, commonly used to measure the height of a font, but technically capable of measuring any length. In applications, 1pt is equal to exactly 1/72th of an inch; in traditional print technically 72pt is 0.996264 inches, although I think you'll be forgiven for rounding it up!
How many pixels = 1pt depends on the resolution of your image. If your image is 72ppi (pixels per inch), then one point will equal exactly one pixel.
关于c# - HTMLBody 拒绝输出我指定的字体大小,总是以不同的大小结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10587159/