XpsDocument.cs
上传用户:huiyue
上传日期:2022-04-08
资源大小:1429k
文件大小:3k
源码类别:

搜索引擎

开发平台:

ASP/ASPX

  1. #if NET35
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.IO;
  6. using System.Windows.Documents;
  7. using System.Windows.Xps.Packaging;
  8. using System.Windows.Media.Imaging;
  9. using System.Windows.Media;
  10. namespace Searcharoo.Common
  11. {
  12.     /// <summary>
  13.     /// Load a Microsoft XPS document - REQUIRES .NET 3.x
  14.     /// </summary>
  15.     /// <remarks>
  16.     /// A compiler flag "NET35" must be set before this class can be used
  17.     /// </remarks>
  18.     public class XpsDocument : DownloadDocument
  19.     {
  20.         private string _WordsOnly;
  21.         public XpsDocument(Uri location)
  22.             : base(location)
  23.         { 
  24.             Extension = "xps";
  25.         }
  26.         public override void Parse()
  27.         {
  28.             // no parsing (for now). perhaps in future we can regex look for urls (www.xxx.com) and try to link to them...
  29.         }
  30.         public override string WordsOnly
  31.         {
  32.             get { return _WordsOnly; }
  33.         }
  34.         /// <remarks>
  35.         /// .NET System.IO.Compression and zip files
  36.         /// http://blogs.msdn.com/dotnetinterop/archive/2006/04/05/.NET-System.IO.Compression-and-zip-files.aspx
  37.         /// </remarks>
  38.         public override bool GetResponse(System.Net.HttpWebResponse webresponse)
  39.         {
  40.             string filename = System.IO.Path.Combine(
  41.                           Preferences.DownloadedTempFilePath
  42.                         , (System.IO.Path.GetFileName(this.Uri.LocalPath)));
  43.             this.Title = System.IO.Path.GetFileNameWithoutExtension(filename);
  44.             SaveDownloadedFile(webresponse, filename);
  45.             try
  46.             {
  47.                 XpsDocument xpsDoc = new XpsDocument(filename, System.IO.FileAccess.Read);
  48.                 FixedDocumentSequence docSeq = xpsDoc.GetFixedDocumentSequence();
  49.                 for (int pageNum = 0; pageNum < docSeq.DocumentPaginator.PageCount; pageNum++)
  50.                 {
  51.                     DocumentPage docPage = docSeq.DocumentPaginator.GetPage(pageNum);
  52.                     foreach (System.Windows.UIElement uie in ((FixedPage)docPage.Visual).Children)
  53.                     {
  54.                         if (uie is System.Windows.Documents.Glyphs)
  55.                         {
  56.                             _WordsOnly += " " + ((System.Windows.Documents.Glyphs)uie).UnicodeString;
  57.                         }
  58.                     }
  59.                 }
  60.                 this.All = _WordsOnly;
  61.                 System.IO.File.Delete(filename);    // clean up
  62.             }
  63.             catch (Exception ex2)
  64.             {
  65.                 //                ProgressEvent(this, new ProgressEventArgs(2, "IFilter failed on " + this.Uri + " " + e.Message + ""));
  66.             }
  67.             if (this.All != string.Empty)
  68.             {
  69.                 this.Description = base.GetDescriptionFromWordsOnly(WordsOnly);
  70.                 return true;
  71.             }
  72.             else
  73.             {
  74.                 return false;
  75.             }
  76.         }
  77.     }
  78. }
  79. #endif