Пример #1
0
        public void LoadImageDocFromFile()
        {
            RtfTree tree = new RtfTree();

            int res = tree.LoadRtfFile("..\\..\\testdocs\\testdoc3.rtf");

            //StreamWriter sw = null;
            //sw = new StreamWriter("testdocs\\rtf5.txt");
            //sw.Write(tree.Rtf);
            //sw.Flush();
            //sw.Close();

            StreamReader sr = null;

            sr = new StreamReader("..\\..\\testdocs\\rtf5.txt");
            string rtf5 = sr.ReadToEnd();
            sr.Close();

            sr = new StreamReader("..\\..\\testdocs\\text2.txt");
            string text2 = sr.ReadToEnd();
            sr.Close();

            Assert.That(res, Is.EqualTo(0));
            Assert.That(tree.MergeSpecialCharacters, Is.False);
            Assert.That(tree.Rtf, Is.EqualTo(rtf5));
            Assert.That(tree.Text, Is.EqualTo(text2));
        }
Пример #2
0
        public void EmptyTreeNavigation()
        {
            RtfTree tree = new RtfTree();

            Assert.That(tree.RootNode, Is.Not.Null);
            Assert.That(tree.RootNode.Tree, Is.SameAs(tree));
            Assert.That(tree.MainGroup, Is.Null);
        }
Пример #3
0
            /// <summary>
            /// Constructor de la clase RtfMerger. 
            /// </summary>
            /// <param name="templateTree">Ruta del documento plantilla.</param>
            public RtfMerger(RtfTree templateTree)
            {
                //Se carga el documento origen
                baseRtfDoc = templateTree;

                //Se crea la lista de parámetros de sustitución (placeholders)
                placeHolder = new Dictionary<string, RtfTree>();
            }
Пример #4
0
            /// <summary>
            /// Constructor de la clase RtfMerger. 
            /// </summary>
            /// <param name="templatePath">Ruta del documento plantilla.</param>
            public RtfMerger(string templatePath)
            {
                //Se carga el documento origen
                baseRtfDoc = new RtfTree();
                baseRtfDoc.LoadRtfFile(templatePath);

                //Se crea la lista de parámetros de sustitución (placeholders)
                placeHolder = new Dictionary<string, RtfTree>();
            }
Пример #5
0
        public void ParseSimpleRtfText()
        {
            RtfTree tree = new RtfTree();
            tree.LoadRtfFile("..\\..\\testdocs\\testdoc1.rtf");

            RtfPullParser parser = new RtfPullParser();
            parser.LoadRtfText(tree.Rtf);

            parserTests(parser);
        }
Пример #6
0
            /// <summary>
            /// Asocia un nuevo parámetro de sustitución (placeholder) con la ruta del documento a insertar.
            /// </summary>
            /// <param name="ph">Nombre del placeholder.</param>
            /// <param name="path">Ruta del documento a insertar.</param>
            public void AddPlaceHolder(string ph, string path)
            {
                RtfTree tree = new RtfTree();

                int res = tree.LoadRtfFile(path);

                if (res == 0)
                {
                    placeHolder.Add(ph, tree);
                }
            }
Пример #7
0
        public void LoadObjectNode()
        {
            RtfTree tree = new RtfTree();
            tree.LoadRtfFile("..\\..\\testdocs\\testdoc3.rtf");

            RtfTreeNode node = tree.MainGroup.SelectSingleNode("object").ParentNode;

            ObjectNode objNode = new ObjectNode(node);

            Assert.That(objNode.ObjectType, Is.EqualTo("objemb"));
            Assert.That(objNode.ObjectClass, Is.EqualTo("Excel.Sheet.8"));
        }
Пример #8
0
        public void ReplaceText()
        {
            RtfTree tree = new RtfTree();

            int res = tree.LoadRtfFile("..\\..\\testdocs\\testdoc1.rtf");

            tree.MainGroup.ReplaceText("Italic", "REPLACED");

            StreamReader sr = null;
            sr = new StreamReader("..\\..\\testdocs\\rtf2.txt");
            string rtf2 = sr.ReadToEnd();
            sr.Close();

            Assert.That(tree.Rtf, Is.EqualTo(rtf2));
        }
