We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

PdfViewer - Find text from Tap/LongPress event

Thread ID:

Created:

Updated:

Platform:

Replies:

145815 Jul 9,2019 01:47 PM UTC Feb 3,2020 05:26 AM UTC Xamarin.Forms 12
loading
Tags: PdfViewer
Roman
Asked On July 9, 2019 01:50 PM UTC

Hello,
I found in the documentation that there are touch interaction events for PdfViewer. 
We can get Position : The position of the double tap event location with respect to the start of the page.
But what can we do with it? 
For example, I need to get the closest text(word) to the touched position. 
Is it possible to extract? 

It would be ideally to have something like that:
 private void PdfViewerControl_Tapped(object sender, Syncfusion.SfPdfViewer.XForms.TouchInteractionEventArgs e)
        {
            //Gets the page number of the PDF Viewer where you long pressed.
            int pageNumber = e.PageNumber;
            //Gets the position of the PDF Viewer where you long pressed.
            Point position = e.Position;
            string text=pdfViewerControl.GetTextFromPosition(position);
}



Gayathri Ramalingam [Syncfusion]
Replied On July 10, 2019 12:23 PM UTC

Hi Roman, 
 
At present, we cannot “get the text from the tapped position” using SfPdfViewer tapped event. However, we can get the text while performing long press on the required text from the ‘TextSelectionCompleted’ event. Please find the below code snippet for your reference. 
 
this.pdfViewerControl.TextSelectionCompleted += PdfViewerControl_TextSelectionCompleted; 
             
private void PdfViewerControl_TextSelectionCompleted(object sender, Syncfusion.SfPdfViewer.XForms.TextSelectionCompletedEventArgs args) 
{ 
            
       //The selected text is acquired and stored in the variable selectedText.  
       string selectedText = args.SelectedText; 
 
       //The number of the page in which the selection is performed is acquired.  
       int pageNumber = args.PageNumber; 
 
       //The bounds of the page in which the selection is performed is acquired.  
       Rectangle pageBounds = args.PageBounds; 
 
       //The region of the text being selected is acquired.  
       Rectangle selectedRegion = args.SelectedRegion; 
 
} 
 
Please find the below UG documentation link for your reference, 

Kindly let us know whether the above proposed solution meets your requirement. 
 
With Regards, 
Gayathri R 


Roman
Replied On July 12, 2019 10:50 AM UTC

Hi Roman, 
 
At present, we cannot “get the text from the tapped position” using SfPdfViewer tapped event. However, we can get the text while performing long press on the required text from the ‘TextSelectionCompleted’ event. Please find the below code snippet for your reference. 
 
this.pdfViewerControl.TextSelectionCompleted += PdfViewerControl_TextSelectionCompleted; 
             
private void PdfViewerControl_TextSelectionCompleted(object sender, Syncfusion.SfPdfViewer.XForms.TextSelectionCompletedEventArgs args) 
{ 
            
       //The selected text is acquired and stored in the variable selectedText.  
       string selectedText = args.SelectedText; 
 
       //The number of the page in which the selection is performed is acquired.  
       int pageNumber = args.PageNumber; 
 
       //The bounds of the page in which the selection is performed is acquired.  
       Rectangle pageBounds = args.PageBounds; 
 
       //The region of the text being selected is acquired.  
       Rectangle selectedRegion = args.SelectedRegion; 
 
} 
 
Please find the below UG documentation link for your reference, 

Kindly let us know whether the above proposed solution meets your requirement. 
 
With Regards, 
Gayathri R 


Thanks! This solution works, but it does not meet our requirements.

We need at least to find the line and the nearest letter of the text to the position received from the Tap/DoubleTap event. 

It might be not straight-forward and works at least for Android. If you have this feature, it would be really nice and convenient. 


Gayathri Ramalingam [Syncfusion]
Replied On July 15, 2019 12:54 PM UTC

Hi Roman, 
 
Thank you for your update. 
 
We have created a work around sample to get the nearby line of the tapped position. Please find the sample link from below, 
 
 
We can get the text with its bounds using ‘Extract Text’ feature with respect to the tapped position. Kindly let us know whether the above proposed solution meets your requirement.  
 
 
With Regards, 
Gayathri R 
 


Roman
Replied On August 2, 2019 09:26 AM UTC

Gayathri R, 
the proposed solution is really great and meets our requirement! 
Thank you very much, indeed.

Though, on some pdf exceptions appeared.  (And those pdf are not like scanned images, and TextSelectionCompleted works fine on them)
For example this pdf.

//
var page =m_loadedDocument.Pages[e.PageNumber-1];
string m_extractedText = page.ExtractText(out textLineCollection);  // Exception appears on this line (ExtractText method)
//

Unhandled Exception:
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index


Could you please advise on it?


Gayathri Ramalingam [Syncfusion]
Replied On August 5, 2019 09:26 AM UTC

Hi Roman, 
 
We were able to reproduce the issue “System.ArgumentOutOfRangeException occur while extracting text from the particular PDF document" in our side and we suspect this to be a defect. We have forwarded this issue to our development team for further analysis and we will update further details by 07-August-2019. 
 
With Regards, 
Gayathri R 


Gayathri Ramalingam [Syncfusion]
Replied On August 7, 2019 09:43 AM UTC

Hi Roman, 
 
We have confirmed that the issue “System.ArgumentOutOfRangeException occur while extracting text from the particular PDF document” is defect and logged defect report for this issue. This fix will be included in our 2019 Vol 3 Main release which will be available in the end of September 2019. 
 
With Regards, 
Gayathri R 


Roman
Replied On August 12, 2019 12:08 PM UTC

Gayathri R, thank you very much for high-quality support. 

Gayathri Ramalingam [Syncfusion]
Replied On August 12, 2019 12:59 PM UTC

Hi Roman, 
  
Thank you for your update. 
  
Please let us know, if you need any further assistance 
  
Regards, 
Ashokkumar Viswanathan 


Roman
Replied On December 16, 2019 06:46 PM UTC

Hi, 

We have tried to test the same functionality with new version of Syncfusion library 17.3.0.34.
But we got runtime error: "Method not found: string Syncfusion.Pdf.PdfPageBase.ExtractText(Syncfusion.Pdf.TextLineCollection&)"
Could you please advise on it. 


Jhansi Priya Ramesh [Syncfusion]
Replied On December 17, 2019 05:13 PM UTC

Hi Roman, 
 
We tried reproducing the exception in our side but it is working fine as expected. Please find the sample with which we tried reproducing the issue in our side from below, 
 
 
Kindly share the following details to analyze more on this issue and assist you with the better solution   
1.       Simple sample/ modify the above sample to reproduce the issue.  
2.       Platform [iOS/Android/UWP 
3.       Replication procedure to reproduce the issue.  
4.       Video representing the issue  
5.       Device specification details with which issue could be reproduced. 
 
 
 
Regards, 
Jhansi Priya Ramesh 


Roman
Replied On February 1, 2020 11:51 PM UTC

Hi Jhansi Priya Ramesh,

we have tried on the new version, it works fine, so no issues with it.

Thanks for the support!

Jhansi Priya Ramesh [Syncfusion]
Replied On February 3, 2020 05:26 AM UTC

Hi Roman, 

Thank you for the update. We are glad that your issue has been resolved.  

Regards, 
Jhansi Priya Ramesh 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon