Link tool is shifting links to different areas of the page & changing properties

Hi,

we are trying to add a Hyperlink with GoToR action in below attached document. After saving the links are getting shifted i.e., dimension gets varied from passed value to the function. Kindly help us to resolve this issue.

page35.pdf (864.5 KB)
image-2023-01-18-16-22-16-848.jpg (241.7 KB)
image-2023-01-18-16-21-48-802.jpg (351.1 KB)

@prnksheela
Please provide a code snippet that you use for this purpose.

private void Logic()
{
// Open document
Document doc = new Document();

// Create link
Page page = doc.Pages.Add();

//Create Rectangle Object
var rectangle = new Aspose.Pdf.Rectangle(20, 500, 120, 600);

// Create Link annotation object
LinkAnnotation linkFile = new LinkAnnotation(page, rectangle);

linkFile .Color = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Black);

linkFile.Action = new GoToRemoteAction($"{PartialPath}_link.pdf", 1);

page.Annotations.Add(linkFile);

// Save updated document
doc.Save($"{PartialPath}_output.pdf");

}

After saving links shifted from the original place, for this specific file.

@prnksheela
I apologize for the delay.
What is the significance of PartialPath in the code you provided?

It is the directory that we are providing.

Can you check once, PDFNET-55186 is related to this?

@prnksheela
I do not really understand what you wanted (and, accordingly, what did not work out for you).
For the given code: do you have in PartialPath a file to which you make a link with the line
linkFile.Action = new GoToRemoteAction($"{PartialPath}_link.pdf", 1);
?

I ran my own code:

string PartialPath = "f:\\2\\";

// Open document
Document doc = new Document();
// Create link
Page page = doc.Pages.Add();

//Create Rectangle Object
var rectangle = new Aspose.Pdf.Rectangle(20, 500, 120, 600);

// Create Link annotation object
LinkAnnotation linkFile = new LinkAnnotation(page, rectangle);

linkFile.Color = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Black);

//string linkedFileName = $"{PartialPath}_link.pdf";
string linkedFileName = PartialPath + "page35.pdf";
linkFile.Action = new GoToRemoteAction(linkedFileName, 1);

page.Annotations.Add(linkFile);

// Save updated document
doc.Save($"{PartialPath}_output.pdf");

and in PartialPath a file “_output.pdf” was created in which there is a Link Annotation, when clicked, the transition to the file “page35.pdf” takes place (I also set the file “page35.pdf” in PartialPath).

If I misunderstood the problem, please explain in more detail.

I am selecting particular dimension for the hyperlink, as in the example. But after saving through code and opened the file, it seems the dimension is varied from given value. Kindly check the scenario and let me know, why link is shifting?

@prnksheela
I used the code below to test. It displays the size of the MediaBox (page) and additionally adds a LinkAnnotation in the corners.

Document doc = new Document();
// Create link
Page page = doc.Pages.Add();

//Create Rectangle Object
var rectangle = new Aspose.Pdf.Rectangle(20, 500, 120, 600);
// Create Link annotation object
LinkAnnotation linkFile = new LinkAnnotation(page, rectangle)
{
    Color = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Black)
};

page.Annotations.Add(linkFile);

Console.WriteLine($"page.MediaBox:{page.MediaBox}");

var rectangle1 = new Aspose.Pdf.Rectangle(0, 0, 100, 10);
var rectangle2 = new Aspose.Pdf.Rectangle(0, page.MediaBox.URY - 10, 100, page.MediaBox.URY);
var rectangle3 = new Aspose.Pdf.Rectangle(page.MediaBox.URX - 100, 0, page.MediaBox.URX, 10);
var rectangle4 = new Aspose.Pdf.Rectangle(page.MediaBox.URX - 100, page.MediaBox.URY - 10, page.MediaBox.URX, page.MediaBox.URY);

var la1 = new LinkAnnotation(page, rectangle1)
{
    Color = Aspose.Pdf.Color.Blue
};
var la2 = new LinkAnnotation(page, rectangle2)
{
    Color = Aspose.Pdf.Color.Red
};
var la3 = new LinkAnnotation(page, rectangle3)
{
    Color = Aspose.Pdf.Color.Purple
};
var la4 = new LinkAnnotation(page, rectangle4)
{
    Color = Aspose.Pdf.Color.Orange
};
page.Annotations.Add(la1);
page.Annotations.Add(la2);
page.Annotations.Add(la3);
page.Annotations.Add(la4);

doc.Save(myDir + "out.pdf");

Everything looks right
Out.png (35.5 KB)
Perhaps you did not take into account that the Y-axis in this case comes from the bottom of the page and is directed upwards.