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.

Thu Mar 02, 2017 4:48 am

Hello - Is it possible to search for a term and then add a bookmark on the found terms?

Thank you,
Stan

FreeStan
 
Posts: 6
Joined: Thu Feb 23, 2017 5:28 am

Thu Mar 02, 2017 6:12 am

Dear Stan,

Thanks for your inquiry.
Here is sample code for your kind reference.
Code: Select all
            PdfDocument doc = new PdfDocument(@"F:\Sample.pdf");
            PdfTextFind[] result = null;
            foreach (PdfPageBase p in doc.Pages)
            {
                result = p.FindText("word").Finds;
                foreach (PdfTextFind find in result)
                {
                    //get the text position
                    PointF location = find.Position;
                    //add the bookmark according to the position
                    PdfBookmark BookMark = doc.Bookmarks.Add("Bookmark1");
                    PdfDestination BookmarkDest = new PdfDestination(p, location);
                    BookMark.Action = new PdfGoToAction(BookmarkDest);                   
                }
            }
            doc.SaveToFile("9922.pdf", FileFormat.PDF);

Hope this can help. 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 Mar 07, 2017 7:06 am

Dear Stan,

Did you test the code I provided ? Did it help you solve your issue ?
We will appreciate it if you could give us some feedback.

Thanks,
Betsy
E-iceblue support team
User avatar

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

Return to Spire.PDF

cron