Пример #9
0
            /// <summary>
            /// Constructor de la clase RtfMerger. 
            /// </summary>
            /// <param name="sSourceDocFullPathName">Ruta del documento plantilla.</param>
            /// <param name="sDestFileFullPathName">Ruta del documento resultante.</param>
            /// <param name="bolRemoveLastParCmd">Indica si se debe eliminar el último nodo \par de los documentos insertados en la plantilla.</param>
            public RtfMerger(string sSourceDocFullPathName, string sDestFileFullPathName, bool bolRemoveLastParCmd)
            {
                //Se carga el documento origen
                baseRtfDoc = new RtfTree();
                baseRtfDoc.LoadRtfFile(sSourceDocFullPathName);

                //Se guarda la ruta del documento destino
                destFilePath = sDestFileFullPathName;

                //Indicativo de eliminación del último nodo \par para documentos insertados
                removeLastPar = bolRemoveLastParCmd;

                //Se crea la lista de parámetros de sustitución (placeholders)
                placeHolder = new Dictionary<string, RtfTree>();
            }
Пример #10
0
        public void FindText()
        {
            RtfTree tree = new RtfTree();

            int res = tree.LoadRtfFile("..\\..\\testdocs\\testdoc1.rtf");

            RtfNodeCollection list1 = tree.MainGroup.FindText("Italic");

            Assert.That(list1.Count, Is.EqualTo(2));

            Assert.That(list1[0], Is.SameAs(tree.MainGroup[18]));
            Assert.That(list1[0].NodeKey, Is.EqualTo("Bold Italic Underline Size 14"));

            Assert.That(list1[1], Is.SameAs(tree.MainGroup[73]));
            Assert.That(list1[1].NodeKey, Is.EqualTo("Italic2"));
        }
Пример #11
0
        public void ImageBinData()
        {
            RtfTree tree = new RtfTree();
            tree.LoadRtfFile("..\\..\\testdocs\\testdoc3.rtf");

            RtfTreeNode pictNode = tree.MainGroup.SelectNodes("pict")[2].ParentNode;

            ImageNode imgNode = new ImageNode(pictNode);

            imgNode.SaveImage("..\\..\\testdocs\\img-result.png", ImageFormat.Jpeg);

            Stream fs1 = new FileStream("..\\..\\testdocs\\img-result.jpg", FileMode.Open);
            Stream fs2 = new FileStream("..\\..\\testdocs\\image1.jpg", FileMode.Open);

            Assert.That(fs1, Is.EqualTo(fs2));
        }
Пример #12
0
        public void ImageHexData()
        {
            RtfTree tree = new RtfTree();
            tree.LoadRtfFile("..\\..\\testdocs\\testdoc3.rtf");

            RtfTreeNode pictNode = tree.MainGroup.SelectNodes("pict")[2].ParentNode;

            ImageNode imgNode = new ImageNode(pictNode);

            StreamReader sr = null;

            sr = new StreamReader("..\\..\\testdocs\\imghexdata.txt");
            string hexdata = sr.ReadToEnd();
            sr.Close();

            Assert.That(imgNode.HexData, Is.EqualTo(hexdata));
        }
