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. Image for the cookie policy date

PdfViewer - Find text from Tap/LongPress event

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);
}



12 Replies

GR Gayathri Ramalingam Syncfusion Team 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 



RO Roman replied to Gayathri Ramalingam 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. 



GR Gayathri Ramalingam Syncfusion Team 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 
 



RO Roman 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?



GR Gayathri Ramalingam Syncfusion Team 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 



GR Gayathri Ramalingam Syncfusion Team 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 



RO Roman August 12, 2019 12:08 PM UTC

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


GR Gayathri Ramalingam Syncfusion Team 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 



RO Roman 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. 



JP Jhansi Priya Ramesh Syncfusion Team 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 



RO Roman 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!


JP Jhansi Priya Ramesh Syncfusion Team 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 


Loader.
Up arrow icon