- Posts: 3
- Thank you received: 0
Microsoft Windows Phone 8.1 support ends (13 Jul 2017)
Microsoft has ended support for Windows Phone 8.1
Questions about Android development and PDF
Search regular expression in pdf
IP: 192.168.0.71
8 years 2 months ago #13353
by sivus
Replied by sivus on topic Search regular expression in pdf
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?
IP: 192.168.0.71
8 years 2 months ago #13354
by Davide
Replied by Davide on topic Search regular expression in pdf
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
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)
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
Code:
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)
Code:
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);
}
IP: 192.168.0.71
8 years 2 months ago #13359
by sivus
Replied by sivus on topic Search regular expression in pdf
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().
IP: 192.168.0.71
8 years 2 months ago #13362
by Davide
Replied by Davide on topic Search regular expression in pdf
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.
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.
Time to create page: 0.353 seconds