Пример #13
0
        public void AdjacentNodes()
        {
            //Creación de un árbol sencillo

            RtfTree tree = new RtfTree();

            RtfTreeNode mainGroup = new RtfTreeNode(RtfNodeType.Group);
            RtfTreeNode rtfNode = new RtfTreeNode(RtfNodeType.Keyword, "rtf", true, 0);
            mainGroup.AppendChild(rtfNode);

            RtfTreeNode newGroup = new RtfTreeNode(RtfNodeType.Group);
            RtfTreeNode node1 = new RtfTreeNode(RtfNodeType.Keyword, "ul", false, 0);
            RtfTreeNode node2 = new RtfTreeNode(RtfNodeType.Text, "Test", false, 0);
            RtfTreeNode node3 = new RtfTreeNode(RtfNodeType.Keyword, "ulnone", false, 0);

            newGroup.AppendChild(node1);
            newGroup.AppendChild(node2);
            newGroup.AppendChild(node3);

            mainGroup.AppendChild(newGroup);

            tree.RootNode.AppendChild(mainGroup);

            RtfTreeNode node4 = new RtfTreeNode(RtfNodeType.Text, "fin", false, 0);

            mainGroup.AppendChild(node4);

            Assert.That(tree.RootNode.NextNode, Is.SameAs(mainGroup));
            Assert.That(mainGroup.NextNode, Is.SameAs(rtfNode));
            Assert.That(rtfNode.NextNode, Is.SameAs(newGroup));
            Assert.That(newGroup.NextNode, Is.SameAs(node1));
            Assert.That(node1.NextNode, Is.SameAs(node2));
            Assert.That(node2.NextNode, Is.SameAs(node3));
            Assert.That(node3.NextNode, Is.SameAs(node4));
            Assert.That(node4.NextNode, Is.Null);

            Assert.That(node4.PreviousNode, Is.SameAs(node3));
            Assert.That(node3.PreviousNode, Is.SameAs(node2));
            Assert.That(node2.PreviousNode, Is.SameAs(node1));
            Assert.That(node1.PreviousNode, Is.SameAs(newGroup));
            Assert.That(newGroup.PreviousNode, Is.SameAs(rtfNode));
            Assert.That(rtfNode.PreviousNode, Is.SameAs(mainGroup));
            Assert.That(mainGroup.PreviousNode, Is.SameAs(tree.RootNode));
            Assert.That(tree.RootNode.PreviousNode, Is.Null);
        }
Пример #14
0
        public void ObjectBinData()
        {
            RtfTree tree = new RtfTree();
            tree.LoadRtfFile("..\\..\\testdocs\\testdoc3.rtf");

            RtfTreeNode node = tree.MainGroup.SelectSingleNode("object").ParentNode;

            ObjectNode objNode = new ObjectNode(node);

            BinaryWriter bw = new BinaryWriter(new FileStream("..\\..\\testdocs\\objbindata-result.dat", FileMode.Create));
            foreach (byte b in objNode.GetByteData())
                bw.Write(b);
            bw.Close();

            FileStream fs1 = new FileStream("..\\..\\testdocs\\objbindata-result.dat", FileMode.Open);
            FileStream fs2 = new FileStream("..\\..\\testdocs\\objbindata.dat", FileMode.Open);

            Assert.That(fs1, Is.EqualTo(fs2));
        }
Пример #15
0
        private string Convert()
        {
            var processLine = new RtfProcessLine();
            var tree = new RtfTree();
            tree.LoadRtfFile(m_FileName, Encoding.GetEncoding("Windows-1252"));

            m_Builder = new StringBuilder();
            foreach (RtfTreeNode node in tree.MainGroup.ChildNodes)
            {
                switch (node.NodeType)
                {
                    case RtfNodeType.Group:
                        if (IncludeText(node.Text) && IsParaOpen)
                            processLine.ProcessGroup(m_Builder, node, m_CurrentLine);
                        break;
                    case RtfNodeType.Text:
                        if (IncludeText(node.Text) && IsParaOpen)
                            processLine.AddText(m_Builder, node.Text);
                        break;
                    case RtfNodeType.Keyword:
                        {
                            switch (node.NodeKey)
                            {
                                case "line":
                                case "par":
                                    if (IsParaOpen)
                                        m_Builder.AppendLine();
                                    break;
                                case "pard":
                                    StartNewPara();
                                    break;
                                case "tx":
                                    AddTabStop(node.Parameter);
                                    break;
                            }
                            break;
                        }
                }
            }
            //Console.WriteLine("Document: " + m_Builder.ToString());
            return m_Builder.ToString();
        }
