silverlight仿“百度文库”的文档控件

开发 后端
通用的FlashPaper支持Word/Excel/PDF,到时对于Silverlight的XPS的文档支持问题比较多,本控件提供了一个可视化的XPS文档展示,提供放大缩小/打印/搜索/分页等功能,主要整合了开源的Document Toolkit。

通用的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

【编辑推荐】

责任编辑:张伟 来源: guozili的博客
相关推荐

2012-06-18 16:29:48

Web

2012-06-19 13:25:15

Web

2012-06-19 13:32:23

Web

2012-06-18 16:37:41

Web

2015-10-28 13:40:28

高仿百度糯米源码

2012-06-19 13:45:57

Web

2012-10-19 09:47:30

百度云百度音乐云计算

2012-06-19 13:42:08

Web

2011-05-24 10:40:12

SEO

2011-06-29 16:02:40

jQuery

2013-08-22 17:08:50

2025-01-21 18:37:07

2014-07-25 17:12:39

数据库WOT2014MongoDB

2023-10-12 17:37:50

百度文库百度世界大会

2017-09-12 17:05:02

AndroidLoading客户端

2020-12-03 06:13:46

iOS
点赞
收藏

51CTO技术栈公众号