How to create remote GoTo action in ASP.NET Core PDF using C#?
The Syncfusion Essential® PDF is a feature-rich and high performance .NET PDF library used to create, read, and edit PDF documents programmatically without Adobe dependencies. Using this library, you can set the remote goto action for the link annotation in a PDF document using C#.
Steps to add remote goto action for the link annotation in a PDF document programmatically:
- Create a new console application project.
- Install the Syncfusion.Pdf.Net.Core NuGet package as a reference to your console application from Nuget.org.
- Include the following namespaces in the Program.cs file.
C#
using Syncfusion.Pdf;
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Interactive;
Imports Syncfusion.Pdf
Imports Syncfusion.Pdf.Parsing
Imports Syncfusion.Pdf.Interactive
- Use the following code sample in Program.cs to set the remote goto action for the link annotation in a PDF document.
C#
// Open the PDF document from a file stream
PdfLoadedDocument document = new PdfLoadedDocument(File.OpenRead(@../../../"Invoice.pdf"));
// Access the first page of the loaded document
PdfLoadedPage page = document.Pages[0] as PdfLoadedPage;
// Create a URI annotation at specified coordinates on the page
PdfUriAnnotation uriAnnotation = new PdfUriAnnotation(new Syncfusion.Drawing.RectangleF(100, 160, 100, 20));
// Set the text for the URI annotation
uriAnnotation.Text = "Uri Annotation";
// Set the border for the URI annotation
uriAnnotation.Border = new PdfAnnotationBorder(1);
// Set the URI (destination) that the annotation will link to
uriAnnotation.Uri = "HeaderAndFooter.pdf";
// Create a new remote destination for navigation
PdfRemoteDestination remoteDestination = new PdfRemoteDestination();
// Set the remote page number to navigate the remove file page
remoteDestination.RemotePageNumber = 5;
// Set the mode for the destination (here, it's set to fit the page)
remoteDestination.Mode = PdfDestinationMode.FitToPage;
//Create a new PdfRemoteGoToAction
PdfRemoteGoToAction goToAction = new PdfRemoteGoToAction("HeaderAndFooter.pdf", remoteDestination);
//Set the IsNewWindow
goToAction.IsNewWindow = true;
//Add the action to the link annotation
uriAnnotation.Action = goToAction;
page.Annotations.Add(uriAnnotation);
//Save the document into stream
MemoryStream stream = new MemoryStream();
document.Save(stream);
//Close the document
document.Close(true);
File.WriteAllBytes("Output.pdf", stream.ToArray());
'Open the PDF document from a file stream
Dim document As New PdfLoadedDocument(File.OpenRead("Invoice.pdf"))
'Access the first page of the loaded document
Dim page As PdfLoadedPage = TryCast(document.Pages(0), PdfLoadedPage)
'Create a URI annotation at specified coordinates on the page
Dim uriAnnotation As New PdfUriAnnotation(New RectangleF(100, 160, 100, 20))
'Set the text for the URI annotation
uriAnnotation.Text = "Uri Annotation"
'Set the border for the URI annotation
uriAnnotation.Border = New PdfAnnotationBorder(1)
'Set the URI (destination) that the annotation will link to
uriAnnotation.Uri = "HeaderAndFooter.pdf"
'Create a new remote destination
Dim remoteDestination As New PdfRemoteDestination()
remoteDestination.RemotePageNumber = 5
remoteDestination.Mode = PdfDestinationMode.FitToPage
'Create a new PdfRemoteGoToAction
Dim goToAction As New PdfRemoteGoToAction("HeaderAndFooter.pdf", remoteDestination)
'Set the IsNewWindow property
goToAction.IsNewWindow = True
'Add the action to the URI annotation
uriAnnotation.Action = goToAction
page.Annotations.Add(uriAnnotation)
'Save the document into a memory stream
Dim stream As New MemoryStream()
document.Save(stream)
stream.Position = 0
File.WriteAllBytes("Output.pdf", stream.ToArray())
'Close the document
document.Close(True)
A complete working sample can be downloaded from Remote_Goto_action_link_annotation.zip
By executing the program, you will get the PDF document as follows.
Take a moment to peruse the documentation, where you can find other options like adding annotation to PDF, flatten annotation, modifying annotation, and removing annotation with code examples.
Refer here to explore the rich set of Syncfusion Essential® PDF features.
Conclusion
I hope you enjoyed learning about how to create remote GoTo action in ASP.NET Core PDF using C#.
You can refer to our ASP.NET Core PDF feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our ASP.NET Core PDF example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!