none
XPS 打印 中文字体异常问题 RRS feed

  • 常规讨论

  • 问题1:
    异常信息:......xxxxx.ttf file does not conform to the expected file format specification.
    原因:我在xps中加入了中文。
    C# code
    //代码片段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");
    }
    就能打印出来。求各位老大帮忙解决。

    C# code
    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; }

    人不犊子枉少年。
    2011年11月3日 7:50

全部回复