Share Silverlight-based document controls similar to Baidu Library

Source: Internet
Author: User
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.

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.