public static string GetInformationAboutRichEditDocumentLayout(Document currentDocument, DocumentLayout currentDocumentLayout)
        {
            SubDocument      subDocument = currentDocument.CaretPosition.BeginUpdateDocument();
            DocumentPosition docPosition = subDocument.CreatePosition(currentDocument.CaretPosition.ToInt() == 0 ? 0 : currentDocument.CaretPosition.ToInt() - 1);

            ReadOnlyShapeCollection         shapes = subDocument.Shapes.Get(subDocument.CreateRange(docPosition, 1));
            ReadOnlyDocumentImageCollection images = subDocument.Images.Get(subDocument.CreateRange(docPosition, 1));

            if (shapes.Count == 0 && images.Count == 0)
            {
                docPosition = subDocument.CreatePosition(currentDocument.CaretPosition.ToInt());
            }

            string returnedInformation = "";

            // get infromation about a current document element
            returnedInformation += GetInformationAboutCurrentDocumentElement(currentDocument, currentDocumentLayout, subDocument, docPosition);

            // collect information about CURRENT PAGE
            RangedLayoutElement layoutPosition = currentDocumentLayout.GetElement <RangedLayoutElement>(docPosition);

            if (layoutPosition != null)
            {
                int currentPageIndex = currentDocumentLayout.GetPageIndex(layoutPosition);
                returnedInformation += PageLayoutHelper.GetInformationAboutCurrentPage(currentDocumentLayout, currentDocumentLayout.GetPage(currentPageIndex), docPosition);
            }

            currentDocument.CaretPosition.EndUpdateDocument(subDocument);

            return(returnedInformation);
        }
