关于Sliverlight4 打印功能

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就无法打印了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值