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.

Mon May 08, 2017 10:33 pm

Hi,
I have a table in my database that includes the page numbers of combined pdf files.
I want to open the combined pdf file and add bookmarks using those page numbers.
Here is the code I've used:
{
string strTitle = ledger._strDocName;
int intDocIndex = ledger._intDocIndex;
PdfDestination pdfDocsDest = new PdfDestination(intDocIndex, new PointF(0,y),0);
PdfBookmark pdfDocsBM = thisDoc.Bookmarks.Add(strTitle);
pdfDocsBM.Color = Color.Blue;
pdfDocsBM.DisplayStyle = PdfTextStyle.Bold;
pdfDocsBM.Action = new PdfGoToAction(pdfDocsDest);
y = y + 5;

}
The bookmarks are being generated but if I look at pdfDocsBM.Action.Destination, the PageNumber property is correct, but the Page is Null.
Once all bookmarks have been created, all the bookmarks are pointed to page 1.
I've uploaded a screenshot of the properties
Thanks,
Rob

saskpower
 
Posts: 8
Joined: Mon Apr 03, 2017 2:40 pm

Tue May 09, 2017 5:34 am

Dear saskpower,

Thanks for your inquiry.
Please use the method PdfDestination(PdfPageBase page, PointF location) to create bookmark, and here is sample code to add known page numbers to bookmark.
Code: Select all
            string strTitle = ledger._strDocName;;
            int intDocIndex = ledger._intDocIndex;
            PdfPageBase page = doc.Pages[intDocIndex - 1];
            PdfDestination pdfDocsDest = new PdfDestination(page, new PointF(0, 10));
            PdfBookmark pdfDocsBM = doc.Bookmarks.Add(strTitle);
            pdfDocsBM.Color = Color.Blue;
            pdfDocsBM.DisplayStyle = PdfTextStyle.Bold;
            pdfDocsBM.Action = new PdfGoToAction(pdfDocsDest);

If there is any question, please let me know.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Tue May 09, 2017 7:12 pm

That worked well Betsy.
Thanks very much.
Warmest Regards,
Rob

saskpower
 
Posts: 8
Joined: Mon Apr 03, 2017 2:40 pm

Wed May 10, 2017 1:28 am

Dear Rob,

Thanks for your feedback.
Please feel free to contact us if you have any question.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.PDF