Reputation:
I use C# WPF and Stimulsoft
I want to send path my font file was embedded to my report when need to show
I have embedded font in my WPF Project and I use it like this :
in 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="White"/>
The font was embed from font's folder in my project :
for my report was generated in stimulsoft I cannot embed font but I can send it a path of my font enter link description here
by this I can send it my font path :
for that I tried two way
C# Code :
1- :
StiFontCollection.AddFontFile(@"pack://application:,,,/FNT/#B Titr");
this case will show this error :
System.NotSupportedException: 'The given path's format is not supported.'
2- :
var fntpath = Assembly.GetEntryAssembly().GetManifestResourceStream("WpfApp5.FNT.BTITRBD.TTF");
StiFontCollection.AddFontFile(fntpath.ToString());
and in this fntpath.ToString() is null !
How to do this ?
Please help
Upvotes: -1
Views: 1788
Reputation: 1
var report = new StiReport();
var reportPath = System.Web.Hosting.HostingEnvironment.MapPath($@"~/Reports/{reportItem.FileName}");
Stimulsoft.Base.StiFontCollection.AddFontFile(System.Web.Hosting.HostingEnvironment.MapPath($@"~/fonts/Samim.ttf"));
Stimulsoft.Base.StiFontCollection.AddFontFile(System.Web.Hosting.HostingEnvironment.MapPath($@"~/fonts/IRANSansWeb.ttf"));
report.Load(reportPath);
report.RegBusinessObject("customer", customerModel);
report.RegBusinessObject("receipt", receiptModel);
report.RegBusinessObject("order", orderModel);
report.Render(false);
Upvotes: 0
Reputation: 31198
The AddFontFile
method expects the path of a physical file on disk. You cannot pass in a pack:
URI, because it doesn't understand that format. And you cannot just call .ToString()
on a Stream
, since that won't produce any meaningful information.
You need to extract your font file to a temporary file, and pass the path to that file to the AddFontFile
method.
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);
Upvotes: 1