/// <summary> /// 将RTF文档内容填充到文本文档中 /// </summary> /// <param name="document">文本文档对象</param> public void FillTo(DomDocument document) { document.Clear(); ReadContent(document); //document.FixElements(); }
/// <summary> /// 根据HTML文档填充文本文档 /// </summary> /// <param name="htmlDoc">HTML文档</param> /// <param name="doc">文本文档</param> public void Load(HTMLDocument htmlDoc, DomDocument doc) { this.DomDocument = doc; this.HtmlDocument = htmlDoc; doc.Clear(); doc.FileName = htmlDoc.Location; doc.Info.Title = htmlDoc.Title; _Styles = new Dictionary <string, HTMLStyle>(); foreach (HTMLStyleElement element in htmlDoc.AllStyles) { foreach (HTMLNameStyleItem item in element.Items) { _Styles[item.Name] = item; } } CreateElements(htmlDoc.Body, doc.Body, doc.DefaultStyle); }
/// <summary> /// 从RTF文档生成文本文档内容对象 /// </summary> /// <param name="document">文本文档对象</param> /// <returns>包含生成的内容对象的列表</returns> public void ReadContent(DomDocument document) { document.Clear(); if (this.EnableDocumentSetting) { XPageSettings ps = new XPageSettings(); ps.Landscape = _RTFDocument.Landscape; ps.LeftMargin = GraphicsUnitConvert.FromTwips( _RTFDocument.LeftMargin, GraphicsUnit.Document) / 3; ps.TopMargin = GraphicsUnitConvert.FromTwips( _RTFDocument.TopMargin, GraphicsUnit.Document) / 3; ps.RightMargin = GraphicsUnitConvert.FromTwips( _RTFDocument.RightMargin, GraphicsUnit.Document) / 3; ps.BottomMargin = GraphicsUnitConvert.FromTwips( _RTFDocument.BottomMargin, GraphicsUnit.Document) / 3; ps.PaperWidth = GraphicsUnitConvert.FromTwips( _RTFDocument.PaperWidth, GraphicsUnit.Document) / 3; ps.PaperHeight = GraphicsUnitConvert.FromTwips( _RTFDocument.PaperHeight, GraphicsUnit.Document) / 3; document.PageSettings = ps; document.Info.Title = _RTFDocument.Info.Title; document.Info.Author = _RTFDocument.Info.Author; document.Info.CreationTime = _RTFDocument.Info.Creatim; document.Info.Description = _RTFDocument.Info.Comment; document.Info.LastPrintTime = _RTFDocument.Info.Printim; document.Info.LastModifiedTime = _RTFDocument.Info.Revtim; document.Info.EditMinute = _RTFDocument.Info.edmins; } document.Elements.Clear(); document.Initializing = true; ReadContent( _RTFDocument, document, document.Elements, new DocumentFormatInfo()); document.Initializing = false; document.AfterLoad(FileFormat.RTF); }