The general flashpaper supports Word, Excel, and PDF files. Therefore, there are many problems with the support for Silverlight XPS documents. This control provides a visual XPS document display, it provides zoom-in, zoom-out, print-out, search-and-Paging functions, and mainly integrates the open-source document toolkit.
1. Document toolkit is used. documentdatasource provides the data source. pagenvaigator provides the following pages:
<DOC: documentdatasourceX: 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 reads local XPS or remote XPS files as the data source
Dotnetzippackagereader load documents based on paging latency
// Loads the sample XPS document from the Web
VaR Url = String . Format ( " /Documentservice. ashx? Id = {0} " , Htmlpage. Document. getelementbyid ( " Entid " ). Getproperty ( " Value " ));
WebClient. openreadasync ( New Uri (htmlpage. Document. documenturi, URL ));
VaRReader =NewWebpackagereader (NewUri (htmlpage. Document. documenturi, URL +"& Part ="));
This. Datasource. packagereader = reader;
VaRXpsclient =NewXpsclient ();
Xpsclient. loadxpsdocumentasync (Reader );
3. The server returns the specified file stream based on the requested file ID and current page number.
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.Source codeDownload
Https: // 199.47.216.171/u/10032723/documenttoolkit.rar
5. Online Preview
Http://rapidsl2.guozili.25u.com /( Admin/adminClick the menu control on the left to display-document viewer)
6.