Provide a link in pdf document to another pdf document and linked pdf should open a new instance

We have provide a link in pdf to another pdf document and we are expecting to open it as a new instance but it always open on existing in same pdf and we are not able to go back. I am using the below code to do it.

Using Annotations :

 LinkAnnotation linkAnn = new LinkAnnotation(document.Pages[lastPage], new Aspose.Pdf.Rectangle(document.PageInfo.Margin.Left, 5, 250, 20));
 Border border = new Border(linkAnn);
 border.Width = 1;
 linkAnn.Border = border;
 linkAnn.Action = new LaunchAction(citi.FilePath);
 document.Pages[lastPage].Annotations.Add(linkAnn);

 FreeTextAnnotation textAnnotation = new FreeTextAnnotation(document.Pages[lastPage],
 new Aspose.Pdf.Rectangle(document.PageInfo.Margin.Left, 5, 250, 20),
 new DefaultAppearance(
 Aspose.Pdf.Text.FontRepository.FindFont("TimesNewRoman"),
 10, System.Drawing.Color.Blue));
             textAnnotation.Contents = "Click here to open the full document";

 // Set same border as used for link annotation
 textAnnotation.Border = border;
 document.Pages[lastPage].Annotations.Add(textAnnotation);

Using File HyperLink :
TextFragment t1 = new TextFragment("Click here to open the document");
t1.Position = new Position(document.PageInfo.Margin.Left, document.PageInfo.Margin.Bottom);  //new Position(document.PageInfo.Margin.Left, yIndent);
                      





FileHyperlink f1 = new FileHyperlink();

f1.Path = citi.FilePath;
t1.Hyperlink = f1;
t1.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.FromArgb(0,0,238)) ;

//t1.TextState.DrawTextRectangleBorder = true;
t1.TextState.Underline = true;

Thanks

@CRAsposeUser

Is it possible for you to share the sample PDF document along with the generated output? We will further proceed with logging an investigation ticket and share the ID with you.

@CRAsposeUser

Could you please try this:

//var licensePath = @"C:\Keys\Aspose.PDF.NET.lic";
//new Aspose.Pdf.License().SetLicense(licensePath);

// Load the PDF file
Document document = new(@"C:\Samples\Sample-Document-01.pdf");
TextFragmentAbsorber textFragmentAbsorber = new();
var page = document.Pages[1];
textFragmentAbsorber.Visit(page);
var textFragment = textFragmentAbsorber.TextFragments
    .First(tf => tf.Text.StartsWith("Headings"));
var linkAnnotation = new LinkAnnotation(page, textFragment.Rectangle)
{
    Action = new LaunchAction(@"C:\Samples\Sample-Document-02.pdf") {
        NewWindow = ExtendedBoolean.True,
    }
};
page.Annotations.Add(linkAnnotation);
// Save updated document
document.Save(@"C:\Samples\Sample-Document-01-test.pdf");

Hi Team,

Thanks for the response. it is working as expected with new window property.
Is there any way we can use FileHyperlink class to open the file in new window ?

Unfortunately, with postprocessing only.

Document document = new();
var page = document.Pages.Add();
var fileHyperlink = new FileHyperlink(@"C:\Samples\Sample-Document-02.pdf");
var textFragment = new TextFragment("Lorem ipsum")
{
    Hyperlink = fileHyperlink
};
page.Paragraphs.Add(textFragment);

// postprocessing code
document.ProcessParagraphs();
foreach (var annotation in page.Annotations.Where(an => an.AnnotationType == AnnotationType.Link))
{
    var actions = annotation.Actions
          .Where(ac => ac.GetType() == typeof(LaunchAction))
          .Cast<LaunchAction>();
    foreach (LaunchAction action in actions)
    {
        action.NewWindow = ExtendedBoolean.True;
    }
}

// Save document
document.Save(@"C:\Samples\Sample-Document-02-test.pdf");

@CRAsposeUser
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFNET-56768

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

The issues you have found earlier (filed as PDFNET-56768) have been fixed in Aspose.PDF for .NET 24.4.