Tue May 28, 2019 7:00 pm
Hi Nina,
I tested the piece of code that you posted, It is duplicating the Bookmarks end not all of the links are working after processed the PDF file.
foreach (PdfPageBase page in document.Pages)
{
PdfPageBase newPage;
if (page.Rotation == PdfPageRotateAngle.RotateAngle90)
newPage = newPdf.Pages.Add(new SizeF(page.Size.Height, page.Size.Width), new PdfMargins(0));
else if (page.Rotation == PdfPageRotateAngle.RotateAngle270)
newPage = newPdf.Pages.Add(new SizeF(page.Size.Height, page.Size.Width), new PdfMargins(0));
else
newPage = newPdf.Pages.Add(page.Size, new PdfMargins(0));
page.CreateTemplate().Draw(newPage, new PointF(0, 0));
//get bookmarks from original pdf
var bms = document.Bookmarks;
for (int w = 0; w < bms.Count; w++)
{
//Add parent bookmark
//PdfDestination vendorBookmarkDest = new PdfDestination(bms[w].Destination.Page, bms[w].Destination.Location);
PdfDestination vendorBookmarkDest = bms[w].Destination;
vendorBookmarkDest.Page = newPage;
PdfBookmark vendorBookmark = newPdf.Bookmarks.Add(bms[w].Title);
vendorBookmark.Color = bms[w].Color;
vendorBookmark.DisplayStyle = bms[w].DisplayStyle;
vendorBookmark.Action = new PdfGoToAction(vendorBookmarkDest);
for (int j = 0; j < bms[w].Count; j++)
{
//Add child bookmark
//PdfDestination partBookmarkDest = new PdfDestination(bms[w][j].Destination.Page, bms[w][j].Destination.Location);
PdfDestination partBookmarkDest = bms[w][j].Destination;
partBookmarkDest.Page = newPage;
PdfBookmark partBookmark = vendorBookmark.Add(bms[w][j].Title);
partBookmark.Color = bms[w][j].Color;
partBookmark.DisplayStyle = bms[w][j].DisplayStyle;
partBookmark.Action = new PdfGoToAction(partBookmarkDest);
}
}
Take a look in the attached files.
Thank You
Login to view the files attached to this post.
Thank You