/// <summary> /// Creates the X link. /// </summary> /// <param name="document">The document.</param> /// <param name="node">The node.</param> /// <returns></returns> public XLink CreateXLink(IDocument document, XmlNode node) { try { XLink xlink = new XLink(document); xlink.Node = node.CloneNode(true); ITextCollection iTxtCol = new ITextCollection(); foreach (XmlNode nodeText in xlink.Node.ChildNodes) { IText iText = this.CreateTextObject(xlink.Document, nodeText); if (iText != null) { iTxtCol.Add(iText); } } xlink.Node.InnerXml = ""; foreach (IText iText in iTxtCol) { xlink.TextContent.Add(iText); } return(xlink); } catch (Exception ex) { throw new AODLException("Exception while trying to create a XLink.", ex); } }
/// <summary> /// Creates the X link. /// </summary> /// <param name="document">The document.</param> /// <param name="node">The node.</param> /// <returns></returns> public XLink CreateXLink(IDocument document, XElement node) { try { XLink xlink = new XLink(document) { Node = new XElement(node) }; ITextCollection iTxtCol = new ITextCollection(); foreach (XNode nodeText in xlink.Node.Nodes()) { IText iText = CreateTextObject(xlink.Document, nodeText); if (iText != null) { iTxtCol.Add(iText); } } xlink.Node.Value = ""; foreach (IText iText in iTxtCol) { xlink.TextContent.Add(iText); } return(xlink); } catch (Exception ex) { throw new AODLException("Exception while trying to create a XLink.", ex); } }
public void XLinkTest() { //Create new TextDocument TextDocument document = new TextDocument(); document.New(); //Create a new Paragraph Paragraph para = new Paragraph(document, "P1"); //Create some simple text SimpleText stext = new SimpleText(para, "Some simple text"); //Create a XLink XLink xlink = new XLink(para, "http://www.sourceforge.net", "Sourceforge"); //Add the textcontent para.TextContent.Add(stext); para.TextContent.Add(xlink); //Add paragraph to the document content document.Content.Add(para); //Save document.SaveTo("XLink.odt"); }
/// <summary> /// Insert the given text as an Table of contents entry. /// e.g. You just insert a Headline 1. My headline to /// the document and want this text also as an Table of /// contents entry, so you can simply add the text using /// this method. /// </summary> /// <param name="textEntry">The text entry.</param> /// <param name="outLineLevel">The outline level possible 1-10.</param> public void InsertEntry(string textEntry, int outLineLevel) { Paragraph paragraph = new Paragraph( Document, "P1_Toc_Entry" + outLineLevel); ((ParagraphStyle)paragraph.Style).ParentStyle = _contentStyleName + outLineLevel; if (UseHyperlinks) { int firstWhiteSpace = textEntry.IndexOf(" "); StringBuilder sb = new StringBuilder(textEntry); sb = sb.Remove(firstWhiteSpace, 1); string link = "#" + sb + "|outline"; XLink xlink = new XLink(Document, link, textEntry) { XLinkType = "simple" }; paragraph.TextContent.Add(xlink); paragraph.TextContent.Add(new TabStop(Document)); paragraph.TextContent.Add(new SimpleText(Document, "1")); } else { //add the tabstop and the page number, the number is //always set to 1, but will be updated by the most //word processors immediately to the correct page number. paragraph.TextContent.Add(new SimpleText(Document, textEntry)); paragraph.TextContent.Add(new TabStop(Document)); paragraph.TextContent.Add(new SimpleText(Document, "1")); } //There is a bug which deny to add new simple ta // this.TitleParagraph.ParagraphStyle.ParagraphProperties.TabStopStyleCollection = // this.GetTabStopStyle(TabStopLeaderStyles.Dotted, ".", 16.999); paragraph.ParagraphStyle.ParagraphProperties.TabStopStyleCollection = GetTabStopStyle(TabStopLeaderStyles.Dotted, ".", 16.999); Content.Add(paragraph); }
/// <summary> /// Creates the X link. /// </summary> /// <param name="document">The document.</param> /// <param name="node">The node.</param> /// <returns></returns> public XLink CreateXLink(IDocument document, XmlNode node) { try { XLink xlink = new XLink(document); xlink.Node = node.CloneNode(true); ITextCollection iTxtCol = new ITextCollection(); foreach (XmlNode nodeText in xlink.Node.ChildNodes) { IText iText = this.CreateTextObject(xlink.Document, nodeText); if (iText != null) { iTxtCol.Add(iText); } } xlink.Node.InnerXml = ""; foreach (IText iText in iTxtCol) { xlink.TextContent.Add(iText); } return(xlink); } catch (Exception ex) { AODLException exception = new AODLException("Exception while trying to create a XLink."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.Node = node; exception.OriginalException = ex; throw exception; } }
public void XLinkTest() { //Create new TextDocument TextDocument document = new TextDocument(); document.New(); //Create a new Paragraph Paragraph para = new Paragraph(document, "P1"); //Create some simple text SimpleText stext = new SimpleText(document, "Some simple text "); //Create a XLink XLink xlink = new XLink(document, "http://www.sourceforge.net", "Sourceforge"); //Add the textcontent para.TextContent.Add(stext); para.TextContent.Add(xlink); //Add paragraph to the document content document.Content.Add(para); //Save using (IPackageWriter writer = new OnDiskPackageWriter()) { document.Save(AARunMeFirstAndOnce.outPutFolder + "XLink.odt", new OpenDocumentTextExporter(writer)); } }