- Home
- Forum
- JavaScript - EJ 2
- Search custom text on pdf viewer load
Search custom text on pdf viewer load
Hello, I am having issues to find the way to search multiple words on loading of the pdf viewer.
I would like to search and highlights two word by default like "Ryan" and "Done".
var viewer = new ej.pdfviewer.PdfViewer({
enableTextSearch: true,
documentPath: _documentPath,
serviceUrl: 'http://localhost:57765/api/pdfviewer',
});
ej.pdfviewer.PdfViewer.Inject(ej.pdfviewer.Toolbar, ej.pdfviewer.Magnification, ej.pdfviewer.BookmarkView, ej.pdfviewer.ThumbnailView, ej.pdfviewer.TextSelection, ej.pdfviewer.TextSearch, ej.pdfviewer.Print, ej.pdfviewer.Navigation, ej.pdfviewer.LinkAnnotation, ej.pdfviewer.Annotation, ej.pdfviewer.FormFields);
//methods
viewer.searchText("Ryan"); //this doesn't work.
viewer.appendTo('#pdfViewer');
I read this documentation: https://ej2.syncfusion.com/javascript/documentation/api/pdfviewer/textSearch/
I don't even know if this is possibile, but I would need this.
Thanks
SIGN IN To post a reply.
14 Replies
AA
Akshaya Arivoli
Syncfusion Team
February 13, 2020 12:31 PM UTC
Hi Alessio,
Thank you for contacting Syncfusion support.
We can initiate single search of the text( which may contain single word or group of words) from the code behind during the control initialization and we do not have support to initiating multiple searches instances during the control initialization. Please find the modified code snippet to initiate single search during the control initialization from the below,
|
var viewer = new ej.pdfviewer.PdfViewer({
serviceUrl:'https://ej2services.syncfusion.com/production/web-services/api/pdfviewer',
documentPath :"PDF_Succinctly.pdf",
});
ej.pdfviewer.PdfViewer.Inject(ej.pdfviewer.Toolbar, ej.pdfviewer.Magnification, ej.pdfviewer.BookmarkView, ej.pdfviewer.ThumbnailView, ej.pdfviewer.TextSelection, ej.pdfviewer.TextSearch, ej.pdfviewer.Print, ej.pdfviewer.Navigation, ej.pdfviewer.LinkAnnotation, ej.pdfviewer.Annotation, ej.pdfviewer.FormFields);
viewer.appendTo('#PdfViewer');
viewer.textSearchModule.searchText("authors and"); |
Note: We need to initiate the text search once the PDF Viewer is appended to the Div.
Please try this and revert us with more details about your requirement and the use scenario for initiating multiple searchs during the control initialization. These details will be helpful for us to investigate further and assist you better.
Regards,
Akshaya
AL
Alessio
February 17, 2020 02:08 PM UTC
Hi, thanks for your response.


