To add a hyperlink annotation at the bottom right of a PDF page with a margin of 10 units from both sides, you can calculate the position of the rectangle based on the page dimensions. Here’s how you can do it in C#:
First, determine the width and height of the page.
Calculate the rectangle’s coordinates for the hyperlink annotation by subtracting the desired margins from the page dimensions.
Here’s a sample code snippet to achieve this:
using System;
using Aspose.Pdf;
using Aspose.Pdf.Annotations;
namespace AsposePdfExample
{
public class AddHyperlink
{
public static void Run()
{
// Open the document
Document document = new Document("input.pdf");
Page page = document.Pages[1];
// Get the page dimensions
float pageWidth = page.Rect.Width;
float pageHeight = page.Rect.Height;
// Define margins
float margin = 10;
// Calculate the rectangle for the hyperlink annotation
float llx = pageWidth - margin; // Lower-left x
float lly = margin; // Lower-left y
float urx = pageWidth; // Upper-right x
float ury = pageHeight - margin; // Upper-right y
// Create the link annotation
LinkAnnotation link = new LinkAnnotation(page, new Aspose.Pdf.Rectangle(llx, lly, urx, ury));
link.Action = new GoToURIAction("http://www.aspose.com");
// Add the link annotation to the page
page.Annotations.Add(link);
// Save the updated document
document.Save("output.pdf");
Console.WriteLine("Hyperlink added successfully.");
}
}
}
In this code:
The rectangle for the hyperlink is defined using the calculated coordinates based on the page dimensions and the specified margins.
Make sure to adjust the input and output file paths as necessary. This will place the hyperlink annotation at the bottom right corner of the page with a 10-unit margin from both the right and bottom edges.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.