关于打印XPS文件后系统对话框显示汉字为乱码的问题,请高手指点

Parmy 2011-02-23 02:19:29
winform中调用方法打印XPS文件,打印完成后该系统中所有弹出对话框中显示的汉字都变为乱码了。


方法如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Printing;
using System.IO;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
Thread printingThread = new Thread(new ThreadStart(BatchXPSPrinter.PrintXPS));

// Set the thread that will use PrintQueue.AddJob to single threading.
printingThread.SetApartmentState(ApartmentState.STA);





// Start the printing thread. The method passed to the Thread
// constructor will execute.
printingThread.Start();



}

private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("真臭");
}
}

public class BatchXPSPrinter
{
public static void PrintXPS()
{
// Create print server and print queue.
LocalPrintServer localPrintServer = new LocalPrintServer();
PrintQueue defaultPrintQueue = LocalPrintServer.GetDefaultPrintQueue();

// Prompt user to identify the directory, and then create the directory object.
Console.Write("Enter the directory containing the XPS files: ");
String directoryPath = "c:";
DirectoryInfo dir = new DirectoryInfo(directoryPath);

// If the user mistyped, end the thread and return to the Main thread.
if (!dir.Exists)
{
Console.WriteLine("There is no such directory.");
}
else
{
// If there are no XPS files in the directory, end the thread
// and return to the Main thread.
if (dir.GetFiles("*.xps").Length == 0)
{
Console.WriteLine("There are no XPS files in the directory.");
}
else
{
Console.WriteLine("\nJobs will now be added to the print queue.");
Console.WriteLine("If the queue is not paused and the printer is working, jobs will begin printing.");

// Batch process all XPS files in the directory.
foreach (FileInfo f in dir.GetFiles("*.xps"))
{
String nextFile = directoryPath + "\\" + f.Name;
Console.WriteLine("Adding {0} to queue.", nextFile);

try
{
// Print the Xps file while providing XPS validation and progress notifications.
PrintSystemJobInfo xpsPrintJob = defaultPrintQueue.AddJob(f.Name, nextFile, false);
}
catch (Exception e)
{

}

}// end for each XPS file

}//end if there are no XPS files in the directory

}//end if the directory does not exist

Console.WriteLine("Press Enter to end program.");
Console.ReadLine();

}// end PrintXPS method

}// end BatchXPSPrinter class


...全文
937 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
jiang011 2011-05-17
  • 打赏
  • 举报
回复
一直没有解决这个问题。。。

在安装了XPS Viewer的Win7系统中,可以试试命令行方式打印:
xpsrchvw.exe d:\test.xps /p

或者在winform中:
Process.Start("xpsrchvw.exe", @"d:\test.xps /p");

很奇怪微软的XPS Viewer就没这个问题,还在探索中,祝好运。。。
Parmy 2011-02-25
  • 打赏
  • 举报
回复
我看过楼上发的连接,也存在所有弹出对话框中显示的汉字都变为乱码的问题。

希望哪位大虾能给个解决方法
Parmy 2011-02-23
  • 打赏
  • 举报
回复
请高手指点呀!

110,526

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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