How to "Enable Selection" in a kendoPDFViewer component

1 Answer 337 Views
PDFViewer
Alireza
Top achievements
Rank 1
Alireza asked on 28 Apr 2021, 03:13 PM

I'm using a KendoPDFViewer component, and it works fine.

I want to enable selection by default, so that the use don't need to enable it manually. 

I want to know in the following code snipet, how can i set "Enable Selection" property to true?

function createPdfViewer($elem) {
	$.when(
		$.getScript("https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.2.2/pdf.js"),
		$.getScript("https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.2.2/pdf.worker.js")
	).done(function () {
		window.pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.2.2/pdf.worker.js';
	}).then(function () {
		$elem.kendoPDFViewer({
			pdfjsProcessing: {
				file: $elem[0].dataset.filename
			},
			width: $elem[0].dataset.width,
			height: $elem[0].dataset.height
		}).data("kendoPDFViewer");
	});
}

1 Answer, 1 is accepted

Sort by
0
Aleksandar
Telerik team
answered on 03 May 2021, 11:05 AM

Hello Alireza,

A possible approach to achieve the desired result is to handle the render event of the PDFViewer. The PDF Viewer uses internally the Toolbar widget, so for example, on the first time the render event is fired, you can get a reference to the Enable Selection button and call the toggle method of the Toolbar:

<script>
      var firstRender = true;
      $(document).ready(function () {
        var vr=  $("#pdfViewer").kendoPDFViewer({
          pdfjsProcessing: {
            file: "https://demos.telerik.com/kendo-ui/content/web/pdfViewer/sample.pdf"
          },
          width: "100%",
          height: 1200,
          render: function(e) {
            if (firstRender) {
              var selectionElement = $(".k-toolbar").find('a[title="Enable Selection"]');
              e.sender.toolbar.toggle(selectionElement, true);

              firstRender = false;
            }
          }
        }).getKendoPDFViewer();            
      });
    </script>

Here is a runnable example of the above-suggested approach.

I hope this helps achieve the desired result.

Regards,
Aleksandar
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

David
Top achievements
Rank 1
commented on 17 Jan 2022, 11:31 AM

This does not work. Whilst the arrow button for select mode is highlighted, the hand cursor is still displayed and pan mode is still selected.
Alireza
Top achievements
Rank 1
commented on 17 Jan 2022, 11:56 AM

For me it's working. Check the runable example in @Aleksander post again. you can test it there.
David
Top achievements
Rank 1
commented on 17 Jan 2022, 12:18 PM

I tried Aleksander's example in his dojo, and it is not working for me. This was with edge, chrome, and ie.
Martin
Telerik team
commented on 20 Jan 2022, 08:25 AM

Could you please try this version of the example and let me know if it works as expected?
Tags
PDFViewer
Asked by
Alireza
Top achievements
Rank 1
Answers by
Aleksandar
Telerik team
Share this question
or