1450434548-4  
通用的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"/>



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);



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;
}
}

 

}



4. 原始程式碼下載

 

HTTPs://199.47.216.171/u/10032723/DocumentToolkit.rar

 

5. 線上預覽

 

HTTP://rapidsl2.guozili.25u.com/ (admin/admin 點左邊功能表 控制項展示 - 文檔檢視器)
創作者介紹
創作者 shadow 的頭像
shadow

資訊園

shadow 發表在 痞客邦 留言(0) 人氣()