Ejemplo n.º 1
0
        //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.
            Document doc = new 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 + @"\Artifacts\Font.Hidden.doc");

            Assert.AreEqual(13, doc.GetChildNodes(NodeType.Paragraph, true).Count); //ExSkip
            Assert.AreEqual(1, doc.GetChildNodes(NodeType.Table, true).Count);      //ExSkip
        }
Ejemplo n.º 2
0
        [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());
        }
Ejemplo n.º 3
0
        public void RemoveHiddenContentFromDocument()
        {
            //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.
            // Open the document we want to remove hidden content from.
            Document doc = new 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 + @"\Artifacts\Font.Hidden.doc");

            Assert.AreEqual(13, doc.GetChildNodes(NodeType.Paragraph, true).Count); //ExSkip
            Assert.AreEqual(1, doc.GetChildNodes(NodeType.Table, true).Count);      //ExSkip
        }
Ejemplo n.º 4
0
 private void method_2(ShapeBase A_0)
 {
     if ((A_0 is ShapeObject) && smethod_2(A_0))
     {
         ShapeObject obj2 = (ShapeObject)A_0;
         if (obj2.WordArt.On && Class567.smethod_16(obj2.WordArt.Text))
         {
             foreach (string str in obj2.WordArt.Text.Split(new char[] { '\n' }))
             {
                 Paragraph paragraph = new Paragraph(this.class422_0.method_15());
                 paragraph.method_0(obj2);
                 paragraph.ChildObjects.Add(new TextRange(this.class422_0.method_15(), str, new CharacterFormat()));
                 paragraph.Accept(this.class422_0);
             }
         }
     }
 }