XPS 打印 字体异常。求各位老大解决

kael_thas kael_thas 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
问题1:
异常信息:......xxxxx.ttf file does not conform to the expected file format specification.
原因:我在xps中加入了中文。

//代码片段1
foreach (XpsFont font in fixedPageReader.Fonts)
{
string name = Helper.GetFileName(font.Uri);
string guid = new Guid(GetFileName(font.Uri).Split('.')[0]).ToString("N");
name = System.IO.Path.Combine(guid, System.IO.Path.GetFileNameWithoutExtension(name) + ".ttf");
string path = string.Format(@"{0}\{1}", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), name);
if (!fontList.ContainsKey(font.Uri.OriginalString))
{
Helper.SaveToDisk(font, path);
fontList.Add(font.Uri.OriginalString, path);
}
}
//代码片段2
foreach (KeyValuePair<string, string> val in fontList)
{
page = Helper.ReplaceAttribute(page, "FontUri", val.Key, val.Value);
//page = Helper.ReplaceAttribute(page, "FontUri", val.Key, "D:\\simsunb.ttf");
}
//代码片段3
FixedPage fp = XamlReader.Load(new MemoryStream(Encoding.Default.GetBytes(page))) as FixedPage;

问题2:自定义一个数据表格绑定完数据后,直接打印 表格出现了,但数据没有,
如果在打印之前加上
PrintDialog dialog = new PrintDialog();

if (dialog.ShowDialog() == true)
{
dialog.PrintVisual(sp, "Print Test");
}
就能打印出来。求各位老大帮忙解决。


private void Print_Click(object sender, RoutedEventArgs e)
{

DataGrid dg = new DataGrid();
dg.ItemsSource = getdata().DefaultView;

StackPanel sp = new StackPanel();
sp.Children.Add(dg);
PrintDialog dialog = new PrintDialog();

if (dialog.ShowDialog() == true)
{
dialog.PrintVisual(sp, "Print Test");
}
VisualPrintDialog printDlg = new VisualPrintDialog(sp);
printDlg.ShowDialog();
}
double width = 11;
double height = 8.5;
private DataTable getdata()
{
DataTable dt = new DataTable();
dt.Columns.Add("aa", typeof(string));
dt.Columns.Add("BB", typeof(string));
dt.Columns.Add("中文", typeof(string));
for (int j = 0; j < 10; j++)
{
string[] objVals = new string[3];
for (int i = 0; i < 3; i++)
{
string obj = "tets" + j;
objVals[i] = obj;
}

dt.Rows.Add(objVals);
}

return dt;
}

在线等。。
...全文

相关推荐

评论 7
收藏 已收藏
分享
返回顶部
kael_thas
WPF/Silverlight 8,757 成员 12,031 内容