Is it possible to convert LaunchAction to URIAction?

Hi Aspose team,

in my scenario I have PDF documents that are pointing to network file which is opened via LaunchAction. After migration to SharePoint, I replaced link from network drive to SharePoint location but LaunchAction will not work any more (I am getting error “Cannot open a file”). Is there any way to convert LaunchAction to GoToURIAction or any type of action where Web address can be opened?

Thx

@dr.doc

Yes, you can convert a LaunchAction to a GoToURIAction in Aspose.PDF. The LaunchAction is designed to open applications or files, which is not suitable for web addresses. To resolve this, you can replace it with a GoToURIAction that points to your SharePoint URL.

Here’s a step-by-step approach to achieve this:

  1. Identify the LaunchAction in your PDF document.
  2. Create a new GoToURIAction with the SharePoint URL.
  3. Replace the LaunchAction with the new GoToURIAction.

Here’s a code snippet to illustrate this:

using Aspose.Pdf;
using Aspose.Pdf.Annotations;

// Load the PDF document
Document pdfDocument = new Document("input.pdf");

// Iterate through the annotations
foreach (var annotation in pdfDocument.Pages[1].Annotations)
{
    if (annotation is LaunchAction launchAction)
    {
        // Create a new GoToURIAction
        var uriAction = new GoToURIAction("https://your-sharepoint-url");

        // Replace the LaunchAction with GoToURIAction
        annotation.Action = uriAction;
    }
}

// Save the updated document
pdfDocument.Save("output.pdf");

Make sure to replace "https://your-sharepoint-url" with your actual SharePoint link. This code will effectively replace any LaunchAction found in the first page of the PDF with a GoToURIAction.

If you have any further questions or need additional assistance, feel free to ask!