Skip to main content
Known Participant
August 12, 2023
Question

Displaying the page a phrase found on is not working as expected.

  • August 12, 2023
  • 0 replies
  • 165 views

I am using C# with the SDK's IAC to display the page a phrase is found on.  Highlighting the phrase is a requirement.  My program works but it does not work the way I though it would and was wondering why and if there is a better wat to do it.

private CAcroAVPageView ThisDocView;
private AcroAVDoc ThisDoc = null;

private void OpenPdf(string filename)
{
	ThisDoc = new AcroAVDoc();
        ThisDoc.Open(filename, "");
}

private void ShowPhraseOnPage(int p, string filename, string phrase)
{
	//ThisDoc = new AcroAVDoc();
	//ThisDoc.Open(filename, "");
	ThisDoc.BringToFront();
	ThisDoc.SetViewMode(1); 

	ThisDocView = ThisDoc.GetAVPageView() as CAcroAVPageView;
	ThisDocView.GoTo(p);
	bool bFound = ThisDoc.FindText(Phrase,
		cbIgnoreCase.Checked ? 0 : 1,
		cbWholeWord.Checked ? 1 : 0,
		0);

 

I thought the above code would work:  I first open the PDF and then I change the view to the page that has the phrase to be highlighted.  The document does go to the correct page when the show function is called.  It then immediately switches to the "next" phrase as measured from page 1.  Basically it starts at page 1 and finds all phrases starting from page 1 and forgets about the "goto".

 

If I uncomment the two lines of code, the show function works as intended.  Acrobat positions to the page and highlights the phrase.  There is no need to call the OpenPdf routine.  

 

Why do I needed to open the PDF on every call to show a page?  ls there a better way to do this?

 

There is a benefit to doing the above "open".  If the user inadvertently closes the document my C# program no longer times out trying to position the doc view when the document no longer exists.

This topic has been closed for replies.