XAML代码如下:
x:Class="DEMO_XPS文?件t处ä|理¤¨ª.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="630"
Width="667">
HorizontalAlignment="Left" Margin="12,48,0,0"
Name="documentViewer1" VerticalAlignment="Top" Width="621"
/>
Height="23" HorizontalAlignment="Left" Margin="12,12,0,0"
Name="buttonLoad" VerticalAlignment="Top" Width="75"
/>
Content="打䨰印®?方¤?式º?一°?" Height="23" HorizontalAlignment="Left"
Margin="118,12,0,0" Name="buttonMode1" VerticalAlignment="Top"
Width="75" />
Content="打䨰印®?方¤?式º?二t" Height="23" HorizontalAlignment="Left"
Margin="230,12,0,0" Name="buttonMode2" VerticalAlignment="Top"
Width="75" />
后台功能代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Xps.Packaging;
using System.Printing;
namespace DEMO_XPS文?件t处ä|理¤¨ª
{
///
///
Interaction logic for MainWindow.xaml
///
public
partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private
void buttonLoad_Click(object sender, RoutedEventArgs e)
{
//添加引用ReachFrameWork
//引入命名空间using System.Windows.Xps.Packaging;
XpsDocument document = new XpsDocument(@"Demo.xps",
System.IO.FileAccess.Read);
FixedDocumentSequence fds =
document.GetFixedDocumentSequence();
documentViewer1.Document = fds;
}
//导Ì?入¨?后¨®打䨰印®?
private void buttonMode1_Click(object sender, RoutedEventArgs
e)
{
PrintDialog pd = new PrintDialog();
pd.PageRangeSelection = PageRangeSelection.AllPages;
pd.UserPageRangeEnabled = true;
bool ? ok= pd.ShowDialog();
if (ok==true)
{
XpsDocument
document = new
XpsDocument(@"Demo.xps",System.IO.FileAccess.Read);
FixedDocumentSequence fds=document.GetFixedDocumentSequence();
pd.PrintDocument(fds.DocumentPaginator, "demo");
}
}
private void buttonMode2_Click(object sender, RoutedEventArgs
e)
{
//添加引用System.Printing
//引入命名空间using System.Printing;
LocalPrintServer lps = new LocalPrintServer();
PrintQueue pq = lps.DefaultPrintQueue;
pq.AddJob("demo", @"Demo.xps", false);
}
}
}