/// <summary> /// Converts any fields of the specified type found in the descendants of the node into static text. /// </summary> /// <param name="compositeNode">The node in which all descendants of the specified FieldType will be converted to static text.</param> /// <param name="targetFieldType">The FieldType of the field to convert to static text.</param> public static void ConvertFieldsToStaticText(CompositeNode compositeNode, FieldType targetFieldType) { string originalNodeText = compositeNode.ToString(SaveFormat.Text); //ExSkip FieldsHelper helper = new FieldsHelper(targetFieldType); compositeNode.Accept(helper); Debug.Assert(originalNodeText.Equals(compositeNode.ToString(SaveFormat.Text)), "Error: Text of the node converted differs from the original"); //ExSkip foreach (Node node in compositeNode.GetChildNodes(NodeType.Any, true)) //ExSkip Debug.Assert(!(node is FieldChar && ((FieldChar)node).FieldType.Equals(targetFieldType)), "Error: A field node that should be removed still remains."); //ExSkip }
/// <summary> /// Converts any fields of the specified type found in the descendants of the node into static text. /// </summary> /// <param name="compositeNode">The node in which all descendants of the specified FieldType will be converted to static text.</param> /// <param name="targetFieldType">The FieldType of the field to convert to static text.</param> public static void ConvertFieldsToStaticText(CompositeNode compositeNode, FieldType targetFieldType) { string originalNodeText = compositeNode.ToString(SaveFormat.Text); //ExSkip FieldsHelper helper = new FieldsHelper(targetFieldType); compositeNode.Accept(helper); Debug.Assert(originalNodeText.Equals(compositeNode.ToString(SaveFormat.Text)), "Error: Text of the node converted differs from the original"); //ExSkip foreach (Node node in compositeNode.GetChildNodes(NodeType.Any, true)) //ExSkip { Debug.Assert(!(node is FieldChar && ((FieldChar)node).FieldType.Equals(targetFieldType)), "Error: A field node that should be removed still remains."); //ExSkip } }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_WorkingWithFields(); Document doc = new Document(dataDir + "TestFile.doc"); // Pass the appropriate parameters to convert PAGE fields encountered to static text only in the body of the first section. FieldsHelper.ConvertFieldsToStaticText(doc.FirstSection.Body, FieldType.FieldPage); // Save the document with fields transformed to disk. doc.Save(dataDir + "TestFileBody Out.doc"); Console.WriteLine("\nConverted fields to static text in the document body successfully.\nFile saved at " + dataDir + "TestFileBody Out.doc"); }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_WorkingWithFields(); Document doc = new Document(dataDir + "TestFile.doc"); // Pass the appropriate parameters to convert all IF fields encountered in the document (including headers and footers) to static text. FieldsHelper.ConvertFieldsToStaticText(doc, FieldType.FieldIf); // Save the document with fields transformed to disk. doc.Save(dataDir + "TestFileDocument Out.doc"); Console.WriteLine("\nConverted fields to static text in the document successfully.\nFile saved at " + dataDir + "TestFileDocument Out.doc"); }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_WorkingWithFields(); Document doc = new Document(dataDir + "TestFile.doc"); // Pass the appropriate parameters to convert all IF fields to static text that are encountered only in the last // paragraph of the document. FieldsHelper.ConvertFieldsToStaticText(doc.FirstSection.Body.LastParagraph, FieldType.FieldIf); // Save the document with fields transformed to disk. doc.Save(dataDir + "TestFileParagraph Out.doc"); Console.WriteLine("\nConverted fields to static text in the paragraph successfully.\nFile saved at " + dataDir + "TestFileParagraph Out.doc"); }