RenderPdfTexts

Hello
I would like to use the PDF Viewer Control to get the text from the PDF I'm displaying.
But if i set the property isExtractText to true , I always get this error:

I think there is something missing in the PDF Viewer Service.
Can anyone help me please?


Maico

2 Replies 1 reply marked as answer

AA Akshaya Arivoli Syncfusion Team October 7, 2020 01:42 PM UTC

Hi Maico, 

Thank you for contacting Syncfusion support. 

In our PDF Viewer, when we set isExtractText to true , we need to add the RenderPdfTexts method in PdfViewerController. Please find the code from the below and the sample from the below link, 



Code Snippet: 

PdfviewerController.cs 

        [HttpPost] 
        [EnableCors("AllowAllOrigins")] 
        [Route("RenderPdfTexts")] 
        public IActionResult RenderPdfTexts([FromBody] Dictionary<string, string> jsonObject) 
        { 
            PdfRenderer pdfviewer = new PdfRenderer(_cache); 
            object result = pdfviewer.GetDocumentText(jsonObject); 
            return Content(JsonConvert.SerializeObject(result)); 
        } 


Default.html 

    <div style="height: 100%;width: 100%"> 
        <button id='textSearch'>TextSearch</button> 
        <button id='searchCount'>SearchCount</button> 
        <div id="pdfViewer" style="height: 100%;width: 100%;"></div> 
    </div> 

Index.ts 

let viewer: PdfViewer = new PdfViewer(); 
viewer.isExtractText  = true; 
viewer.serviceUrl = "http://localhost:62869/api/PdfViewer"; 
viewer.appendTo("#pdfViewer"); 


document.getElementById('textSearch').addEventListener('click', () => { 
    viewer.textSearch.searchText('pdf', false); 
}) 

document.getElementById('searchCount').addEventListener('click', () => { 
    var searchCount = viewer.textSearchModule.searchCount; 
    console.log(searchCount); 
}) 



Please try it and revert us with more details, if you need further assistance. 




Regards, 
Akshaya 


Marked as answer

MA Maico October 7, 2020 02:09 PM UTC

Perfect! Thank you!!

Loader.
Up arrow icon