资 源 简 介
C# 打印选择的XPS文档,打印XPS文件,相关代码如下:
private void button1_Click(object sender, RoutedEventArgs e)
{//打印选择的XPS文档
var MyDlg = new Microsoft.Win32.OpenFileDialog();
MyDlg.InitialDirectory = System.IO.Directory.GetCurrentDirectory();
MyDlg.Filter = "XPS文件(*.xps)|*.xps|所有文件(*.*)|*.*";
if (MyDlg.ShowDialog() == true)
{
string MyFileName = MyDlg.FileName;
var pDialog = new PrintDialog();
pDialog.PageRangeSelection = PageRangeSelection.AllPages;
pDialog.UserPageRangeEnabled = true;
if (pDialog.ShowDialog() == true)
{
var MyDocument = new System.Windows.Xps.Packaging.XpsDocument(MyFileName, System.IO.FileAccess.ReadWrite);
FixedDocumentSequence MyFixedDocumentSequence = MyDocument.GetFixedDocumentSequence();
pDialog.PrintDocument(MyFixedDocumentSequence.DocumentPaginator, "我的XPS打印文档");
}
}
}