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

kael_thas 2011-11-03 03:31:39
问题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;
}

在线等。。
...全文
488 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
kael_thas 2012-01-09
  • 打赏
  • 举报
回复
最终的解决办法 是把 打印出来的东西 写到 image里 再打印出来。感谢回复。
heren5201314 2011-11-21
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 jv9 的回复:]
问题1:
异常信息:......xxxxx.ttf file does not conform to the expected file format specification.

这个错误是因为字体不识别中文造成的错误。

更换字体试试。
[/Quote]
冷老大正解!
jv9 2011-11-17
  • 打赏
  • 举报
回复
问题1:
异常信息:......xxxxx.ttf file does not conform to the expected file format specification.

这个错误是因为字体不识别中文造成的错误。

更换字体试试。
kael_thas 2011-11-11
  • 打赏
  • 举报
回复
第二个问题已经得到解决

打印前
myPanel.Measure(new Size(dialog.PrintableAreaWidth,
dialog.PrintableAreaHeight));
myPanel.Arrange(new Rect(new Point(0, 0),
myPanel.DesiredSize));

感谢 Sheldon _Xiao

继续等第一个问题。。。
kakaniuren 2011-11-03
  • 打赏
  • 举报
回复
木有做过..
kael_thas 2011-11-03
  • 打赏
  • 举报
回复
木有回复?

8,736

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