Unable to update destination action in existing bookmark

Hi,

I am trying to update update destination action in a existing bookmark as below code snippets,
First solution:
Aspose.Pdf.License license = new Aspose.Pdf.License();
license.SetLicense(“Aspose.Pdf.lic”);
Aspose.Pdf.Document targetDoc = null;
targetDoc = new Aspose.Pdf.Document(tempRepoDocumentPath);
List originalOutlineItems = new List(targetDoc.Outlines);
targetDoc.Outlines.Delete();

foreach (OutlineItemCollection outlineItemCollection in originalOutlineItems)
{
try
{
if (outlineItemCollection.Action != null && outlineItemCollection.Action is GoToRemoteAction)
{
string bookmarkfilepath = (outlineItemCollection.Action as GoToRemoteAction).File.Name;
string extractedValue1 = “0000”;
string AbsolutePath = bookmarkfilepath.Remove(bookmarkfilepath.IndexOf(extractedValue1), extractedValue1.Length).Insert(bookmarkfilepath.IndexOf(extractedValue1), value);

        GoToRemoteAction goToRemoteAction = (GoToRemoteAction)outlineItemCollection.Action;
        GoToRemoteAction newGoToRemoteAction = new GoToRemoteAction(AbsolutePath, (XYZExplicitDestination)goToRemoteAction.Destination);
        outlineItemCollection.Action = newGoToRemoteAction;
        targetDoc.Outlines.Add(outlineItemCollection);
    }
}
catch (Exception ex)
{
}

}
targetDoc.Save(tempRepoDocumentPath);
Second Solution:
Aspose.Pdf.License license = new Aspose.Pdf.License();
license.SetLicense(“Aspose.Pdf.lic”);
Aspose.Pdf.Document targetDoc = null;
Aspose.Pdf.Document newDocument = new Aspose.Pdf.Document(tempRepoDocumentPath);
targetDoc = new Aspose.Pdf.Document(tempRepoDocumentPath);
newDocument.Outlines.Delete();

foreach (OutlineItemCollection outlineItemCollection in targetDoc.Outlines)
{
try
{
if (outlineItemCollection.Action != null && outlineItemCollection.Action is GoToRemoteAction)
{
string bookmarkfilepath = (outlineItemCollection.Action as GoToRemoteAction).File.Name;
string extractedValue1 = “0000”;
string AbsolutePath = bookmarkfilepath.Remove(bookmarkfilepath.IndexOf(extractedValue1), extractedValue1.Length).Insert(bookmarkfilepath.IndexOf(extractedValue1), value);

        GoToRemoteAction newGoToRemoteAction = new GoToRemoteAction(AbsolutePath, (XYZExplicitDestination)(outlineItemCollection.Action as GoToRemoteAction).Destination);
        
        outlineItemCollection.Action = newGoToRemoteAction;
        newDocument.Outlines.Add(outlineItemCollection);
    }
}
catch (Exception ex)
{

}

}
newDocument.Save(tempRepoDocumentPath);

The bookmark got deleted, but not added after the destination value is updated.
Kindly let us know what is the issue.
Please find the document, which we are using to update the destination from “0001” to “0000”. coge-f-2001 (1).pdf (352.0 KB)

@prnksheela

It looks like you have shared an output PDF document. Can you please share respective source PDF as well? Also, can you please try using 23.7 version of the API as well? In case issue still persists, please let us know.

Could you please let me know sample API call, also attaching source file for reference.a-house-of-pomegranates.pdf (442.0 KB)

@prnksheela

We used your code snippet with both PDF files that you shared but we could not properly run the scenario. The program never enters in the below condition:

if (outlineItemCollection.Action != null && outlineItemCollection.Action is GoToRemoteAction)

Furthermore, below is a sample code snippet to update the action in existing bookmark:

// Open document
Document pdfDocument = new Document(dataDir + "coge-f-2001 (1).pdf");

// Get the bookmark that you want to update by index or title
OutlineItemCollection bookmark = pdfDocument.Outlines[0]; // First bookmark
                                                          // OutlineItemCollection bookmark = pdfDocument.Outlines["Bookmark 1"]; // Bookmark with title "Bookmark 1"

// Create a new GoToAction object and specify the destination page and location
GoToAction action = new GoToAction();
action.Destination = new XYZExplicitDestination(pdfDocument.Pages[2], 100, 100, 1); // Page 2, x = 100, y = 100, zoom = 1

// Assign the new GoToAction object to the Action property of the bookmark
bookmark.Action = action;

// Save updated document
pdfDocument.Save(dataDir + "UpdateBookmark_out.pdf");

Can you please share the code snippet or respective document that we can use and try to replicate the same issue that you are facing?

Hi,

In our requirement, we have some document with external bookmarks i.e., gotor bookmarks at path For example, dataDir+ “original\0001\coge-f-2001 (1).pdf” and the gotor bookmark points to the path For example,"…\0002\ a-house-of-pomegranates.pdf".

When we clone the source document, we are copying the destination document to the same path as well for example: source file is cloned at dataDir+ “cloned\0000\coge-f-2001 (1).pdf” and the the file where initially it was pointing now moved to “…\0000\ a-house-of-pomegranates.pdf”

so here we are trying to update the path of bookmark from “…\0002\ a-house-of-pomegranates.pdf” to “…\0000\ a-house-of-pomegranates.pdf”.

But it is not updating the path, we have tried below snippet as well

Aspose.Pdf.License license = new Aspose.Pdf.License();
license.SetLicense(“Aspose.Pdf.lic”);
Aspose.Pdf.Document targetDoc = null;
targetDoc = new Aspose.Pdf.Document(“f:\cloned\0000\coge-f-2001 (1).pdf”);

foreach (OutlineItemCollection bookmark in targetDoc.Outlines)
{
if (bookmark.Action != null && bookmark.Action is GoToRemoteAction)
{
string bookmarkfilepath = (bookmark.Action as GoToRemoteAction).File.Name;
string extractedValue1 = “0000”;
string AbsolutePath = bookmarkfilepath.Remove(bookmarkfilepath.IndexOf(extractedValue1), extractedValue1.Length).Insert(bookmarkfilepath.IndexOf(extractedValue1), value);

GoToRemoteAction goToRemoteAction = (GoToRemoteAction)bookmark.Action;
GoToRemoteAction newGoToRemoteAction = new GoToRemoteAction(AbsolutePath, (XYZExplicitDestination)goToRemoteAction.Destination);
bookmark.Action = newGoToRemoteAction;
}
}
targetDoc.Save(“f:\test\cloned\0000\coge-f-2001 (1).pdf”);

Please help us to resolve this.

@prnksheela

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-55254

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.