CreateLocalLink changing the zoom

I am taking an existing PDF file and adding some local links using the CreateLocalLink() method. It all works fine except that when I click on the link it changes the current zoom value to “Fit One Full Page to Window.” For example, if I set the zoom to 100% and then click on a link, the zoom changes to “Fit One Full Page to Window.” I don’t want it to change to this new zoom value. When I click on the link I want it to stay at the 100% (or whatever the current zoom is) that I had it set to.


Is there a way to maintain the current zoom?

Here is the code:

string outputFile = tbPDFFile5.Text;
Document finalDoc = new Document(outputFile);

var contentEditor = new PdfContentEditor();
contentEditor.BindPdf(finalDoc);

System.Drawing.Rectangle gobackTextRc1 = new System.Drawing.Rectangle(50, 725, 105, 16);
contentEditor.CreateFreeText(gobackTextRc1, “Go Back to Page 1”, 2);

System.Drawing.Rectangle gobackRect1 = new System.Drawing.Rectangle(50, 725, 105, 16);
contentEditor.CreateLocalLink(gobackRect1, 1, 2, System.Drawing.Color.Red);


System.Drawing.Rectangle gobackTextRc2 = new System.Drawing.Rectangle(50, 725, 105, 16);

contentEditor.CreateFreeText(gobackTextRc2, “Go Back to Page 2”, 3);

System.Drawing.Rectangle gobackRect2 = new System.Drawing.Rectangle(50, 725, 105, 16);

contentEditor.CreateLocalLink(gobackRect2, 2, 3, System.Drawing.Color.Red);

outputFile = outputFile.Insert(outputFile.Length - 4, “_2”);
finalDoc.Save(outputFile);

I have attached a sample PDF file showing my dilemma.

Hi Marsha,


Thanks for contacting support.

I have tested the scenario and I am able to
notice the same problem. For the sake of correction, I have logged this issue
as PDFNEWNET-35176 in our issue tracking system. We will
further look into the details of this problem and will keep you updated on the
status of correction. Please be patient and spare us little time.

We are sorry
for this inconvenience.

@MADavis

The described behavior is not a bug. The CreateLocalLink method creates a link that changes the page’s zoom to fit the entire page within the window.

To create a link without changing the zoom, you can use the following code snippet:

static void Main(string[] args)
{
    var input = "input.pdf;
    var output = "output.pdf;

    Document document = new Document(input);
    var contentEditor = new PdfContentEditor();
    contentEditor.BindPdf(document);

    System.Drawing.Rectangle gobackTextRc1 = new System.Drawing.Rectangle(50, 725, 105, 16);
    contentEditor.CreateFreeText(gobackTextRc1, "Go Back to Page 1", 2);
    System.Drawing.Rectangle gobackRect1 = new System.Drawing.Rectangle(50, 725, 105, 16);
    CreateXYZLocalLink(document, gobackRect1, 1, 2, System.Drawing.Color.Red);

    System.Drawing.Rectangle gobackTextRc2 = new System.Drawing.Rectangle(50, 725, 105, 16);
    contentEditor.CreateFreeText(gobackTextRc2, "Go Back to Page 2", 3);
    System.Drawing.Rectangle gobackRect2 = new System.Drawing.Rectangle(50, 725, 105, 16);
    CreateXYZLocalLink(document, gobackRect2, 2, 3, System.Drawing.Color.Red);
    document.Save(output);
}

private static void CreateXYZLocalLink(Document document, System.Drawing.Rectangle rectangle,
    int destinationPage, int originalPage, System.Drawing.Color color)
{
    var link = new LinkAnnotation(document.Pages[originalPage], Aspose.Pdf.Rectangle.FromRect(rectangle));
    link.Color = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Red);
    link.Destination = XYZExplicitDestination.CreateDestinationToUpperLeftCorner(document.Pages[destinationPage]);
    document.Pages[originalPage].Annotations.Add(link);
}