I tried your code and now I'm able to search a word initializing the pdf-viewer, anyway I get this error after the debug passes this line: viewer.textSearchModule.searchText("Capitolo");
By the way, the word is searched as well.
Point 2: If i try something like this (currently is impossibile due to the error above):
viewer.textSearchModule.searchText("Capitolo");
viewer.textSearchModule.searchText("Legge);
this will not search the two words and highlight them both?
Let me know please, because I need to find a way (if possibile) to highlights more words.
Thank you
AA
Akshaya Arivoli
Syncfusion Team
February 18, 2020 11:56 AM UTC
Hi Alessio,
Sorry for the inconvenience caused.
As mentioned earlier we do not have support to initiate multiple searches one by one from the code behind in the PDF Viewer. Also, we can reproduce the reported script error. However, we can resolve it by initializing the text search in the documentLoad event of the PDF Viewer. Please find the modified code snippet from the below,
|
var viewer = new ej.pdfviewer.PdfViewer({
serviceUrl: ‘https://ej2services.syncfusion.com/production/web-services/api/pdfviewer,
documentPath :"PDF_Succinctly.pdf",
documentLoad:function(args){
viewer.textSearchModule.searchText("authors and");
},
});
ej.pdfviewer.PdfViewer.Inject(ej.pdfviewer.Toolbar, ej.pdfviewer.Magnification, ej.pdfviewer.BookmarkView, ej.pdfviewer.ThumbnailView, ej.pdfviewer.TextSelection, ej.pdfviewer.TextSearch, ej.pdfviewer.Print, ej.pdfviewer.Navigation, ej.pdfviewer.LinkAnnotation, ej.pdfviewer.Annotation, ej.pdfviewer.FormFields);
viewer.appendTo('#PdfViewer'); |
Please try this and revert us with more details about your requirements and the use scenario for initiating multiple searches during the control initialization. These details will be helpful for us to investigate further and assist you better.
Regards,
Akshaya
AL
Alessio
February 18, 2020 06:01 PM UTC
Hello, thanks for your response.
I tried your code and it has fixed my problem.
Anyway, we need to open the pdf and search by exact sentence or by single word:
Exact Phase: 'unlock full power'
List of Strings: Unlock+full+power
Could you helping us, implementing this functionality?
Regards,
Alessio
AA
Akshaya Arivoli
Syncfusion Team
February 19, 2020 11:18 AM UTC
Hi Alessio,
Thank you for your update.
Currently PDF Viewer supports to search for the exact phase (i.e., unlock full power) in the provided document. Please find the sample for your reference,
Please try it and if you have concerns provide us more details about your requirement and confirm us whether your requirement is to search for all the occurrence of the provided words( unlock, full , power) along with the exact phase. It will be helpful in further researching and assist you better.
Regards,
Akshaya
AL
Alessio
February 19, 2020 02:35 PM UTC
Hello,
for us it is important to highlight the single words because the pdf is opened by the result of a search engine that returns the document both by exact sentence and by single words. So, we need to highlight more then 1 word like: (unlock, full, power) that are scattered throughout the PDF.
Like this example:
Lorem ipsum dolor sit unlock, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo full. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est power
If we don't have this functionality we should find another PDF Viewer.
Thanks.
AA
Akshaya Arivoli
Syncfusion Team
February 21, 2020 01:01 PM UTC
Hi Alessio,
Thank you for your update.
As we mentioned, we do not have support for searching multiple words in our PDF Viewer at a time. We don’t have any immediate plans to implement this type of multiple words search in our PDF Viewer control in near future. You can track the status using the below feedback link,
Regards,
Akshaya
AL
Alessio
April 9, 2020 09:23 AM UTC
Dear All,
as mentioned before, for us it is very important to highlight the single words because the pdf is opened by the result of a search engine that returns the document both by exact sentence and by single words. So, we need to highlight more then 1 word.
As you will have understood, we need to understand if and when you will be able to close this issue. Alternatively we will have to take other solutions.
We think it is useful for all your customers too.
Regards
Alessio
MS
Mohan Selvaraj
Syncfusion Team
April 10, 2020 09:30 AM UTC
Hi Alessio
Thanks for your update.
We will analysis more on this query and update you with more details on April 14th 2020.
Regards,
Mohan S
AA
Akshaya Arivoli
Syncfusion Team
April 15, 2020 02:24 PM UTC
Hi Alessio,
We have analyzed to provide support for searching multiple words in our PDF Viewer at a time and it will be included in our 2020 Volume 2 release which is expected to be rolled out in the end of June . You can track the status using the below feedback link,
Regards,
Akshaya
LR
L R
February 11, 2021 07:59 AM UTC
I am using Angular application and web service (.net api) to load the document in pdf. How can we initialize the text search in this scenario?
Basically, I am looking for a customized text search in pdf viewer via angular. It highlights the searched text and dynamically stores searched object as an annotation. Then it sends to the web service for redaction. Can you help me with that?
DM
Dhivyabharathi Mohan
Syncfusion Team
February 12, 2021 10:41 AM UTC
Hi LR,
Currently, we are creating a sample to highlight the extracted text and dynamically and store the extracted text object as an annotation. And then we can redact the extracted text on the server-side. We will provide the sample on February 16, 2021. In the meantime, we suggest you use the property searchText to search the target text in the PDF document and highlight the occurrences on the page. Please find the API details from the following link,
Regards,
Dhivya.
LR
L R
February 17, 2021 03:38 AM UTC
Looking forward to the sample which highlights the extracted text dynamically and store the extracted text object as an annotation
VS
Vasugi Sivajothi
Syncfusion Team
February 18, 2021 02:08 PM UTC
Hi LR,
Sorry for the inconvenience.
We are currently working on creating the sample with high priority, we will update the sample on 22 February 2021.
Regards,
Vasugi
SIGN IN To post a reply.
- 14 Replies
- 6 Participants
-
AL Alessio
- Feb 12, 2020 05:00 PM UTC
- Feb 18, 2021 02:08 PM UTC