/// <summary> /// 保存指定文档 /// </summary> /// <param name="document">要保存的文档</param> protected virtual void Save(IHtmlDocument document) { var filename = Guid.NewGuid().ToString("N") + ".html"; using (var stream = File.OpenWrite(Path.Combine(@"C:\Temp", filename))) { document.Render(stream, Encoding.UTF8); } }
public static AlternateView CreateView( IHtmlDocument document ) { var stream = new MemoryStream(); document.Render( stream, Encoding.UTF8 ); stream.Seek( 0, SeekOrigin.Begin ); var resources = GetResources( document ); var view = new AlternateView( stream, "text/html" ); view.TransferEncoding = TransferEncoding.Base64; view.BaseUri = document.DocumentUri; foreach ( var r in resources ) view.LinkedResources.Add( r ); return view; }
public string Translate() { Save(); var uri = document.DocumentUri; if (!uri.IsFile) { throw new InvalidOperationException(); } var path = uri.LocalPath + ".translated"; using (var writer = File.CreateText(path)) { document.Render(writer, this); } return(path); }
public string Translate() { Save(); var uri = _document.DocumentUri; if (!uri.IsFile) { throw new InvalidOperationException(); } var path = Path.ChangeExtension(uri.LocalPath, ".translated") + ".html"; using (var writer = File.CreateText(path)) { _document.Render(writer, this); } return(path); }
public static AlternateView CreateView(IHtmlDocument document) { var stream = new MemoryStream(); document.Render(stream, Encoding.UTF8); stream.Seek(0, SeekOrigin.Begin); var resources = GetResources(document); var view = new AlternateView(stream, "text/html"); view.TransferEncoding = TransferEncoding.Base64; view.BaseUri = document.DocumentUri; foreach (var r in resources) { view.LinkedResources.Add(r); } return(view); }