Bookmark page location

1 Answer 169 Views
PdfProcessing
Steffen
Top achievements
Rank 1
Iron
Steffen asked on 11 Jan 2022, 11:59 AM

Hi.

I am attempting to create bookmark for several blocks on several pages, to create a Table of Content. Each page can contain more than one block. When reading your documents I have found this:

Location location = new Location();
location.Page = document.Pages.Last(); // The issue
location.Left = 10;
location.Top = 10;
BookmarkItem bookmark = new BookmarkItem(titleString, location);
bookmark.IsExpanded = true;
document.Bookmarks.Add(bookmark);

This works creating a ToC with the help of this method:

private static void ToC()
{
	RadFixedPage toc = new RadFixedPage();
	document.Pages.Insert(1, toc);

	FixedContentEditor editor = new FixedContentEditor(toc);
	int offSetVal = 0;

	foreach (BookmarkItem bookmark in document.Bookmarks)
	{
		int pageNumber = 1;

		if (pageNumber > 0)
		{
			int factor = 20;

			int offsetX = 70;
			int offsetY = offSetVal + 20 + factor * pageNumber;
			offSetVal += 10;
			editor.Position.Translate(offsetX, offsetY);

			Block block = new Block();
			block.InsertLineBreak();
			block.GraphicProperties.FillColor = new RgbColor(255, 5, 99, 193);
			block.InsertText(bookmark.Title);
			Size blockSize = block.Measure();
			editor.DrawBlock(block);


			var location = bookmark.Destination;
			GoToAction goToAction = new GoToAction();
			goToAction.Destination = location;

			Link uriLink = toc.Annotations.AddLink(goToAction);
			uriLink.Rect = new Rect(offsetX, offsetY, blockSize.Width, blockSize.Height);
		}
	}
}

The problem is that each action links to the same page. When debugging I can also see that "document.Pages.Last()" has the same value. How can I make it so the correct page is connected?

PS: Please let me know if any value is needed.

Thanks

-Steffen

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 13 Jan 2022, 08:09 AM

Hello Steffen,

You can specify the page by using its index like this: 

Location location = new Location();
location.Page = document.Pages[1]; 

I addition, I have created a small example that shows how you can add bookmarks for 3 different pages. 

I hope this helps. Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
PdfProcessing
Asked by
Steffen
Top achievements
Rank 1
Iron
Answers by
Dimitar
Telerik team
Share this question
or