WPF打印之二 文档打印

这个示例演示了如何进行一个最简单的文档打印,为此需要引入一个dll:reachframework.dll

vs2008中还需引入两个命名空间:

using System.IO;

using System.Windows.Xps.Packaging;

   XAML前台代码:

  <Button Height="24" Width="75" Margin="100,100,0,0" Name="btnPrint"

      HorizontalAlignment="Left"  VerticalAlignment="Top" Click="btnPrint_Click">打印文档</Button>    

  C#后台代码:

    private void btnPrint_Click(object sender, RoutedEventArgs e)
       {

      string printFileName = @"C:\入住登记单.xps";
            // 打印对话框,设置属性
            PrintDialog pDialog = new PrintDialog();
            pDialog.PageRangeSelection = PageRangeSelection.AllPages;
            pDialog.UserPageRangeEnabled = true;
            // 这里你还可以设置对话框的MaxPage, MinPage, PageRange, PrintableAreaHeight, PrintableAreaWidth, PrintQueue, PrintTicket属性值等。
            // 显示对话框,如果用户点击“打印”按钮,则返回true。
            Nullable<Boolean> print = pDialog.ShowDialog();
            if (print == true)
            {
                System.Windows.Xps.Packaging.XpsDocument xpsDocument = new System.Windows.Xps.Packaging.XpsDocument(printFileName, System.IO.FileAccess.ReadWrite);
                FixedDocumentSequence fixedDocSeq = xpsDocument.GetFixedDocumentSequence();
                pDialog.PrintDocument(fixedDocSeq.DocumentPaginator, "打印示例");
            }

    }

 

转载于:https://www.cnblogs.com/zhengwen/archive/2010/06/06/1752799.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值