Пример #16
0
        public void SimpleTreeNavigation()
        {
            //Creación de un árbol sencillo

            RtfTree tree = new RtfTree();

            RtfTreeNode mainGroup = new RtfTreeNode(RtfNodeType.Group);
            RtfTreeNode rtfNode = new RtfTreeNode(RtfNodeType.Keyword, "rtf", true, 0);
            mainGroup.AppendChild(rtfNode);

            RtfTreeNode newGroup = new RtfTreeNode(RtfNodeType.Group);
            RtfTreeNode node1 = new RtfTreeNode(RtfNodeType.Keyword, "ul", false, 0);
            RtfTreeNode node2 = new RtfTreeNode(RtfNodeType.Text, "Test", false, 0);
            RtfTreeNode node3 = new RtfTreeNode(RtfNodeType.Text, "ulnone", false, 0);

            newGroup.AppendChild(node1);
            newGroup.AppendChild(node2);
            newGroup.AppendChild(node3);

            mainGroup.AppendChild(newGroup);

            tree.RootNode.AppendChild(mainGroup);

            //Navegación básica: tree
            Assert.That(tree.RootNode, Is.Not.Null);
            Assert.That(tree.MainGroup, Is.SameAs(mainGroup));

            //Navegación básica: newGroup
            Assert.That(newGroup.Tree, Is.SameAs(tree));
            Assert.That(newGroup.ParentNode, Is.SameAs(mainGroup));
            Assert.That(newGroup.RootNode, Is.SameAs(tree.RootNode));
            Assert.That(newGroup.ChildNodes, Is.Not.Null);
            Assert.That(newGroup[1], Is.SameAs(node2));
            Assert.That(newGroup.ChildNodes[1], Is.SameAs(node2));
            Assert.That(newGroup["ul"], Is.SameAs(node1));
            Assert.That(newGroup.FirstChild, Is.SameAs(node1));
            Assert.That(newGroup.LastChild, Is.SameAs(node3));
            Assert.That(newGroup.PreviousSibling, Is.SameAs(rtfNode));
            Assert.That(newGroup.NextSibling, Is.Null);
            Assert.That(newGroup.Index, Is.EqualTo(1));

            //Navegación básica: nodo2
            Assert.That(node2.Tree, Is.SameAs(tree));
            Assert.That(node2.ParentNode, Is.SameAs(newGroup));
            Assert.That(node2.RootNode, Is.SameAs(tree.RootNode));
            Assert.That(node2.ChildNodes, Is.Null);
            Assert.That(node2[1], Is.Null);
            Assert.That(node2["ul"], Is.Null);
            Assert.That(node2.FirstChild, Is.Null);
            Assert.That(node2.LastChild, Is.Null);
            Assert.That(node2.PreviousSibling, Is.SameAs(node1));
            Assert.That(node2.NextSibling, Is.SameAs(node3));
            Assert.That(node2.Index, Is.EqualTo(1));
        }
Пример #17
0
            public void Clear()
            {
                currentFormat = null;

                tree = new RtfTree();
                mainGroup = new RtfTreeNode(RtfNodeType.Group);

                InitializeTree();
            }
Пример #18
0
            /// <summary>
            /// Constructor de la clase RtfDocument.
            /// </summary>
            /// <param name="path">Ruta del fichero a generar.</param>
            /// <param name="enc">Codificación del documento a generar.</param>
            public RtfDocument(string path, Encoding enc)
            {
                this.path = path;
                this.encoding = enc;

                fontTable = new RtfFontTable();
                fontTable.AddFont("Arial");  //Default font

                colorTable = new RtfColorTable();
                colorTable.AddColor(Color.Black);  //Default color

                currentFormat = null;

                tree = new RtfTree();
                mainGroup = new RtfTreeNode(RtfNodeType.Group);

                InitializeTree();
            }
