Highlighted

Getting getSelectedText() value

Explorer ,
Sep 12, 2020

Copy link to clipboard

Copied

I am trying to retrieve the getSelectedText() value from a PREVIEW_SELECTED_END callback to populate the prompt for a Highlight comment entry as follows...  trying to set var [selectedText]

var selectedText;   
const eventOptions = {
           enableFilePreviewEvents: true
    }
    adobeDCView.registerCallback(
        AdobeDC.View.Enum.CallbackType.EVENT_LISTENER,
        function(event) {
            console.log("Event: " + event.type);
            if (event.type === "PREVIEW_SELECTION_END") {
                previewFilePromise.then(adobeViewer => {
                    adobeViewer.getAPIs().then(apis => {
                        apis.getSelectedContent()
                            .then(result => selectedText = result.data)
                            .catch(error => console.log(error));
                    });
                });
                console.log("selectedText = " + selectedText);
            }
        }, eventOptions
   );

...which does work, but not always. For instance, the first selection of text appears to block the Tool popover, clear and select again and it works, but then only randomly thereafter. What am I missing?

 

Any help greatly appretiated, Nick Gates

 

 

Hi Nick,
Thanks for choosing PDF Embed APIs. You snippet seems to miss one thing, you are using console.log outside the promise which might not get resolved before console.log statement. Below is the updated snippet which should work in your case.

var selectedText;   
const eventOptions = {
           enableFilePreviewEvents: true
    }
    adobeDCView.registerCallback(
        AdobeDC.View.Enum.CallbackType.EVENT_LISTENER,
        function(event) {
            console.log("Event: " + event.type);
            if (event.type === "PREVIEW_SELECTION_END") {
                previewFilePromise.then(adobeViewer => {
                    adobeViewer.getAPIs().then(apis => {
                        apis.getSelectedContent()
                            .then(result => {
                                 selectedText = result.data;
                                 console.log("selectedText = " + selectedText);
                            })
                            .catch(error => console.log(error));
                    });
                });
            }
        }, eventOptions
   );

  
Thanks

Topics

PDF Embed API

Views

39

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Getting getSelectedText() value

Explorer ,
Sep 12, 2020

Copy link to clipboard

Copied

I am trying to retrieve the getSelectedText() value from a PREVIEW_SELECTED_END callback to populate the prompt for a Highlight comment entry as follows...  trying to set var [selectedText]

var selectedText;   
const eventOptions = {
           enableFilePreviewEvents: true
    }
    adobeDCView.registerCallback(
        AdobeDC.View.Enum.CallbackType.EVENT_LISTENER,
        function(event) {
            console.log("Event: " + event.type);
            if (event.type === "PREVIEW_SELECTION_END") {
                previewFilePromise.then(adobeViewer => {
                    adobeViewer.getAPIs().then(apis => {
                        apis.getSelectedContent()
                            .then(result => selectedText = result.data)
                            .catch(error => console.log(error));
                    });
                });
                console.log("selectedText = " + selectedText);
            }
        }, eventOptions
   );

...which does work, but not always. For instance, the first selection of text appears to block the Tool popover, clear and select again and it works, but then only randomly thereafter. What am I missing?

 

Any help greatly appretiated, Nick Gates

 

 

Hi Nick,
Thanks for choosing PDF Embed APIs. You snippet seems to miss one thing, you are using console.log outside the promise which might not get resolved before console.log statement. Below is the updated snippet which should work in your case.

var selectedText;   
const eventOptions = {
           enableFilePreviewEvents: true
    }
    adobeDCView.registerCallback(
        AdobeDC.View.Enum.CallbackType.EVENT_LISTENER,
        function(event) {
            console.log("Event: " + event.type);
            if (event.type === "PREVIEW_SELECTION_END") {
                previewFilePromise.then(adobeViewer => {
                    adobeViewer.getAPIs().then(apis => {
                        apis.getSelectedContent()
                            .then(result => {
                                 selectedText = result.data;
                                 console.log("selectedText = " + selectedText);
                            })
                            .catch(error => console.log(error));
                    });
                });
            }
        }, eventOptions
   );

  
Thanks

Topics

PDF Embed API

Views

40

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Employee ,
Sep 13, 2020

Copy link to clipboard

Copied

Hi Nick,
Thanks for choosing PDF Embed APIs. You snippet seems to miss one thing, you are using console.log outside the promise which might not get resolved before console.log statement. Below is the updated snippet which should work in your case.

var selectedText;   
const eventOptions = {
           enableFilePreviewEvents: true
    }
    adobeDCView.registerCallback(
        AdobeDC.View.Enum.CallbackType.EVENT_LISTENER,
        function(event) {
            console.log("Event: " + event.type);
            if (event.type === "PREVIEW_SELECTION_END") {
                previewFilePromise.then(adobeViewer => {
                    adobeViewer.getAPIs().then(apis => {
                        apis.getSelectedContent()
                            .then(result => {
                                 selectedText = result.data;
                                 console.log("selectedText = " + selectedText);
                            })
                            .catch(error => console.log(error));
                    });
                });
            }
        }, eventOptions
   );

  
Thanks

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Explorer ,
Sep 20, 2020

Copy link to clipboard

Copied

Thank you for the reply.

 

That does seem to have done the job, thank you!

 

Nick

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Resources