none
How to create an hyperlink to an existing bookmark RRS feed

  • Question

  • After search everywhere on the net I will ask you how to create an hyperlink using the SDK 2.0. 
    I create a new DOCX from a copy of a template, which contains already a bookmark "TOP" 
    here is my code: 
    Paragraph pb = new Paragraph( 
    new ParagraphProperties( 
    new Justification() { Val = JustificationValues.Center }), 
    new DocumentFormat.OpenXml.Wordprocessing.Hyperlink() {Anchor = "TOP" }, 
    new Run( 
    new RunProperties( 
    new RunStyle() { Val = "Hyperlink" }, 
    new Text("Back to TOP")))); 

    This create the correct text but the link is not available. 
    I also try to put Id, History,Anchor, Names... 
    If a try to add the Id of the bookmark, word is reporting an error with the contents.... 

    Hope someone already made this
    Monday, July 27, 2009 2:08 PM

Answers

  • I solved this using the DocumentReflector included into the SDK. 
    follow the step from this post: 
    DocumentReflector example of use  
    and you will get the solution easily. 

    Here is the Code I extract from the DocumentReflector: 
            public static Paragraph GenerateLinktoTop()
            {
                var element =
                    new Paragraph(
                        new ParagraphProperties(
                            new Justification() { Val = JustificationValues.Center },
                            new ParagraphMarkRunProperties(
                                new Languages() { Val = "en-GB" })),
                        new Hyperlink(
                            new Run(
                                new RunProperties(
                                    new RunStyle() { Val = "Hyperlink" },
                                    new Languages() { Val = "en-GB" }),
                                new Text("Link to TOP")
                            ) { RsidRunProperties = new HexBinaryValue() { Value = "007C02BC" } }
                        ) { History = BooleanValues.One, Anchor = "TOP" }
                    ) { RsidParagraphAddition = new HexBinaryValue() { Value = "007C02BC" }, RsidParagraphProperties = new HexBinaryValue() { Value = "007C02BC" }, RsidRunAdditionDefault = new HexBinaryValue() { Value = "007C02BC" } };
                return element;
            }


    Psylion
    • Marked as answer by Psylo Tuesday, July 28, 2009 7:37 AM
    • Edited by Psylo Tuesday, July 28, 2009 7:39 AM Update link
    Tuesday, July 28, 2009 7:36 AM