Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
Questions about Android development and PDF
  • Page:
  • 1
  • 2

TOPIC:

Search regular expression in pdf 6 years 3 months ago #13353

  • sivus
  • sivus's Avatar
  • Offline
  • New Member
  • New Member
  • Posts: 3
  • Thank you received: 0
OK, I can do the searching on my own, but I need to navigate and highlight the exact text on pdf page (like you do with m_reader.PDFFind();). How can I accomplish that?

Please Log in or Create an account to join the conversation.

Search regular expression in pdf 6 years 3 months ago #13354

  • Davide
  • Davide's Avatar
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 814
  • Thank you received: 65
Hi,
We suggest you to save the page and the start char index of the search results.

Then to be able to highlight them, you can add the following method to OnPageDisplayed listener
private void highlightResults(Canvas canvas){
        Paint mSearchPaint = new Paint();
        mSearchPaint.setARGB((Global.findPrimaryColor>>24)&0xFF, (Global.findPrimaryColor>>16)&0xFF, (Global.findPrimaryColor>>8)&0xFF,
                Global.findPrimaryColor&0xFF );
        mSearchPaint.setStyle(Paint.Style.FILL);
        float[] mSearchDrawRect = new float[4];
        VPage vPage = m_layout.vGetPage(PDFGetCurrPage());
        mSearchDrawRect[0] = vPage.GetVX(mSearchRect[0]) - m_layout.vGetX();
        mSearchDrawRect[1] = vPage.GetVY(mSearchRect[3]) - m_layout.vGetY();
        mSearchDrawRect[2] = vPage.GetVX(mSearchRect[2]) - m_layout.vGetX(
);
        mSearchDrawRect[3] = vPage.GetVY(mSearchRect[1]) - m_layout.vGetY();
        canvas.drawRect(mSearchDrawRect[0], mSearchDrawRect[1], mSearchDrawRect[2], mSearchDrawRect[3],
                mSearchPaint);
    }

To be able to calculate mSearchRect (the rect of the word to highlight) you can take as a reference the below method (it's used in the demo project when PDFFind is called)

private void find_draw( Canvas canvas, VPage page, int index, Paint paint, int scrollx, int scrolly )
	{
		int ichar = m_finder.GetFirstChar(index);
		int ichar_end = ichar + m_str.length();

		float rect[] = new float[4];
		float rect_word[] = new float[4];
		float rect_draw[] = new float[4];
		m_page.ObjsGetCharRect(ichar, rect);
		rect_word[0] = rect[0];
		rect_word[1] = rect[1];
		rect_word[2] = rect[2];
		rect_word[3] = rect[3];
		ichar++;
		while( ichar < ichar_end )
		{
			m_page.ObjsGetCharRect(ichar, rect);
			float gap = (rect[3] - rect[1])/2;
			if( rect_word[1] == rect[1] && rect_word[3] == rect[3] &&
				rect_word[2] + gap > rect[0] && rect_word[0] - gap < rect[2] )
			{
				if( rect_word[0] > rect[0] ) rect_word[0] = rect[0];
				if( rect_word[2] < rect[2] ) rect_word[2] = rect[2];
			}

else
			{
				rect_draw[0] = page.GetVX(rect_word[0]) - scrollx;
				rect_draw[1] = page.GetVY(rect_word[3]) - scrolly;
				rect_draw[2] = page.GetVX(rect_word[2]) - scrollx;
				rect_draw[3] = page.GetVY(rect_word[1]) - scrolly;
				canvas.drawRect(rect_draw[0], rect_draw[1], rect_draw[2], rect_draw[3], paint);
				rect_word[0] = rect[0];
				rect_word[1] = rect[1];
				rect_word[2] = rect[2];
				rect_word[3] = rect[3];
			}
			ichar++;
		}
		rect_draw[0] = page.GetVX(rect_word[0]) - scrollx;
		rect_draw[1] = page.GetVY(rect_word[3]) - scrolly;
		rect_draw[2] = page.GetVX(rect_word[2]) - scrollx;
		rect_draw[3] = page.GetVY(rect_word[1]) - scrolly;
		canvas.drawRect(rect_draw[0], rect_draw[1], rect_draw[2], rect_draw[3], paint);
	}

Please Log in or Create an account to join the conversation.

Search regular expression in pdf 6 years 3 months ago #13359

  • sivus
  • sivus's Avatar
  • Offline
  • New Member
  • New Member
  • Posts: 3
  • Thank you received: 0
OK, thanks! How can I find out actual displayed page in PDFReaderAct after I scroll the page using swipe? I cannot find any refference of ViewSwitcher or method PDFGetCurrPage().

Please Log in or Create an account to join the conversation.

Search regular expression in pdf 6 years 2 months ago #13362

  • Davide
  • Davide's Avatar
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 814
  • Thank you received: 65
Hi,
PDFReaderAct is a class from PDFReader that is an old module with some deprecated classes, so I suggest you to use RDPDFReader from the demo, this is a new module that improves the performance, has higher zoom levels, new features and methods.

I suggest you to check PDFViewAct, so you can use PDFGetCurrPage() to get the page after scroll.

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
  • 2
Powered by Kunena Forum