0

我从根目录的这个文件夹中有 OpenSans-Light.ttf:~/fonts/open-sans/OpenSans-Light.ttf

PrivateFontCollection privateFontCollection = new PrivateFontCollection();
privateFontCollection.AddFontFile("~/fonts/open-sans/OpenSans-Light.ttf");

但我得到“System.IO.FileNotFoundException:找不到文件”

如何定位该字体文件?

4

1 回答 1

0

我找到了使用 MapPath 的解决方案:

PrivateFontCollection privateFontCollection = new PrivateFontCollection();
privateFontCollection.AddFontFile(HttpContext.Current.Server.MapPath("~/fonts/open-sans/OpenSans-Light.ttf"));
于 2019-03-30T18:00:43.940 回答