Пример #19
0
            private static void ExtractHyperlinks()
            {
                RtfTree tree = new RtfTree();
                tree.LoadRtfFile("..\\..\\testdocs\\test-doc.rtf");

                RtfNodeCollection fields = tree.MainGroup.SelectGroups("field");

                foreach (RtfTreeNode node in fields)
                {
                    //Extract URL

                    RtfTreeNode fldInst = node.ChildNodes[1];

                    string fldInstText = ExtractGroupText(fldInst);

                    string url = fldInstText.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)[1];

                    //Extract Link Text

                    RtfTreeNode fldRslt = node.SelectSingleChildGroup("fldrslt");

                    string linkText = ExtractGroupText(fldRslt);

                    Console.WriteLine("[" + linkText + ", " + url + "]");
                }
            }
Пример #20
0
            private static void ConvertToHtml()
            {
                RtfTree tree = new RtfTree();
                tree.LoadRtfFile("..\\..\\testdocs\\test-doc2.rtf");

                Rtf2Html rtfToHtml = new Rtf2Html();

                Console.WriteLine("Processing...");
                rtfToHtml.IncrustImages = false;
                string html = rtfToHtml.Convert(tree.Rtf);

                StreamWriter sw = new StreamWriter("..\\..\\testdocs\\test.html", false);
                sw.Write(html);
                sw.Flush();
                sw.Close();

                Console.WriteLine("File 'test.html' created.");

                Console.WriteLine("");
            }
Пример #21
0
            /// <summary>
            /// Elimina los elementos no deseados del documento a insertar, por ejemplo los nodos "\par" finales.
            /// </summary>
            /// <param name="docToInsert">Documento a insertar.</param>
            private void cleanToInsertDoc(RtfTree docToInsert)
            {
                //Borra el último "\par" del documento si existe
                RtfTreeNode lastNode = docToInsert.RootNode.FirstChild.LastChild;

                if (removeLastPar)
                {
                    if (lastNode.NodeType == RtfNodeType.Keyword && lastNode.NodeKey == "par")
                    {
                        docToInsert.RootNode.FirstChild.RemoveChild(lastNode);
                    }
                }
            }
Пример #22
0
            /// <summary>
            /// Inserta el nuevo árbol en el árbol base (como un nuevo grupo) eliminando toda la cabecera del documento insertado.
            /// </summary>
            /// <param name="parentNode">Grupo base en el que se insertará el nuevo arbol.</param>
            /// <param name="treeToCopyParent">Nuevo árbol a insertar.</param>
            /// <param name="intCurrIndex">Índice en el que se insertará el nuevo árbol dentro del grupo base.</param>
            private void execMergeDoc(RtfTreeNode parentNode, RtfTree treeToCopyParent, int intCurrIndex)
            {
                //Se busca el primer "\pard" del documento (comienzo del texto)
                RtfTreeNode nodePard = treeToCopyParent.RootNode.FirstChild.SelectSingleChildNode("pard");

                //Se obtiene el índice del nodo dentro del principal
                int indPard = treeToCopyParent.RootNode.FirstChild.ChildNodes.IndexOf(nodePard);

                //Se crea el nuevo grupo
                RtfTreeNode newGroup = new RtfTreeNode(RtfNodeType.Group);

                //Se resetean las opciones de párrafo y fuente
                newGroup.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "pard", false, 0));
                newGroup.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "plain", false, 0));

                //Se inserta cada nodo hijo del documento nuevo en el documento base
                for (int i = indPard + 1; i < treeToCopyParent.RootNode.FirstChild.ChildNodes.Count; i++)
                {
                    RtfTreeNode newNode =
                        treeToCopyParent.RootNode.FirstChild.ChildNodes[i].CloneNode(true);

                    newGroup.AppendChild(newNode);
                }

                //Se inserta el nuevo grupo con el nuevo documento
                parentNode.InsertChild(intCurrIndex, newGroup);
            }
Пример #23
0
            /// <summary>
            /// Ajusta los colores del documento a insertar.
            /// </summary>
            /// <param name="docToInsert">Documento a insertar.</param>
            private void mainAdjustColor(RtfTree docToInsert)
            {
                RtfColorTable colorDestTbl = baseRtfDoc.GetColorTable();
                RtfColorTable colorToCopyTbl = docToInsert.GetColorTable();

                adjustColorRecursive(docToInsert.RootNode, colorDestTbl, colorToCopyTbl);
            }
