通用的FlashPaper支持Word/Excel/PDF,到时对于Silverlight的XPS的文档支持问题比较多,本控件提供了一个可视化的XPS文档展示,提供放大缩小/打印/搜索/分页等功能,主要整合了开源的Document Toolkit。
1. 使用Document Toolkit,DocumentDataSource提供数据源,PageNvaigator提供分页 :
<doc:DocumentDataSource x:Name="dataSource"/>
<doc:DocumentViewer Grid.Row="1" x:Name="viewer" DocumentDataSource="{Binding ElementName=dataSource}" ViewMode="{Binding SelectedViewMode, ElementName=viewModePicker}" BorderBrush="#9fa9a4" BorderThickness="1"/>
<doc:PageNavigator x:Name="navigator" HorizontalAlignment="Center"
PageCount="{Binding PageCount, ElementName=viewer}"
PageIndex="{Binding PageIndex, ElementName=viewer, Mode=TwoWay}"
/>
<doc:ViewModePicker Grid.Column="1" x:Name="viewModePicker" Visibility="Collapsed"/>
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
2. WebPackageReader读取本地xps或远程xps文件作为数据源
DotNetZipPackageReader 根据分页延迟加载文档
// loads the sample XPS document from the web
var url = string.Format("/DocumentService.ashx?id={0}", HtmlPage.Document.GetElementById("documentId").GetProperty("value"));
webClient.OpenReadAsync(new Uri(HtmlPage.Document.DocumentUri, url));
var reader = new WebPackageReader(new Uri(HtmlPage.Document.DocumentUri, url + "&part="));
this.dataSource.PackageReader = reader;
var xpsClient = new XpsClient();
xpsClient.LoadXpsDocumentAsync(reader);
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
3. 服务端根据请求的文件ID和当前页码返回指定的文件流
private void Response(HttpContext context, string xpsFileName, string partName)
{
using (FileStream stream = File.OpenRead(xpsFileName))
{
ZipFile file = new ZipFile(stream);
ZipEntry entry = file.GetEntry(partName);
if (entry != null)
{
using (Stream entryStream = file.GetInputStream(entry))
{
// TODO: set mime-type as defined in XPS package
context.Response.ContentType = "application/octet-stream";
byte[] buffer = new byte[2 << 14]; // write blocks of 32768 bytes
int read;
while ((read = entryStream.Read(buffer, 0, buffer.Length)) > 0)
{
context.Response.OutputStream.Write(buffer, 0, read);
}
}
}
else
{
// return 404 Not Found
context.Response.StatusCode = (int)HttpStatusCode.NotFound;
}
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
4. 源代码下载
5. 在线预览
http://rapidsl2.guozili.25u.com/ (admin/admin 点左边菜单 控件展示 - 文档查看器)
6. 截图
原文链接:http://www.cnblogs.com/guozili/archive/2012/07/16/2593437.html
【编辑推荐】