How to create a hyper link at the end of every page ? ASPOSE.Words

We are using ASPOSE.WOrds to convert from .doc to .docx. How to add a hyperlink at the end of every page of the document?

@hrnallap

To add a hyperlink at the end of every page in a document using Aspose.Words, you can utilize the DocumentBuilder class to insert hyperlinks programmatically. Below is a sample code snippet that demonstrates how to achieve this:

import com.aspose.words.Document;
import com.aspose.words.DocumentBuilder;
import com.aspose.words.PageSetup;
import com.aspose.words.Paragraph;
import com.aspose.words.Section;

public class AddHyperlinkToEveryPage {
    public static void main(String[] args) throws Exception {
        // Create a new document
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);

        // Add some content to the document
        for (int i = 0; i < 5; i++) {
            builder.writeln("This is page " + (i + 1));
            builder.InsertBreak(BreakType.PAGE_BREAK);
        }

        // Loop through each section to add a hyperlink at the end of each page
        for (Section section : doc.getSections()) {
            for (Paragraph paragraph : section.getBody().getParagraphs()) {
                if (paragraph.getText().contains("page")) {
                    // Move the builder to the end of the paragraph
                    builder.moveTo(paragraph);
                    // Insert the hyperlink
                    builder.insertHyperlink("Visit Aspose", "http://www.aspose.com", false);
                    builder.writeln(); // Add a new line after the hyperlink
                }
            }
        }

        // Save the document
        doc.save("DocumentWithHyperlinks.docx");
        System.out.println("Document saved with hyperlinks at the end of each page.");
    }
}

Explanation:

  1. Document Creation: A new document is created, and some sample content is added to simulate multiple pages.
  2. Looping Through Sections: The code iterates through each section and its paragraphs to find where to insert the hyperlink.
  3. Inserting Hyperlink: The hyperlink is inserted at the end of each page’s content.
  4. Saving the Document: Finally, the document is saved with the hyperlinks included.

This approach ensures that a hyperlink is added at the end of every page in the document. You can modify the hyperlink text and URL as needed.

For more detailed examples and documentation, you can refer to the official Aspose documentation or the provided code examples on GitHub.

Sources:
[1]: AsposeAddHyperlink.java

@hrnallap You can insert hyperlink into the document’s footer. In this can there be a hyperlink at the end of each page. Is this what you are trying to achieve? If not, please attach your input and expected output documents. We will check them and provide you more information.