关于Sliverlight4 打印功能

来源:互联网 发布:t局域网通讯软件 编辑:程序博客网 时间:2024/06/05 16:15

sliverlight4  打印功能基于 PrintDocument

我做了个DEMO 关于打印页面的实现

前台界面:

<UserControl x:Class="PrintPage.MainPage"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"    mc:Ignorable="d"    d:DesignHeight="300" d:DesignWidth="400">    <Grid x:Name="LayoutRoot" Background="White">        <Grid.RowDefinitions>            <RowDefinition Height="262*"/>            <RowDefinition Height="38*"/>        </Grid.RowDefinitions>        <Grid.ColumnDefinitions>            <ColumnDefinition Width="*"/>        </Grid.ColumnDefinitions>        <ScrollViewer Margin="4,4.135,4,4" HorizontalScrollBarVisibility="Auto"            VerticalScrollBarVisibility="Auto">            <Image x:Name="imgOne" Source="image/09r.jpg"                   Height="500" Width="500"/>        </ScrollViewer>        <Button x:Name="Print" Content="Print" Margin="4,5,4,0"                Click="Print_Click" Grid.Row="1" />    </Grid></UserControl>

后台代码:

using System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Windows;using System.Windows.Controls;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Animation;using System.Windows.Shapes;using System.Windows.Printing;namespace PrintPage{    public partial class MainPage : UserControl    {        public MainPage()        {            InitializeComponent();        }        private void Print_Click(object sender, RoutedEventArgs e)        {            var pdoc = new PrintDocument();            pdoc.PrintPage += (p, args) =>            {                args.PageVisual = imgOne;                args.HasMorePages = false;            };            pdoc.EndPrint += (p, args) =>            {                MessageBox.Show("打印完毕");            };            pdoc.Print("打印改页面");            }    }}

  

需要注意的是 页面打印时会触发printPage 事件,其中利用PrintPageEventArgs 会去设定页面中需要打印的区域(控件),是否需要打印多页等等

关于PrintPageEventArgs 的属性大家可以参考msdn。

同时可以定制打印完事件,触发打印完毕后一系列的逻辑

有朋友问我sliverlight4 最大打印的范围(长度)是多少。

苦苦寻找之后发泄一些线索:

  

1:Yes, its not documented though, Silverlight doesn't print for paper  sizes A3 and larger. This is due to bitmap printing which would result  in too large print jobs.

On contacting support, they said its a known issue for them with no  known schedule about when it will be resolved. Looks like it won't be so before Silverlight 5.

大致意思是sliverlight4不能打印A3或者更大的页面,这个BUG可能在SL5中被修正

2:

a0 paper size in pixel on  96dip is

Width 3174

Height 4492

when i select Print paper size in printer settings it didn't generate print

大致意思是

a0纸  的长度是3174,宽度是4492,选择A0纸的时候sliverlight就无法打印了

原创粉丝点击