I have a pdf document generated by Spire Office version 8.2.2. This document is generated with a hand built Table of Contents that generates annotations to other pages within the document using the following code:
- Code: Select all
private void CreatePdfAnnotations(PdfDocument tocPdf, Dictionary<PdfLabelValueElement, KeyValuePair<PdfPageBase, float>> pageNumLocations, int startingPageNumberIndex)
{
int pageNumberIndex = startingPageNumberIndex;
for (int i = 0; i < pageNumLocations.Count; i++)
{
// Get both our current TOC item and next TOC item information
var currentPageNumItem = pageNumLocations.ElementAtOrDefault(i);
var nextPageNumItem = pageNumLocations.ElementAtOrDefault((i + 1));
if (currentPageNumItem.Key == null)
continue;
// Declare variables based on keyvalupair values to make the next block more readable
// Page num needs to converted from string to int
int.TryParse(currentPageNumItem.Key.Value.Text, out int currentPageNum);
var page = currentPageNumItem.Value.Key;
float yOffset = currentPageNumItem.Value.Value;
// Create go to action for hyperlinks
var itemBounds = new RectangleF(new PointF(0f, yOffset), new SizeF(page.Canvas.ClientSize.Width, currentPageNumItem.Key.Label.Height));
var dest = new PdfDestination(pageNumberIndex + tocPdf.Pages.Count - 1, new PointF(page.Canvas.ClientSize.Width / 2, page.Canvas.Size.Height), 0);
var action = new PdfActionAnnotation(itemBounds, new PdfGoToAction(dest));
action.Border = new PdfAnnotationBorder(0);
(page as PdfNewPage).Annotations.Add(action);
// Determine the next TOC items page number and re-calculate the page number index by retrieving the difference between the next item's page number and the current item page number
if (nextPageNumItem.Key != null) {
int.TryParse(nextPageNumItem.Key.Value.Text, out int nextPageNum);
pageNumberIndex += (nextPageNum - currentPageNum);
}
}
}
When I download the resulting PDF everything works as expected. However when I view the PDF in Adobe Reader and perform a Save As function, to save it to a new location or change the file name, the annotations built from the code block above in the document appear to be removed in the resulting document.
I'm assuming this is an issue with Spire as bookmarks/annotations created via Adobe Reader appear to be maintained after performing a Save As function.
Please refer to the attached PDF's as a demonstration of the change in metadata after having saved via Adobe.
Please let me know as soon as you can what the solution to this may be.
Thanks,
Zac