Пример #24
0
            /// <summary>
            /// Realiza una copia exacta del árbol RTF.
            /// </summary>
            /// <returns>Devuelve una copia exacta del árbol RTF.</returns>
            public RtfTree CloneTree()
            {
                RtfTree clon = new RtfTree();

                clon.rootNode = rootNode.CloneNode();

                return clon;
            }
Пример #25
0
        public void ResultNode()
        {
            RtfTree tree = new RtfTree();
            tree.LoadRtfFile("..\\..\\testdocs\\testdoc3.rtf");

            RtfTreeNode node = tree.MainGroup.SelectSingleNode("object").ParentNode;

            ObjectNode objNode = new ObjectNode(node);

            RtfTreeNode resNode = objNode.ResultNode;

            Assert.That(resNode, Is.SameAs(tree.MainGroup.SelectSingleGroup("object").SelectSingleChildGroup("result")));

            RtfTreeNode pictNode = resNode.SelectSingleNode("pict").ParentNode;
            ImageNode imgNode = new ImageNode(pictNode);

            Assert.That(imgNode.Height, Is.EqualTo(2247));
            Assert.That(imgNode.Width, Is.EqualTo(9320));

            Assert.That(imgNode.DesiredHeight, Is.EqualTo(1274));
            Assert.That(imgNode.DesiredWidth, Is.EqualTo(5284));

            Assert.That(imgNode.ScaleX, Is.EqualTo(100));
            Assert.That(imgNode.ScaleY, Is.EqualTo(100));

            Assert.That(imgNode.ImageFormat, Is.EqualTo(ImageFormat.Emf));
        }
Пример #26
0
            private static void ExtractImages()
            {
                RtfTree tree = new RtfTree();
                tree.LoadRtfFile("..\\..\\testdocs\\test-doc.rtf");

                RtfNodeCollection imageNodes = tree.RootNode.SelectNodes("pict");

                Console.WriteLine("Extracting images...");

                int i = 1;
                foreach (RtfTreeNode node in imageNodes)
                {
                    ImageNode imageNode = new ImageNode(node.ParentNode);

                    if (imageNode.ImageFormat == ImageFormat.Png)
                    {
                        imageNode.SaveImage("..\\..\\testdocs\\image" + i + ".png");

                        Console.WriteLine("File '" + "image" + i + ".png" + "' created.");

                        i++;
                    }
                }

                Console.WriteLine("");
            }
