我使用C# WPF和Stimulsoft
。當需要顯示時,我想將我的字體檔案嵌入到我的報告中的路徑
在XAML中:<Label x。 Name="preloader" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Content=" Loading . . . " Margin="319,178,48,34" FontFamily="/WpfApp5。 component/FNT/#B Titr" FontSize="48" Background="白色"/>
字體是從我的專案中的字體檔案夾中嵌入的 :
我的報告是在stimulsoft中生成的,我不能嵌入字體,但我可以向它發送我的字體的路徑
為此我嘗試了兩種方法
C#代碼 :1- :
StiFontCollection.AddFontFile(@"pack://application:,,/FNT/#B Titr") 。
這種情況下會出現這樣的錯誤 :
System.NotSupportedException: 'The given path's format is not supported.'
2- :
var fntpath = Assembly.GetEntryAssembly().GetManifestResourceStream("WPFApp5.FNT.BTITRBD.TTF") 。
StiFontCollection.AddFontFile(fntpath.ToString())。
而在這個fntpath.ToString()是空的!
如何做到這一點?
請幫助
uj5u.com熱心網友回復:
AddFontFile方法希望得到磁盤上一個物理檔案的路徑。你不能傳入一個pack: URI,因為它不理解這種格式。你也不能只是在一個Stream上呼叫.ToString(),因為這將不會產生任何有意義的資訊。
你需要將你的字體檔案提取到一個臨時檔案,并將該檔案的路徑傳遞給AddFontFile方法。
string tempPath = Path.GetTempPath()。
string fileName = "WPFApp5.FNT.BTITRBD.TTF"。
string fontPath = Path.Combine(tempPath, fileName);
if (!File.Exists(fontPath))
{
using (var stream = Assembly.GetEntryAssembly().GetManifestResourceStream(fileName)
using (var output = File.Create(fontPath)
{
stream.CopyTo(output);
}
}
StiFontCollection.AddFontFile(fontPath)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/307903.html
標籤:
上一篇:迭代器的東西,如str