示例#2
0
    //public DxDoc(DxChartFactory factory, string projtitle, string datafile, string netid)
    //{
    //	_creator_netid = netid;
    //	//Document doc = new DevExpress.XtraRichEdit.API.Native.Document();
    //}



    //public DxDoc(List<DxChartOrder> ordersC, string path, string projtitle, string datafile, string netid)
    //{
    //	_creator_netid = netid;
    //	_temppath = path;
    //	_projtitle = projtitle;
    //	_datafile = datafile;
    //	_filename = "test.docx"; // filename;

    //	MakeDocx(ordersC);

    //	//Document doc = new DevExpress.XtraRichEdit.API.Native.Document();
    //}



    //public DxDoc(DataTable dt_plots, List<string> htmltables, string path, string filename, string projtitle, string datafile, string netid)
    //{
    //	_creator_netid = netid;
    //	_temppath = path;
    //	_projtitle = projtitle;
    //	_datafile = datafile;
    //	_filename = filename;

    //	MakeDocx(dt_plots, htmltables);

    //	//Document doc = new DevExpress.XtraRichEdit.API.Native.Document();
    //}

    //public DxDoc(DataTable dt_plots, DataTable dt_tables, string path, string filename, string projtitle, string datafile, string netid)
    //{
    //	_creator_netid = netid;
    //	_temppath = path;
    //	_projtitle = projtitle;
    //	_datafile = datafile;
    //	_filename = filename;

    //	MakeDocx(dt_plots, dt_tables);

    //	//Document doc = new DevExpress.XtraRichEdit.API.Native.Document();
    //}
    #endregion


    protected void DocxHeader(DevExpress.XtraRichEdit.API.Native.Document doc, string s1, string s2)
    {
        DevExpress.XtraRichEdit.API.Native.Section firstSection = doc.Sections[0];
        // Create an empty header.
        SubDocument newHeader = firstSection.BeginUpdateHeader();

        firstSection.EndUpdateHeader(newHeader);
        // Check whether the document already has a header (the same header for all pages).
        if (firstSection.HasHeader(DevExpress.XtraRichEdit.API.Native.HeaderFooterType.Primary))
        {
            SubDocument myHeader = firstSection.BeginUpdateHeader();
            doc.ChangeActiveDocument(myHeader);
            doc.CaretPosition = myHeader.CreatePosition(0);

            string        txt   = String.Format("{0}     p.", s1);
            DocumentRange range = myHeader.InsertText(myHeader.CreatePosition(0), txt);
            Field         fld   = myHeader.Fields.Create(range.End, "PAGE");   //  "PAGE \\* ARABICDASH");
            myHeader.Fields.Update();

            myHeader.Paragraphs.Append();
            string user_time = String.Format("{0}     {1:MM/dd/yy H:mm}", _creator_netid, System.DateTime.Now);
            myHeader.AppendText(String.Format("{0}                             {1}", s2, user_time));


            firstSection.EndUpdateHeader(myHeader);
        }
    }
        public Form1()
        {
            InitializeComponent();

            // Fill first section with text
            for (int i = 0; i < 5; i++)
            {
                richEditControl1.Document.AppendText(StringSample.SampleText);
            }

            // Add a header to the document
            Section     firstSection = richEditControl1.Document.Sections[0];
            SubDocument doc          = firstSection.BeginUpdateHeader();

            doc.InsertText(doc.CreatePosition(doc.Range.End.ToInt()), "Default Header");
            firstSection.EndUpdateHeader(doc);

            // Add a new section with a separate header
            richEditControl1.Document.AppendSection();

            Section newSection = richEditControl1.Document.Sections[richEditControl1.Document.Sections.Count - 1];

            newSection.UnlinkHeaderFromPrevious();

            doc = newSection.BeginUpdateHeader();
            doc.Replace(doc.Range, "Non-Default Header");
            newSection.EndUpdateHeader(doc);

            richEditControl1.Document.AppendText(StringSample.SampleText);
        }
        private void EditComment()
        {
            #region #EditCommentContent
            Document document = richEditControl.Document;

            int commentCount = document.Comments.Count;
            if (commentCount > 0)
            {
                //The target comment is the first one
                Comment comment = document.Comments[0];
                if (comment != null)
                {
                    //Open the comment for modification
                    SubDocument commentDocument = comment.BeginUpdate();

                    //Add text to the comment range
                    commentDocument.InsertText(commentDocument.CreatePosition(0),
                                               "J. Taylor, Enabling Voice - over - IP and RAID with sofa,  in Proceedings of NOSSDAV, Oct. 1994.\r\n" +
                                               @"R.Tarjan, S.Shenker, J.Gray, A.Einstein, Q.Thomas, and X.Sato, ""Deconstructing operating systems with flanchedripper"", in Proceedings of INFOCOM, Mar. 2000.");

                    //End the comment update
                    comment.EndUpdate(commentDocument);
                }
            }
            #endregion #EditCommentContent
        }
 static void EditCommentContent(Document document)
 {
     #region #EditCommentContent
     document.LoadDocument("Documents//Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
     int commentCount = document.Comments.Count;
     if (commentCount > 0)
     {
         DevExpress.XtraRichEdit.API.Native.Comment comment = document.Comments[document.Comments.Count - 1];
         if (comment != null)
         {
             SubDocument commentDocument = comment.BeginUpdate();
             commentDocument.InsertText(commentDocument.CreatePosition(0), "comment text");
             commentDocument.Tables.Create(commentDocument.CreatePosition(13), 5, 4);
             comment.EndUpdate(commentDocument);
         }
     }
     #endregion #EditCommentContent
 }
 void EditCommentContent(RichEditDocumentServer server)
 {
     #region #EditCommentContent
     Document document = server.Document;
     document.LoadDocument("Documents\\Grimm.docx", DocumentFormat.OpenXml);
     int commentCount = document.Comments.Count;
     if (commentCount > 0)
     {
         Comment comment = document.Comments[document.Comments.Count - 1];
         if (comment != null)
         {
             SubDocument commentDocument = comment.BeginUpdate();
             commentDocument.InsertText(commentDocument.CreatePosition(0), "some text");
             commentDocument.Tables.Create(commentDocument.CreatePosition(9), 5, 4);
             comment.EndUpdate(commentDocument);
         }
     }
     #endregion #EditCommentContent
 }
 private void btnAppendToParagraph_Click(object sender, EventArgs e)
 {
     #region #AppendToParagraph
     DocumentPosition pos    = richEditControl1.Document.CaretPosition;
     SubDocument      doc    = pos.BeginUpdateDocument();
     Paragraph        par    = doc.Paragraphs.Get(pos);
     DocumentPosition newPos = doc.CreatePosition(par.Range.End.ToInt() - 1);
     doc.InsertText(newPos, "<<Appended to the End>>");
     pos.EndUpdateDocument(doc);
     #endregion #AppendToParagraph
 }
 private void btnEditHeader_Click(object sender, EventArgs e)
 {
     #region #EditHeader
     Section       firstSection = richEditControl1.Document.Sections[0];
     SubDocument   doc          = firstSection.BeginUpdateHeader(HeaderFooterType.First);
     DocumentRange range        = doc.InsertText(doc.CreatePosition(0), " PAGE NUMBER ");
     Field         fld          = doc.Fields.Create(range.End, "PAGE \\* ARABICDASH");
     doc.Fields.Update();
     richEditControl1.Document.Sections[0].EndUpdateHeader(doc);
     richEditControl1.Document.Sections[0].DifferentFirstPage = true;
     #endregion #EditHeader
 }
示例#9
0
 static void AppendToParagraph(Document document)
 {
     #region #AppendToParagraph
     document.BeginUpdate();
     document.AppendText("First Paragraph\nSecond Paragraph\nThird Paragraph");
     document.EndUpdate();
     DocumentPosition pos    = document.CaretPosition;
     SubDocument      doc    = pos.BeginUpdateDocument();
     Paragraph        par    = doc.Paragraphs.Get(pos);
     DocumentPosition newPos = doc.CreatePosition(par.Range.End.ToInt() - 1);
     doc.InsertText(newPos, "<<Appended to Paragraph End>>");
     pos.EndUpdateDocument(doc);
     #endregion #AppendToParagraph
 }
 static void ModifyHeader(Document document)
 {
     #region #ModifyHeader
     document.AppendSection();
     Section firstSection = document.Sections[0];
     // Modify the header of the HeaderFooterType.First type.
     SubDocument   myHeader = firstSection.BeginUpdateHeader(HeaderFooterType.First);
     DocumentRange range    = myHeader.InsertText(myHeader.CreatePosition(0), " PAGE NUMBER ");
     Field         fld      = myHeader.Fields.Create(range.End, "PAGE \\* ARABICDASH");
     myHeader.Fields.Update();
     firstSection.EndUpdateHeader(myHeader);
     // Display the header of the HeaderFooterType.First type on the first page.
     firstSection.DifferentFirstPage = true;
     #endregion #ModifyHeader
 }
        public Form1()
        {
            InitializeComponent();

            // Fill first section with text
            for (int i = 0; i < 5; i++)
            {
                richEditControl1.Document.AppendText(StringSample.SampleText);
            }

            // Add page numbering to the document
            Section     firstSection = richEditControl1.Document.Sections[0];
            SubDocument doc          = firstSection.BeginUpdateHeader();

            doc.InsertText(doc.CreatePosition(doc.Range.End.ToInt()), "Page ");
            doc.Fields.Create(doc.CreatePosition(doc.Range.End.ToInt()), "PAGE");
            doc.Fields.Update();
            firstSection.EndUpdateHeader(doc);

            // Add a new section and configure its page numbering
            richEditControl1.Document.AppendSection();
            richEditControl1.Document.Sections[richEditControl1.Document.Sections.Count - 1].PageNumbering.FirstPageNumber = 1;
            richEditControl1.Document.AppendText(StringSample.SampleText);
        }
 static void CreateHeader(Document document)
 {
     #region #CreateHeader
     Section firstSection = document.Sections[0];
     // Create an empty header.
     SubDocument newHeader = firstSection.BeginUpdateHeader();
     firstSection.EndUpdateHeader(newHeader);
     // Check whether the document already has a header (the same header for all pages).
     if (firstSection.HasHeader(HeaderFooterType.Primary))
     {
         SubDocument headerDocument = firstSection.BeginUpdateHeader();
         document.ChangeActiveDocument(headerDocument);
         document.CaretPosition = headerDocument.CreatePosition(0);
         firstSection.EndUpdateHeader(headerDocument);
     }
     #endregion #CreateHeader
 }
 private void btnPositionInfo_Click(object sender, EventArgs e)
 {
     #region #GetPageForPosition
     SubDocument      subDoc   = richEditControl1.Document.CaretPosition.BeginUpdateDocument();
     DocumentPosition pos      = subDoc.CreatePosition(richEditControl1.Document.CaretPosition.ToInt() == 0 ? 0 : richEditControl1.Document.CaretPosition.ToInt() - 1);
     LayoutPageArea   pageArea = richEditControl1.DocumentLayout.GetElement(pos, LayoutType.PageArea) as LayoutPageArea;
     LayoutPage       page     = pageArea.GetParentByType <LayoutPage>();
     if (page != null)
     {
         string s = String.Format("The caret is on the page with index={0}\r\n" +
                                  "The page starts at document position {1},\r\n" +
                                  "the range length of the page content is {2}.\r\n",
                                  page.Index, page.MainContentRange.Start, page.MainContentRange.Length);
         lblPageInfo.Text = s;
     }
     richEditControl1.Document.CaretPosition.EndUpdateDocument(subDoc);
     #endregion #GetPageForPosition
 }
 static void InsertRichTextInTextBox(Document document)
 {
     #region #InsertRichTextInTextBox
     document.LoadDocument("Documents//Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
     Shape myTextBox = document.Shapes[0];
     // Allow text box resize to fit contents.
     myTextBox.TextBox.HeightRule = TextBoxSizeRule.Auto;
     SubDocument boxedDocument  = myTextBox.TextBox.Document;
     int         appendPosition = myTextBox.TextBox.Document.Range.End.ToInt();
     // Append the second paragraph of the main document to the boxed text.
     DocumentRange newRange = boxedDocument.AppendDocumentContent(document.Paragraphs[1].Range);
     boxedDocument.Paragraphs.Insert(newRange.Start);
     // Insert an image form the main document into the text box.
     boxedDocument.Images.Insert(boxedDocument.CreatePosition(appendPosition), document.Images[0].Image.NativeImage);
     // Resize the image so that its size equals the image in the main document.
     boxedDocument.Images[0].Size = document.Images[0].Size;
     #endregion #InsertRichTextInTextBox
 }
示例#15
0
        public static void InsertPageNumber(Document someDocument)
        {
            for (int i = 1; i < someDocument.Sections.Count; i++)
            {
                Section currentSection = someDocument.Sections[i];

                SubDocument   myFooter = currentSection.BeginUpdateFooter();
                DocumentRange range    = myFooter.InsertText(myFooter.CreatePosition(0), " PAGE NUMBER ");
                Field         fld      = myFooter.Fields.Create(range.End, "PAGE");
                myFooter.Fields.Update();

                ParagraphProperties pp = myFooter.BeginUpdateParagraphs(myFooter.Range);
                pp.Alignment = ParagraphAlignment.Right;
                myFooter.EndUpdateParagraphs(pp);

                currentSection.EndUpdateFooter(myFooter);
            }
        }
示例#16
0
        static void ProtectDocument(RichEditDocumentServer server)
        {
            #region #ProtectDocument
            server.LoadDocument("Documents//Grimm.docx", DocumentFormat.OpenXml);
            Document document = server.Document;
            if (!document.IsDocumentProtected)
            {
                //Protect the document with a password
                document.Protect("123", DocumentProtectionType.ReadOnly);

                //Insert a comment indicating that the document is protected
                document.Comments.Create(document.Paragraphs[0].Range, "Admin");
                SubDocument commentDocument = document.Comments[0].BeginUpdate();
                commentDocument.InsertText(commentDocument.CreatePosition(0),
                                           "Document is protected with a password.\nYou cannot modify the document until protection is removed.");
                commentDocument.EndUpdate();
            }
            #endregion #ProtectDocument
        }
示例#17
0
        static void UnprotectDocument(RichEditDocumentServer server)
        {
            #region #UnprotectDocument
            server.LoadDocument("Documents//Grimm_Protected.docx", DocumentFormat.OpenXml);
            Document document = server.Document;

            if (document.IsDocumentProtected == true)
            {
                //Unprotect the document
                document.Unprotect();

                //Insert a comment indicating that the document can be edited
                document.Comments.Create(document.Paragraphs[0].Range, "Admin");
                SubDocument commentDocument = document.Comments[0].BeginUpdate();
                commentDocument.InsertText(commentDocument.CreatePosition(0),
                                           "Document is unprotected. You can modify the document according to your requests.");
                commentDocument.EndUpdate();
            }
            #endregion #UnprotectDocument
        }
        private void InsertNestedComment()
        {
            #region #NestedComment
            Document document = richEditControl.Document;


            if (document.Comments.Count > 0)
            {
                //Create a new comment nested to the second comment in the collection
                Comment nestedComment = document.Comments.Create("Brian Zetc", DateTime.Now, document.Comments[1]);

                //Add text to the newly created comment
                SubDocument   nestedCommentDocument = nestedComment.BeginUpdate();
                DocumentRange textRange             = nestedCommentDocument.InsertText(nestedCommentDocument.CreatePosition(0),
                                                                                       "Suffix trees are comprehensively reviewed in Wikipedia");
                nestedComment.EndUpdate(nestedCommentDocument);
            }
            #endregion #NestedComment
        }
        private void richEditControl1_MouseMove(object sender, MouseEventArgs e)
        {
            Point            docPoint = Units.PixelsToDocuments(e.Location, richEditControl1.DpiX, richEditControl1.DpiY);
            DocumentPosition pos      = richEditControl1.GetPositionFromPoint(docPoint);

            if (pos == null)
            {
                return;
            }

            DocumentPosition start = pos;
            DocumentPosition end   = pos;

            SubDocument doc = richEditControl1.Document.CaretPosition.BeginUpdateDocument();

            for (int i = 0; i < doc.Range.End.ToInt(); i++)
            {
                if (start.ToInt() - i < 0)
                {
                    start = doc.Range.Start;
                    break;
                }

                DocumentRange range = doc.CreateRange(start.ToInt() - i, i + 1);
                string        str   = doc.GetText(range);

                if (ContainsPunctuationOrWhiteSpace(str))
                {
                    start = doc.CreatePosition(range.Start.ToInt() + 1);
                    break;
                }
            }

            for (int i = 0; i < doc.Range.End.ToInt(); i++)
            {
                if (end.ToInt() + i > doc.Range.End.ToInt())
                {
                    end = doc.Range.End;
                    break;
                }

                DocumentRange range = doc.CreateRange(end.ToInt(), i + 1);
                string        str   = doc.GetText(range);

                if (ContainsPunctuationOrWhiteSpace(str))
                {
                    end = doc.CreatePosition(range.End.ToInt() - 1);
                    break;
                }
            }

            if (end.ToInt() < start.ToInt())
            {
                return;
            }

            DocumentRange wordRange = doc.CreateRange(start, end.ToInt() - start.ToInt());
            string        word      = doc.GetText(wordRange);

            richEditControl1.Document.CaretPosition.EndUpdateDocument(doc);

            ShowToolTip(word);
        }