[Test] //ExSkip public void DocumentToTxt() { // This document contains two sentences separated by an absolute position tab. Document doc = new Document(MyDir + "AbsolutePositionTab.docx"); // An AbsolutePositionTab is a child node of a paragraph. // AbsolutePositionTabs get picked up when looking for nodes of the SpecialChar type. Paragraph para = doc.FirstSection.Body.FirstParagraph; AbsolutePositionTab absPositionTab = (AbsolutePositionTab)para.GetChild(NodeType.SpecialChar, 0, true); // This implementation of the DocumentVisitor pattern converts the document to plain text. MyDocToTxtWriter myDocToTxtWriter = new MyDocToTxtWriter(); // We can run the DocumentVisitor over the whole first paragraph. para.Accept(myDocToTxtWriter); // A tab character is placed where the AbsolutePositionTab was found. Assert.AreEqual("Before AbsolutePositionTab\tAfter AbsolutePositionTab", myDocToTxtWriter.GetText()); // An AbsolutePositionTab can accept a DocumentVisitor by itself too. myDocToTxtWriter = new MyDocToTxtWriter(); absPositionTab.Accept(myDocToTxtWriter); Assert.AreEqual("\t", myDocToTxtWriter.GetText()); }
public static void Run() { // ExStart:ExtractContentUsingDocumentVisitor // The path to the documents directory. string dataDir = RunExamples.GetDataDir_WorkingWithDocument(); // Open the document we want to convert. Document doc = new Document(dataDir + "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()); // ExEnd:ExtractContentUsingDocumentVisitor }
public static void Run() { //ExStart:ExtractContentUsingDocumentVisitor // The path to the documents directory. string dataDir = RunExamples.GetDataDir_WorkingWithDocument(); // Open the document we want to convert. Document doc = new Document(dataDir + "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()); //ExEnd:ExtractContentUsingDocumentVisitor }
public void ExtractContentUsingDocumentVisitor() { //ExStart:ExtractContentUsingDocumentVisitor Document doc = new Document(MyDir + "Absolute position tab.docx"); 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()); //ExEnd:ExtractContentUsingDocumentVisitor }
//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()); }
public void ToText() { //ExStart //ExFor:Document.Accept //ExFor:Body.Accept //ExFor:DocumentVisitor //ExFor:DocumentVisitor.VisitAbsolutePositionTab //ExFor:DocumentVisitor.VisitBookmarkStart //ExFor:DocumentVisitor.VisitBookmarkEnd //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. // Open the document we want to convert. Document doc = new 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()); }