HTML JPG PDF XML DOCX
  Product Family
PDF

Replace Links in PDF via Go SDK

API for replacing Links in PDF documents with Aspose.PDF Cloud Go SDK

Get Started

How to replace Links in PDF documents using Cloud Go SDK

For replacing Links in PDF documents, we’ll use Aspose.PDF Cloud Go SDK This Cloud SDK SDK assists Go programmers in developing cloud-based PDF creator, annotator, editor, and converter apps using Go programming language via Aspose.PDF REST API. Use the following command from the Package Manager Console.

Package Manager Console Command


     
    go get -u github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25
     
     

Steps to replace Links using Go

Aspose.PDF Cloud Go developers can easily replace Links in PDF documents. Developers need just a few lines of code.

  1. Retrieve the existing link annotation from the PDF document.
  2. Extract the existing link annotations and display them.
  3. Create a new link object.
  4. Update the link annotation in the PDF document.
  5. Download the updated PDF document.

Note: when replacing links, we change their color to show the changed hyperlink.

 

This sample code shows replacing Links in PDF document using PDF Cloud Go SDK


    package main

    import (
        "fmt"

        asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25"
    )

    func replaceLink(pdf_api *asposepdfcloud.PdfApiService, document string, output_document string, link_id string, link_action string, remote_folder string) {
        uploadFile(pdf_api, document)

        args := map[string]interface{}{
            "folder": remote_folder,
        }

        result, httpResponse, err := pdf_api.GetLinkAnnotation(document, link_id, args)
        if err != nil {
            fmt.Println(err.Error())
        } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 {
            fmt.Println("Unexpected error!")
        } else {
            links := []asposepdfcloud.LinkAnnotation{*result.Link}
            showLinks(&links)

            link := asposepdfcloud.Link{Href: link_action}

            link_annotation := asposepdfcloud.LinkAnnotation{
                Links:        []asposepdfcloud.Link{link},
                ActionType:   asposepdfcloud.LinkActionTypeGoToURIAction,
                Action:       link_action,
                Highlighting: asposepdfcloud.LinkHighlightingModeInvert,
                Color:        &asposepdfcloud.Color{A: 0xFF, R: 0xAA, G: 0x00, B: 0x00},
                Rect:         result.Link.Rect,
            }

            result2, httpResponse, err := pdf_api.PutLinkAnnotation(PDF_DOCUMENT, result.Link.Id, link_annotation, args)
            if err != nil {
                fmt.Println(err.Error())
            } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 {
                fmt.Println("Unexpected error!")
            } else {
                fmt.Println(result2)

                downloadFile(pdf_api, document, output_document)
            }
        }
    }
 

Work with Links in PDF

By regularly reviewing and updating the hyperlinks in your PDF documents, you can maintain their relevance, accuracy, and security, thereby providing a better experience for your readers. Replace the Links in PDF documents with Aspose.PDF Cloud Go SDK.

With our Go library you can:

  • Add PDF document’s header & footer in text or image format.
  • Add tables & text or image stamps to PDF documents.
  • Append multiple PDF documents to an existing file.
  • Work with PDF attachments, annotations, & form fields.
  • Apply encryption or decryption to PDF documents & set a password.
  • Delete all stamps & tables from a page or entire PDF document.
  • Delete a specific stamp or table from the PDF document by its ID.
  • Replace single or multiple instances of text on a PDF page or from the entire document.
  • Extensive support for converting PDF documents to various other file formats.
  • Extract various elements of PDF files & make PDF documents optimized.
  • You can try out our free App to test the functionality online.

  •