2010-04-06 98 views
0
 byte[] mediaBytes = Convert.FromBase64String("<<strings>>"); 

     XpsDocument doc; 

     ms = new MemoryStream(mediaBytes, 0, mediaBytes.Length); 

     Uri DocumentUri = new Uri("pack://document.xps"); 

     using (Package package = Package.Open(ms, FileMode.Create)) 
     { 
      PackageStore.AddPackage(DocumentUri, package); 
      doc = new XpsDocument(package, CompressionOption.Maximum, DocumentUri.AbsoluteUri); 
      FixedDocumentSequence fds = doc.GetFixedDocumentSequence(); 
      documentViewer.Document = fds as IDocumentPaginatorSource; 
      PackageStore.RemovePackage(DocumentUri); 
      doc.Close(); 
     } 

任何人都可以請幫助我。其結果是一個空文件。 mediaBytes是一個PDF文檔。WPF和XPS:空文檔查看器

回答

0

在您的聲明中:Package package = Package.Open(ms,FileMode.Create) 您正在將ms設置爲程序包目標流,而不是源流。

+0

如何將其設置爲源? – xscape 2010-04-06 12:23:16

+0

當你通過代碼時,你會得到什麼?你得到一個對象或null? – psabela 2010-04-07 13:15:17

+0

請參閱此鏈接的代碼:http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/48043d53-f552-4869-8d93-8060ba2ab898 – psabela 2010-04-07 14:52:51