Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Fri Jan 26, 2018 6:33 pm

Hy,
Merge document page by page and then copy bookmarks. The new Bookmark location is shifted / misplaced.

Function used to copy bookmark.

Code: Select all
// doc - new document
// odocbooks - new document bookmarks
// offset - Page Offset
// books - bookmark to copy
 private static void CopyBookmark(PdfDocument doc, PdfBookmarkCollection  odocbooks,int offset, PdfBookmarkCollection books)
            {
                foreach (PdfBookmark _cbook in books)
                {
                    int _cpos = _cbook.Destination.Page.Document.Pages.IndexOf(_cbook.Destination.Page);
                    PdfBookmark _book = odocbooks.Add(_cbook.Title);
                    PdfDestination _destination = new PdfDestination(doc.Pages[_cpos + offset], _cbook.Destination.Location);
                    _book.DisplayStyle = _cbook.DisplayStyle;
                    //_book.Action = new PdfGoToAction(_destination);
                    _book.Destination = _destination;
                    _book.Destination.Mode = _cbook.Destination.Mode;
                    _book.Color = _cbook.Color;
                    if (_cbook.Count > 0)
                    {
                        CopyBookmark(doc,_book, offset, _cbook);
                    }
                }
            }



Thanks,
JD

aibizcore
 
Posts: 12
Joined: Fri Dec 29, 2017 12:12 pm

Mon Jan 29, 2018 6:30 am

Hello JD,

Thanks for your inquiry.
Generally, the bookmarks would also be copied when merging documents, and there seems no need to copy the bookmarks separately. Besides, I could get the correct result using your code. To help us reproduce your issue, could you please send the sample documents and the complete code snippet including the document merging part to us([email protected])? If you could specify your case in detail and provide a screenshot to demonstrate the problem, that couldn't be better.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Return to Spire.PDF