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

update page after annotation was insert/removed

More
9 years 11 months ago - 9 years 11 months ago #10490 by mineusdev
Hi, my current code
Code:
final Page currentPage = doc.GetPage(pageNumber); currentPage.ObjsStart(); //Remove possible previous highlights. for (int i = 0; i < currentPage.GetAnnotCount(); i++) { final Page.Annotation pageAnnotation = currentPage.GetAnnot(i); pageAnnotation.RemoveFromPage(); } if (pageHolder.searchedQuery != null) { final Page.Finder mFinder = currentPage.FindOpen(pageHolder.searchedQuery, false, false); if (mFinder != null) { int finds = mFinder.GetCount(); Log.debug("PDF current page " + pageNumber + " found " + finds + " searchString=" + pageHolder.searchedQuery); for (int j = 0; j < finds; j++) { int foundIndex = mFinder.GetFirstChar(j); int phraseEndIndex = foundIndex + pageHolder.searchedQuery.length(); // Log.debug("PDF phrase " + currentPage.ObjsGetString(foundIndex, phraseEndIndex)); currentPage.AddAnnotMarkup(foundIndex, phraseEndIndex, 0); } mFinder.Close(); } } currentPage.Close();

Now the problems, I cannot use PDFView.GetPage() because that is null very often, so I have to use the page from the Document, but then I cannot call PDFView.vRenderAsync() because it accepts only PDFVPage and not Page.

Also let me express my endless pleasure to work with your code. The one who wrote it never ever heard about how java code should be written nor about any conventions. Using underscores, camel case with methods starting uppercase and for example this onDraw code from your view class, it is just pure excitement to try to debug that code
Code:
if( m_pages == null ) return; //long rec_time = System.currentTimeMillis(); int left = m_scroller.getCurrX(); int top = m_scroller.getCurrY(); int left1 = left; int top1 = top; if( left1 > m_docw - m_w ) left1 = m_docw - m_w; if( left1 < 0 ) left1 = 0; if( top1 > m_doch - m_h ) top1 = m_doch - m_h; if( top1 < 0 ) top1 = 0; if( left1 != left ) { setFinalX(left1); left = left1; } if( top1 != top ) { m_scroller.setFinalY(top1); top = top1; } vFlushRange(); int cur = m_prange_start; int end = m_prange_end; int sel_rect1[] = null; int sel_rect2[] = null; if( m_drawbmp ) { if( Global.dark_mode ) { m_bmp.eraseColor(m_back); Canvas bcan = new Canvas(m_bmp); while( cur < end ) { PDFVPage vpage = m_pages[cur]; if( m_status != STA_ZOOM ) m_thread.start_render(vpage); vpage.Draw(bcan, left, top); if( sel_rect1 == null || sel_rect2 == null ) { sel_rect1 = vpage.GetSelRect1(left, top); sel_rect2 = vpage.GetSelRect2(left, top); } if( m_finder.find_get_page() == cur ) m_finder.find_draw(bcan, vpage, left, top); cur++; } m_draw_bmp.Create(m_bmp); m_draw_bmp.Invert(); m_draw_bmp.Free(m_bmp); //Log.i("time_d1", String.valueOf(System.currentTimeMillis() - rec_time)); canvas.drawBitmap(m_bmp, 0, 0, null); //Log.i("time_d2", String.valueOf(System.currentTimeMillis() - rec_time)); } else { canvas.drawColor(m_back); while( cur < end ) { PDFVPage vpage = m_pages[cur]; if( m_status != STA_ZOOM ) m_thread.start_render(vpage); if( sel_rect1 == null || sel_rect2 == null ) { sel_rect1 = vpage.GetSelRect1(left, top); sel_rect2 = vpage.GetSelRect2(left, top); } vpage.Draw(canvas, left, top); if( m_finder.find_get_page() == cur ) m_finder.find_draw(canvas, vpage, left, top); cur++; } } } else { m_bmp.eraseColor(m_back); //Log.i("time_d0", String.valueOf(System.currentTimeMillis() - rec_time)); m_draw_bmp.Create(m_bmp); while( cur < end ) { PDFVPage vpage = m_pages[cur]; m_thread.start_render(vpage); if( sel_rect1 == null || sel_rect2 == null ) { sel_rect1 = vpage.GetSelRect1(left, top); sel_rect2 = vpage.GetSelRect2(left, top); } vpage.Draw(m_draw_bmp, left, top); if( m_finder.find_get_page() == cur ) { m_finder.find_draw(m_draw_bmp, vpage, left, top); } cur++; } if( Global.dark_mode ) m_draw_bmp.Invert(); m_draw_bmp.Free(m_bmp); //Log.i("time_d1", String.valueOf(System.currentTimeMillis() - rec_time)); canvas.drawBitmap(m_bmp, 0, 0, null); //Log.i("time_d2", String.valueOf(System.currentTimeMillis() - rec_time)); } if( m_listener != null ) { cur = m_prange_start; end = m_prange_end; while( cur < end ) { m_listener.OnPDFPageDisplayed(canvas, m_pages[cur] ); cur++; } if( sel_rect1 != null && sel_rect2 != null ) m_listener.OnPDFSelecting(canvas, sel_rect1, sel_rect2); }

