Looking for Example code for searching PDF in code. Telerik Example Code gives compile error

1 Answer 117 Views
Form
Roger
Top achievements
Rank 2
Iron
Iron
Iron
Roger asked on 20 Jan 2023, 07:48 PM

I am looking to search many PDF's looking for a certain TEXT and saving the Page# of this text to db table.

While I did find this example on the Telerik Website, it does NOT compile for me.

using Telerik.Windows.Documents.Fixed.FormatProviders.Pdf;
using Telerik.Windows.Documents.Fixed.Model.Editing;
using Telerik.Windows.Documents.Fixed.Search;

 

            int pageBegin = -1;
            var provider = new PdfFormatProvider();
            var document = provider.Import(File.ReadAllBytes(@"Test.pdf"));

            var search = new TextSearch(document);  // I get a compile error here stating TextSearch is inaccessible due to it's protection level.
            var result = search.FindAll("Lorem", TextSearchOptions.Default);

            foreach (var resultItem in result)
            {
                var rect = resultItem.GetWordBoundingRect();
                var page = resultItem.GetResultPage();
                pageBegin = page;
                var editor = new FixedContentEditor(page);
                //editor.DrawRectangle(rect);
            }

            File.WriteAllBytes(@"result.pdf", provider.Export(document));
            return pageBegin;

1 Answer, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 24 Jan 2023, 11:25 AM

Hi Roger,

The text search API was just recently introduced with 2023 R1, so in order to use it the project's assemblies must be up to date. After updating them the project should run as expected.

Examples and documentation for the search functionality of PdfProcessing can be found in the Search article.

Hope that helps and in case you have any other questions, don't hesitate to ask.

Regards, Yoan 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
Form
Asked by
Roger
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Yoan
Telerik team
Share this question
or