Пример #27
0
            /// <summary>
            /// Inserta un nuevo árbol en el lugar de una etiqueta de texto del árbol base.
            /// </summary>
            /// <param name="parentNode">Nodo de tipo grupo que se está procesando.</param>
            /// <param name="iNdIndex">Índice (dentro del grupo padre) del nodo texto que se está procesando.</param>
            /// <param name="docToInsert">Nuevo árbol RTF a insertar.</param>
            /// <param name="strCompletePlaceholder">Texto del la etiqueta que se va a reemplazar.</param>
            /// <param name="intPlaceHolderNodePos">Posición de la etiqueta que se va a reemplazar dentro del nodo texto que se está procesando.</param>
            private void mergeCore(RtfTreeNode parentNode, int iNdIndex, RtfTree docToInsert, string strCompletePlaceholder, int intPlaceHolderNodePos)
            {
                //Si el documento a insertar no está vacío
                if (docToInsert.RootNode.HasChildNodes() == true)
                {
                    int currentIndex = iNdIndex + 1;

                    //Se combinan las tablas de colores y se ajustan los colores del documento a insertar
                    mainAdjustColor(docToInsert);

                    //Se combinan las tablas de fuentes y se ajustan las fuentes del documento a insertar
                    mainAdjustFont(docToInsert);

                    //Se elimina la información de cabecera del documento a insertar (colores, fuentes, info, ...)
                    cleanToInsertDoc(docToInsert);

                    //Si el documento a insertar tiene contenido
                    if (docToInsert.RootNode.FirstChild.HasChildNodes())
                    {
                        //Se inserta el documento nuevo en el árbol base
                        execMergeDoc(parentNode, docToInsert, currentIndex);
                    }

                    //Si la etiqueta no está al final del nodo texto:
                    //Se inserta un nodo de texto con el resto del texto original (eliminando la etiqueta)
                    if (parentNode.ChildNodes[iNdIndex].NodeKey.Length != (intPlaceHolderNodePos + strCompletePlaceholder.Length))
                    {
                        //Se inserta un nodo de texto con el resto del texto original (eliminando la etiqueta)
                        string remText =
                            parentNode.ChildNodes[iNdIndex].NodeKey.Substring(
                                parentNode.ChildNodes[iNdIndex].NodeKey.IndexOf(strCompletePlaceholder) + strCompletePlaceholder.Length);

                        parentNode.InsertChild(currentIndex + 1, new RtfTreeNode(RtfNodeType.Text, remText, false, 0));
                    }

                    //Si la etiqueta reemplazada estaba al principio del nodo de texto eliminamos el nodo
                    //original porque ya no es necesario
                    if (intPlaceHolderNodePos == 0)
                    {
                        parentNode.RemoveChild(iNdIndex);
                    }
                    //En otro caso lo sustituimos por el texto previo a la etiqueta
                    else
                    {
                        parentNode.ChildNodes[iNdIndex].NodeKey =
                            parentNode.ChildNodes[iNdIndex].NodeKey.Substring(0, intPlaceHolderNodePos);
                    }
                }
            }
Пример #28
0
            private static void ExtractObjects()
            {
                RtfTree tree = new RtfTree();
                tree.LoadRtfFile("..\\..\\testdocs\\test-doc.rtf");

                //Busca el primer nodo de tipo objeto.
                RtfNodeCollection objects = tree.RootNode.SelectGroups("object");

                Console.WriteLine("Extracting objects...");

                int i = 1;
                foreach (RtfTreeNode node in objects)
                {
                    //Se crea un nodo RTF especializado en imágenes
                    ObjectNode objectNode = new ObjectNode(node);

                    Console.WriteLine("Found new object:");
                    Console.WriteLine("Object type: " + objectNode.ObjectType);
                    Console.WriteLine("Object class: " + objectNode.ObjectClass);

                    byte[] data = objectNode.GetByteData();

                    FileStream binaryFile = new FileStream("..\\..\\testdocs\\object" + i + ".xls", FileMode.Create, FileAccess.ReadWrite);
                    BinaryWriter bw = new BinaryWriter(binaryFile);

                    for (int j = 38; j < data.Length; j++)
                    {
                        bw.Write(data[j]);
                    }
                    bw.Flush();
                    bw.Close();

                    Console.WriteLine("File 'object" + i + ".xls' created.");

                    i++;
                }

                Console.WriteLine("");
            }
Пример #29
0
        public void ObjectHexData()
        {
            RtfTree tree = new RtfTree();
            tree.LoadRtfFile("..\\..\\testdocs\\testdoc3.rtf");

            RtfTreeNode node = tree.MainGroup.SelectSingleNode("object").ParentNode;

            ObjectNode objNode = new ObjectNode(node);

            StreamReader sr = null;

            sr = new StreamReader("..\\..\\testdocs\\objhexdata.txt");
            string hexdata = sr.ReadToEnd();
            sr.Close();

            Assert.That(objNode.HexData, Is.EqualTo(hexdata));
        }
Пример #30
0
            /// <summary>
            /// Ajusta las fuentes del documento a insertar.
            /// </summary>
            /// <param name="docToInsert">Documento a insertar.</param>
            private void mainAdjustFont(RtfTree docToInsert)
            {
                RtfFontTable fontDestTbl = baseRtfDoc.GetFontTable();
                RtfFontTable fontToCopyTbl = docToInsert.GetFontTable();

                adjustFontRecursive(docToInsert.RootNode, fontDestTbl, fontToCopyTbl);
            }