//ExStart //ExFor:Font.Hidden //ExFor:Paragraph.Accept //ExFor:DocumentVisitor.VisitParagraphStart(Aspose.Words.Paragraph) //ExFor:DocumentVisitor.VisitFormField(Aspose.Words.Fields.FormField) //ExFor:DocumentVisitor.VisitTableEnd(Aspose.Words.Tables.Table) //ExFor:DocumentVisitor.VisitCellEnd(Aspose.Words.Tables.Cell) //ExFor:DocumentVisitor.VisitRowEnd(Aspose.Words.Tables.Row) //ExFor:DocumentVisitor.VisitSpecialChar(Aspose.Words.SpecialChar) //ExFor:DocumentVisitor.VisitGroupShapeStart(Aspose.Words.Drawing.GroupShape) //ExFor:DocumentVisitor.VisitShapeStart(Aspose.Words.Drawing.Shape) //ExFor:DocumentVisitor.VisitCommentStart(Aspose.Words.Comment) //ExFor:DocumentVisitor.VisitFootnoteStart(Aspose.Words.Footnote) //ExFor:SpecialChar //ExFor:Node.Accept //ExFor:Paragraph.ParagraphBreakFont //ExFor:Table.Accept //ExSummary:Implements the Visitor Pattern to remove all content formatted as hidden from the document. public void RemoveHiddenContentFromDocument() { // Open the document we want to remove hidden content from. Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Font.Hidden.doc"); // Create an object that inherits from the DocumentVisitor class. RemoveHiddenContentVisitor hiddenContentRemover = new RemoveHiddenContentVisitor(); // This is the well known Visitor pattern. Get the model to accept a visitor. // The model will iterate through itself by calling the corresponding methods // on the visitor object (this is called visiting). // We can run it over the entire the document like so: doc.Accept(hiddenContentRemover); // Or we can run it on only a specific node. Paragraph para = (Paragraph)doc.GetChild(NodeType.Paragraph, 4, true); para.Accept(hiddenContentRemover); // Or over a different type of node like below. Table table = (Table)doc.GetChild(NodeType.Table, 0, true); table.Accept(hiddenContentRemover); doc.Save(MyDir + "Font.Hidden Out.doc"); Assert.AreEqual(13, doc.GetChildNodes(NodeType.Paragraph, true).Count); //ExSkip Assert.AreEqual(1, doc.GetChildNodes(NodeType.Table, true).Count); //ExSkip }
//ExStart //ExFor:Document.Accept //ExFor:Body.Accept //ExFor:DocumentVisitor //ExFor:DocumentVisitor.VisitRun //ExFor:DocumentVisitor.VisitFieldStart //ExFor:DocumentVisitor.VisitFieldEnd //ExFor:DocumentVisitor.VisitFieldSeparator //ExFor:DocumentVisitor.VisitBodyStart //ExFor:DocumentVisitor.VisitBodyEnd //ExFor:DocumentVisitor.VisitParagraphEnd //ExFor:DocumentVisitor.VisitHeaderFooterStart //ExFor:VisitorAction //ExId:ExtractContentDocToTxtConverter //ExSummary:Shows how to use the Visitor pattern to add new operations to the Aspose.Words object model. In this case we create a simple document converter into a text format. public void ToText() { // Open the document we want to convert. Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Visitor.ToText.doc"); // Create an object that inherits from the DocumentVisitor class. MyDocToTxtWriter myConverter = new MyDocToTxtWriter(); // This is the well known Visitor pattern. Get the model to accept a visitor. // The model will iterate through itself by calling the corresponding methods // on the visitor object (this is called visiting). // // Note that every node in the object model has the Accept method so the visiting // can be executed not only for the whole document, but for any node in the document. doc.Accept(myConverter); // Once the visiting is complete, we can retrieve the result of the operation, // that in this example, has accumulated in the visitor. Console.WriteLine(myConverter.GetText()); }
//ExStart //ExFor:Document.Accept //ExFor:Body.Accept //ExFor:DocumentVisitor //ExFor:DocumentVisitor.VisitRun //ExFor:DocumentVisitor.VisitFieldStart //ExFor:DocumentVisitor.VisitFieldEnd //ExFor:DocumentVisitor.VisitFieldSeparator //ExFor:DocumentVisitor.VisitBodyStart //ExFor:DocumentVisitor.VisitBodyEnd //ExFor:DocumentVisitor.VisitParagraphEnd //ExFor:DocumentVisitor.VisitHeaderFooterStart //ExFor:VisitorAction //ExId:ExtractContentDocToTxtConverter //ExSummary:Shows how to use the Visitor pattern to add new operations to the Aspose.Words object model. In this case we create a simple document converter into a text format. public void ToText() { // Open the document we want to convert. Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Visitor.ToText.doc"); // Create an object that inherits from the DocumentVisitor class. MyDocToTxtWriter myConverter = new MyDocToTxtWriter(); // This is the well known Visitor pattern. Get the model to accept a visitor. // The model will iterate through itself by calling the corresponding methods // on the visitor object (this is called visiting). // // Note that every node in the object model has the Accept method so the visiting // can be executed not only for the whole document, but for any node in the document. doc.Accept(myConverter); // Once the visiting is complete, we can retrieve the result of the operation, // that in this example, has accumulated in the visitor. Console.WriteLine(myConverter.GetText()); }
//ExStart //ExFor:Font.Hidden //ExFor:Paragraph.Accept //ExFor:DocumentVisitor.VisitParagraphStart(Aspose.Words.Paragraph) //ExFor:DocumentVisitor.VisitFormField(Aspose.Words.Fields.FormField) //ExFor:DocumentVisitor.VisitTableEnd(Aspose.Words.Tables.Table) //ExFor:DocumentVisitor.VisitCellEnd(Aspose.Words.Tables.Cell) //ExFor:DocumentVisitor.VisitRowEnd(Aspose.Words.Tables.Row) //ExFor:DocumentVisitor.VisitSpecialChar(Aspose.Words.SpecialChar) //ExFor:DocumentVisitor.VisitGroupShapeStart(Aspose.Words.Drawing.GroupShape) //ExFor:DocumentVisitor.VisitShapeStart(Aspose.Words.Drawing.Shape) //ExFor:DocumentVisitor.VisitCommentStart(Aspose.Words.Comment) //ExFor:DocumentVisitor.VisitFootnoteStart(Aspose.Words.Footnote) //ExFor:SpecialChar //ExFor:Node.Accept //ExFor:Paragraph.ParagraphBreakFont //ExFor:Table.Accept //ExSummary:Implements the Visitor Pattern to remove all content formatted as hidden from the document. public void RemoveHiddenContentFromDocument() { // Open the document we want to remove hidden content from. Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Font.Hidden.doc"); // Create an object that inherits from the DocumentVisitor class. RemoveHiddenContentVisitor hiddenContentRemover = new RemoveHiddenContentVisitor(); // This is the well known Visitor pattern. Get the model to accept a visitor. // The model will iterate through itself by calling the corresponding methods // on the visitor object (this is called visiting). // We can run it over the entire the document like so: doc.Accept(hiddenContentRemover); // Or we can run it on only a specific node. Paragraph para = (Paragraph)doc.GetChild(NodeType.Paragraph, 4, true); para.Accept(hiddenContentRemover); // Or over a different type of node like below. Table table = (Table)doc.GetChild(NodeType.Table, 0, true); table.Accept(hiddenContentRemover); doc.Save(ExDir + "Font.Hidden Out.doc"); Assert.AreEqual(13, doc.GetChildNodes(NodeType.Paragraph, true).Count); //ExSkip Assert.AreEqual(1, doc.GetChildNodes(NodeType.Table, true).Count); //ExSkip }