关于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
{
publicpartialclass MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
privatevoid 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就无法打印了
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架