where every variable name is self explanatory right ? Not mentioning everything is private and extending this is almost impossible. Every single time I have to work with your library is like a short visit to programming/reverse engineering hell.
Last edit: 9 years 11 months ago by mineusdev.
More
9 years 11 months ago #10542 by Davide
Hi,
apologize us for the late reply, the PDFView.vGetPage() method returns null if you are passing a wrong page number (negative or max page + 1) or if the internal variable that represents the pdf pages is still null, this may happens because the reader is not yet ready.
When are you using this lines of code?
If you are doing this just after the pdf opening I suggest you to use a delay, so the reader variables will be ready and you can use the PDFView.vGetPage() instead of doc.GetPage().

We are sorry about the code, we will take your suggestions into considerations.
More
9 years 10 months ago #10565 by mineusdev
delay did not help, current code:
Code:
pdfView.vOpen(doc, 4, 0xFFCCCCCC, this); postDelayed(new Runnable() { @Override public void run() { highlightSearchQuery(doc, pageHolder); } }, 15000) private void highlightSearchQuery(Document doc, PageMetaDataViewHelper.PageHolder pageHolder) { this.highlightedSearchQuery = pageHolder.searchedQuery; for (int pageNumber : pageHolder.pages) { final PDFVPage page = pdfView.vGetPage(pageNumber); final Page currentPage = page.GetPage(); // final Page currentPage = doc.GetPage(pageNumber); if (currentPage != null) { currentPage.ObjsStart(); //Remove possible previous highlights. for (int i = 0; i < currentPage.GetAnnotCount(); i++) { final Page.Annotation pageAnnotation = currentPage.GetAnnot(i); pageAnnotation.RemoveFromPage(); } if (pageHolder.searchedQuery != null) { final Page.Finder mFinder = currentPage.FindOpen(pageHolder.searchedQuery, false, false); if (mFinder != null) { int finds = mFinder.GetCount(); Log.debug("PDFX current page " + pageNumber + " found " + finds + " searchString=" + pageHolder.searchedQuery); for (int j = 0; j < finds; j++) { int foundIndex = mFinder.GetFirstChar(j); int phraseEndIndex = foundIndex + pageHolder.searchedQuery.length(); // Log.debug("PDF phrase " + currentPage.ObjsGetString(foundIndex, phraseEndIndex)); currentPage.AddAnnotMarkup(foundIndex, phraseEndIndex, 0); } mFinder.Close(); } } currentPage.Close(); } pdfView.vRenderAsync(page); } } ;

15 seconds delay should be enough I suppose, I cannot let the user wait that long anyway. pageNumber in my example is 1 and the pdf opened has more than 20 pages.
Time to create page: 0.407 seconds
Powered by Kunena Forum